mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(l2-withdrawals): Define OpEngineApiBuilder (#14426)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -8613,6 +8613,7 @@ dependencies = [
|
||||
"alloy-rpc-types-engine",
|
||||
"alloy-rpc-types-eth",
|
||||
"async-trait",
|
||||
"derive_more",
|
||||
"jsonrpsee",
|
||||
"jsonrpsee-core",
|
||||
"jsonrpsee-types",
|
||||
|
||||
@ -23,6 +23,9 @@ pub use engine::OpEngineTypes;
|
||||
pub mod node;
|
||||
pub use node::{OpNetworkPrimitives, OpNode};
|
||||
|
||||
pub mod rpc;
|
||||
pub use rpc::OpEngineApiBuilder;
|
||||
|
||||
pub use reth_optimism_txpool as txpool;
|
||||
|
||||
/// Helpers for running test node instances.
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::{
|
||||
args::RollupArgs,
|
||||
engine::OpEngineValidator,
|
||||
txpool::{OpTransactionPool, OpTransactionValidator},
|
||||
OpEngineTypes,
|
||||
OpEngineApiBuilder, OpEngineTypes,
|
||||
};
|
||||
use op_alloy_consensus::OpPooledTransaction;
|
||||
use reth_chainspec::{EthChainSpec, Hardforks};
|
||||
@ -202,7 +202,12 @@ impl NodeTypesWithEngine for OpNode {
|
||||
pub struct OpAddOns<N: FullNodeComponents> {
|
||||
/// Rpc add-ons responsible for launching the RPC servers and instantiating the RPC handlers
|
||||
/// and eth-api.
|
||||
pub rpc_add_ons: RpcAddOns<N, OpEthApi<N>, OpEngineValidatorBuilder>,
|
||||
pub rpc_add_ons: RpcAddOns<
|
||||
N,
|
||||
OpEthApi<N>,
|
||||
OpEngineValidatorBuilder,
|
||||
OpEngineApiBuilder<OpEngineValidatorBuilder>,
|
||||
>,
|
||||
/// Data availability configuration for the OP builder.
|
||||
pub da_config: OpDAConfig,
|
||||
}
|
||||
|
||||
40
crates/optimism/node/src/rpc.rs
Normal file
40
crates/optimism/node/src/rpc.rs
Normal file
@ -0,0 +1,40 @@
|
||||
//! RPC component builder
|
||||
|
||||
pub use reth_optimism_rpc::OpEngineApi;
|
||||
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_node_api::{
|
||||
AddOnsContext, EngineTypes, ExecutionData, FullNodeComponents, NodeTypes, NodeTypesWithEngine,
|
||||
};
|
||||
use reth_node_builder::rpc::{BasicEngineApiBuilder, EngineApiBuilder, EngineValidatorBuilder};
|
||||
|
||||
/// Builder for basic [`OpEngineApi`] implementation.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct OpEngineApiBuilder<EV> {
|
||||
inner: BasicEngineApiBuilder<EV>,
|
||||
}
|
||||
|
||||
impl<N, EV> EngineApiBuilder<N> for OpEngineApiBuilder<EV>
|
||||
where
|
||||
N: FullNodeComponents<
|
||||
Types: NodeTypesWithEngine<
|
||||
ChainSpec: EthereumHardforks,
|
||||
Engine: EngineTypes<ExecutionData = ExecutionData>,
|
||||
>,
|
||||
>,
|
||||
EV: EngineValidatorBuilder<N>,
|
||||
{
|
||||
type EngineApi = OpEngineApi<
|
||||
N::Provider,
|
||||
<N::Types as NodeTypesWithEngine>::Engine,
|
||||
N::Pool,
|
||||
EV::Validator,
|
||||
<N::Types as NodeTypes>::ChainSpec,
|
||||
>;
|
||||
|
||||
async fn build_engine_api(self, ctx: &AddOnsContext<'_, N>) -> eyre::Result<Self::EngineApi> {
|
||||
let inner = self.inner.build_engine_api(ctx).await?;
|
||||
|
||||
Ok(OpEngineApi::new(inner))
|
||||
}
|
||||
}
|
||||
@ -69,6 +69,7 @@ serde_json.workspace = true
|
||||
# misc
|
||||
thiserror.workspace = true
|
||||
tracing.workspace = true
|
||||
derive_more = { workspace = true, features = ["constructor"] }
|
||||
|
||||
[dev-dependencies]
|
||||
reth-optimism-chainspec.workspace = true
|
||||
|
||||
@ -6,12 +6,14 @@ use alloy_rpc_types_engine::{
|
||||
ClientVersionV1, ExecutionPayloadBodiesV1, ExecutionPayloadInputV2, ExecutionPayloadV3,
|
||||
ForkchoiceState, ForkchoiceUpdated, PayloadId, PayloadStatus,
|
||||
};
|
||||
use derive_more::Constructor;
|
||||
use jsonrpsee::proc_macros::rpc;
|
||||
use jsonrpsee_core::RpcResult;
|
||||
use jsonrpsee_core::{server::RpcModule, RpcResult};
|
||||
use op_alloy_rpc_types_engine::OpExecutionPayloadV4;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_node_api::{EngineTypes, EngineValidator, ExecutionData};
|
||||
use reth_provider::{BlockReader, HeaderProvider, StateProviderFactory};
|
||||
use reth_rpc_api::IntoEngineApiRpcModule;
|
||||
use reth_rpc_engine_api::{EngineApi, EngineApiServer};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
@ -194,7 +196,7 @@ pub trait OpEngineApi<Engine: EngineTypes> {
|
||||
|
||||
/// The Engine API implementation that grants the Consensus layer access to data and
|
||||
/// functions in the Execution layer that are crucial for the consensus process.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Constructor)]
|
||||
pub struct OpEngineApi<Provider, EngineT: EngineTypes, Pool, Validator, ChainSpec> {
|
||||
inner: EngineApi<Provider, EngineT, Pool, Validator, ChainSpec>,
|
||||
}
|
||||
@ -312,3 +314,14 @@ where
|
||||
EngineApiServer::exchange_capabilities(&self.inner, _capabilities).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<Provider, EngineT, Pool, Validator, ChainSpec> IntoEngineApiRpcModule
|
||||
for OpEngineApi<Provider, EngineT, Pool, Validator, ChainSpec>
|
||||
where
|
||||
EngineT: EngineTypes,
|
||||
Self: OpEngineApiServer<EngineT>,
|
||||
{
|
||||
fn into_rpc_module(self) -> RpcModule<()> {
|
||||
self.into_rpc().remove_context()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user