mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-25 23:28:03 -05:00
feat(engine): Op engine capabilities (#14733)
Co-authored-by: Ishika Choudhury <117741714+Rimeeeeee@users.noreply.github.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@@ -7,6 +7,7 @@ use std::{
|
||||
};
|
||||
|
||||
use crate::{BeaconConsensusEngineEvent, BeaconConsensusEngineHandle, EthApiBuilderCtx};
|
||||
use alloy_primitives::map::HashSet;
|
||||
use alloy_rpc_types::engine::{ClientVersionV1, ExecutionData};
|
||||
use futures::TryFutureExt;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
@@ -664,6 +665,17 @@ pub trait EngineApiBuilder<Node: FullNodeComponents>: Send + Sync {
|
||||
#[derive(Debug, Default)]
|
||||
pub struct BasicEngineApiBuilder<EV> {
|
||||
engine_validator_builder: EV,
|
||||
capabilities: Option<EngineCapabilities>,
|
||||
}
|
||||
|
||||
impl<EV> BasicEngineApiBuilder<EV> {
|
||||
/// Sets list of capabilities supported by engine API. Takes list of method names.
|
||||
pub fn capabilities(mut self, caps: &[&str]) -> Self {
|
||||
self.capabilities = Some(EngineCapabilities::new(
|
||||
caps.iter().map(|cap| cap.to_string()).collect::<HashSet<_>>(),
|
||||
));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<N, EV> EngineApiBuilder<N> for BasicEngineApiBuilder<EV>
|
||||
@@ -685,7 +697,7 @@ where
|
||||
>;
|
||||
|
||||
async fn build_engine_api(self, ctx: &AddOnsContext<'_, N>) -> eyre::Result<Self::EngineApi> {
|
||||
let Self { engine_validator_builder } = self;
|
||||
let Self { engine_validator_builder, capabilities } = self;
|
||||
|
||||
let engine_validator = engine_validator_builder.build(ctx).await?;
|
||||
let client = ClientVersionV1 {
|
||||
@@ -702,7 +714,7 @@ where
|
||||
ctx.node.pool().clone(),
|
||||
Box::new(ctx.node.task_executor().clone()),
|
||||
client,
|
||||
EngineCapabilities::default(),
|
||||
capabilities.unwrap_or_default(),
|
||||
engine_validator,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! RPC component builder
|
||||
|
||||
use reth_optimism_rpc::engine::OP_CAPABILITIES;
|
||||
pub use reth_optimism_rpc::OpEngineApi;
|
||||
|
||||
use alloy_rpc_types_engine::ExecutionData;
|
||||
@@ -34,7 +35,7 @@ where
|
||||
>;
|
||||
|
||||
async fn build_engine_api(self, ctx: &AddOnsContext<'_, N>) -> eyre::Result<Self::EngineApi> {
|
||||
let inner = self.inner.build_engine_api(ctx).await?;
|
||||
let inner = self.inner.capabilities(OP_CAPABILITIES).build_engine_api(ctx).await?;
|
||||
|
||||
Ok(OpEngineApi::new(inner))
|
||||
}
|
||||
|
||||
@@ -17,6 +17,24 @@ use reth_rpc_api::IntoEngineApiRpcModule;
|
||||
use reth_rpc_engine_api::{EngineApi, EngineApiServer};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
/// The list of all supported Engine capabilities available over the engine endpoint.
|
||||
///
|
||||
/// Spec: <https://specs.optimism.io/protocol/exec-engine.html>
|
||||
pub const OP_CAPABILITIES: &[&str] = &[
|
||||
"engine_forkchoiceUpdatedV2",
|
||||
"engine_forkchoiceUpdatedV3",
|
||||
"engine_exchangeTransitionConfigurationV1",
|
||||
"engine_getClientVersionV1",
|
||||
"engine_getPayloadV2",
|
||||
"engine_getPayloadV3",
|
||||
"engine_getPayloadV4",
|
||||
"engine_newPayloadV2",
|
||||
"engine_newPayloadV3",
|
||||
"engine_newPayloadV4",
|
||||
"engine_getPayloadBodiesByHashV1",
|
||||
"engine_getPayloadBodiesByRangeV1",
|
||||
];
|
||||
|
||||
/// Extension trait that gives access to Optimism engine API RPC methods.
|
||||
///
|
||||
/// Note:
|
||||
@@ -311,7 +329,7 @@ where
|
||||
}
|
||||
|
||||
async fn exchange_capabilities(&self, _capabilities: Vec<String>) -> RpcResult<Vec<String>> {
|
||||
EngineApiServer::exchange_capabilities(&self.inner, _capabilities).await
|
||||
Ok(self.inner.capabilities().list())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ pub mod witness;
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
pub use engine::OpEngineApiClient;
|
||||
pub use engine::{OpEngineApi, OpEngineApiServer};
|
||||
pub use engine::{OpEngineApi, OpEngineApiServer, OP_CAPABILITIES};
|
||||
pub use error::{OpEthApiError, OpInvalidTransactionError, SequencerClientError};
|
||||
pub use eth::{OpEthApi, OpReceiptBuilder};
|
||||
pub use sequencer::SequencerClient;
|
||||
|
||||
@@ -553,6 +553,11 @@ where
|
||||
|
||||
Ok(self.inner.beacon_consensus.fork_choice_updated(state, payload_attrs, version).await?)
|
||||
}
|
||||
|
||||
/// Returns reference to supported capabilities.
|
||||
pub fn capabilities(&self) -> &EngineCapabilities {
|
||||
&self.inner.capabilities
|
||||
}
|
||||
}
|
||||
|
||||
impl<Provider, EngineT, Pool, Validator, ChainSpec>
|
||||
@@ -1009,7 +1014,7 @@ where
|
||||
/// Handler for `engine_exchangeCapabilitiesV1`
|
||||
/// See also <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/common.md#capabilities>
|
||||
async fn exchange_capabilities(&self, _capabilities: Vec<String>) -> RpcResult<Vec<String>> {
|
||||
Ok(self.inner.capabilities.list())
|
||||
Ok(self.capabilities().list())
|
||||
}
|
||||
|
||||
async fn get_blobs_v1(
|
||||
|
||||
Reference in New Issue
Block a user