refactor: move EngineValidator setup to RpcAddOns (#11850)

This commit is contained in:
Arsenii Kulikov
2024-10-19 14:08:34 +04:00
committed by GitHub
parent da5079d11f
commit 2ae93682b4
12 changed files with 140 additions and 219 deletions

1
Cargo.lock generated
View File

@ -7495,7 +7495,6 @@ dependencies = [
"reth-consensus", "reth-consensus",
"reth-db", "reth-db",
"reth-db-common", "reth-db-common",
"reth-ethereum-engine-primitives",
"reth-evm", "reth-evm",
"reth-execution-types", "reth-execution-types",
"reth-exex", "reth-exex",

View File

@ -12,15 +12,16 @@ use reth_ethereum_engine_primitives::{
use reth_evm_ethereum::execute::EthExecutorProvider; use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_network::NetworkHandle; use reth_network::NetworkHandle;
use reth_node_api::{ use reth_node_api::{
ConfigureEvm, EngineValidator, FullNodeComponents, NodePrimitives, NodeTypesWithDB, AddOnsContext, ConfigureEvm, EngineValidator, FullNodeComponents, NodePrimitives,
NodeTypesWithDB,
}; };
use reth_node_builder::{ use reth_node_builder::{
components::{ components::{
ComponentsBuilder, ConsensusBuilder, EngineValidatorBuilder, ExecutorBuilder, ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
NetworkBuilder, PayloadServiceBuilder, PoolBuilder, PayloadServiceBuilder, PoolBuilder,
}, },
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine}, node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
rpc::RpcAddOns, rpc::{EngineValidatorBuilder, RpcAddOns},
BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, PayloadTypes, BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, PayloadTypes,
}; };
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
@ -57,7 +58,6 @@ impl EthereumNode {
EthereumNetworkBuilder, EthereumNetworkBuilder,
EthereumExecutorBuilder, EthereumExecutorBuilder,
EthereumConsensusBuilder, EthereumConsensusBuilder,
EthereumEngineValidatorBuilder,
> >
where where
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = ChainSpec>>, Node: FullNodeTypes<Types: NodeTypes<ChainSpec = ChainSpec>>,
@ -74,7 +74,6 @@ impl EthereumNode {
.network(EthereumNetworkBuilder::default()) .network(EthereumNetworkBuilder::default())
.executor(EthereumExecutorBuilder::default()) .executor(EthereumExecutorBuilder::default())
.consensus(EthereumConsensusBuilder::default()) .consensus(EthereumConsensusBuilder::default())
.engine_validator(EthereumEngineValidatorBuilder::default())
} }
} }
@ -96,6 +95,7 @@ pub type EthereumAddOns<N> = RpcAddOns<
NetworkHandle, NetworkHandle,
<N as FullNodeComponents>::Evm, <N as FullNodeComponents>::Evm,
>, >,
EthereumEngineValidatorBuilder,
>; >;
impl<Types, N> Node<N> for EthereumNode impl<Types, N> Node<N> for EthereumNode
@ -110,7 +110,6 @@ where
EthereumNetworkBuilder, EthereumNetworkBuilder,
EthereumExecutorBuilder, EthereumExecutorBuilder,
EthereumConsensusBuilder, EthereumConsensusBuilder,
EthereumEngineValidatorBuilder,
>; >;
type AddOns = EthereumAddOns< type AddOns = EthereumAddOns<
@ -347,12 +346,12 @@ pub struct EthereumEngineValidatorBuilder;
impl<Node, Types> EngineValidatorBuilder<Node> for EthereumEngineValidatorBuilder impl<Node, Types> EngineValidatorBuilder<Node> for EthereumEngineValidatorBuilder
where where
Types: NodeTypesWithEngine<ChainSpec = ChainSpec>, Types: NodeTypesWithEngine<ChainSpec = ChainSpec>,
Node: FullNodeTypes<Types = Types>, Node: FullNodeComponents<Types = Types>,
EthereumEngineValidator: EngineValidator<Types::Engine>, EthereumEngineValidator: EngineValidator<Types::Engine>,
{ {
type Validator = EthereumEngineValidator; type Validator = EthereumEngineValidator;
async fn build_validator(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Validator> { async fn build(self, ctx: &AddOnsContext<'_, Node>) -> eyre::Result<Self::Validator> {
Ok(EthereumEngineValidator::new(ctx.chain_spec())) Ok(EthereumEngineValidator::new(ctx.config.chain.clone()))
} }
} }

View File

@ -31,7 +31,6 @@ reth-primitives.workspace = true
reth-provider = { workspace = true, features = ["test-utils"] } reth-provider = { workspace = true, features = ["test-utils"] }
reth-tasks.workspace = true reth-tasks.workspace = true
reth-transaction-pool = { workspace = true, features = ["test-utils"] } reth-transaction-pool = { workspace = true, features = ["test-utils"] }
reth-ethereum-engine-primitives.workspace = true
## async ## async
futures-util.workspace = true futures-util.workspace = true

View File

@ -24,7 +24,6 @@ use reth_db::{
DatabaseEnv, DatabaseEnv,
}; };
use reth_db_common::init::init_genesis; use reth_db_common::init::init_genesis;
use reth_ethereum_engine_primitives::EthereumEngineValidator;
use reth_evm::test_utils::MockExecutorProvider; use reth_evm::test_utils::MockExecutorProvider;
use reth_execution_types::Chain; use reth_execution_types::Chain;
use reth_exex::{ExExContext, ExExEvent, ExExNotification, ExExNotifications, Wal}; use reth_exex::{ExExContext, ExExEvent, ExExNotification, ExExNotifications, Wal};
@ -41,10 +40,7 @@ use reth_node_builder::{
}; };
use reth_node_core::node_config::NodeConfig; use reth_node_core::node_config::NodeConfig;
use reth_node_ethereum::{ use reth_node_ethereum::{
node::{ node::{EthereumAddOns, EthereumNetworkBuilder, EthereumPayloadBuilder},
EthereumAddOns, EthereumEngineValidatorBuilder, EthereumNetworkBuilder,
EthereumPayloadBuilder,
},
EthEngineTypes, EthEvmConfig, EthEngineTypes, EthEvmConfig,
}; };
use reth_payload_builder::noop::NoopPayloadBuilderService; use reth_payload_builder::noop::NoopPayloadBuilderService;
@ -140,7 +136,6 @@ where
EthereumNetworkBuilder, EthereumNetworkBuilder,
TestExecutorBuilder, TestExecutorBuilder,
TestConsensusBuilder, TestConsensusBuilder,
EthereumEngineValidatorBuilder,
>; >;
type AddOns = EthereumAddOns< type AddOns = EthereumAddOns<
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>, NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
@ -154,7 +149,6 @@ where
.network(EthereumNetworkBuilder::default()) .network(EthereumNetworkBuilder::default())
.executor(TestExecutorBuilder::default()) .executor(TestExecutorBuilder::default())
.consensus(TestConsensusBuilder::default()) .consensus(TestConsensusBuilder::default())
.engine_validator(EthereumEngineValidatorBuilder::default())
} }
fn add_ons(&self) -> Self::AddOns { fn add_ons(&self) -> Self::AddOns {
@ -284,8 +278,6 @@ pub async fn test_exex_context_with_chain_spec(
let tasks = TaskManager::current(); let tasks = TaskManager::current();
let task_executor = tasks.executor(); let task_executor = tasks.executor();
let engine_validator = EthereumEngineValidator::new(chain_spec.clone());
let components = NodeAdapter::<FullNodeTypesAdapter<NodeTypesWithDBAdapter<TestNode, _>, _>, _> { let components = NodeAdapter::<FullNodeTypesAdapter<NodeTypesWithDBAdapter<TestNode, _>, _>, _> {
components: Components { components: Components {
transaction_pool, transaction_pool,
@ -294,7 +286,6 @@ pub async fn test_exex_context_with_chain_spec(
consensus, consensus,
network, network,
payload_builder, payload_builder,
engine_validator,
}, },
task_executor, task_executor,
provider, provider,

View File

@ -5,7 +5,6 @@ use std::{future::Future, marker::PhantomData};
use alloy_rpc_types_engine::JwtSecret; use alloy_rpc_types_engine::JwtSecret;
use reth_beacon_consensus::BeaconConsensusEngineHandle; use reth_beacon_consensus::BeaconConsensusEngineHandle;
use reth_consensus::Consensus; use reth_consensus::Consensus;
use reth_engine_primitives::EngineValidator;
use reth_evm::execute::BlockExecutorProvider; use reth_evm::execute::BlockExecutorProvider;
use reth_network_api::FullNetwork; use reth_network_api::FullNetwork;
use reth_node_core::node_config::NodeConfig; use reth_node_core::node_config::NodeConfig;
@ -64,9 +63,6 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
/// Network API. /// Network API.
type Network: FullNetwork; type Network: FullNetwork;
/// Validator for the engine API.
type EngineValidator: EngineValidator<<Self::Types as NodeTypesWithEngine>::Engine>;
/// Returns the transaction pool of the node. /// Returns the transaction pool of the node.
fn pool(&self) -> &Self::Pool; fn pool(&self) -> &Self::Pool;
@ -87,9 +83,6 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
&self, &self,
) -> &PayloadBuilderHandle<<Self::Types as NodeTypesWithEngine>::Engine>; ) -> &PayloadBuilderHandle<<Self::Types as NodeTypesWithEngine>::Engine>;
/// Returns the engine validator.
fn engine_validator(&self) -> &Self::EngineValidator;
/// Returns the provider of the node. /// Returns the provider of the node.
fn provider(&self) -> &Self::Provider; fn provider(&self) -> &Self::Provider;

View File

@ -97,7 +97,6 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
type Executor = C::Executor; type Executor = C::Executor;
type Network = C::Network; type Network = C::Network;
type Consensus = C::Consensus; type Consensus = C::Consensus;
type EngineValidator = C::EngineValidator;
fn pool(&self) -> &Self::Pool { fn pool(&self) -> &Self::Pool {
self.components.pool() self.components.pool()
@ -130,10 +129,6 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
fn consensus(&self) -> &Self::Consensus { fn consensus(&self) -> &Self::Consensus {
self.components.consensus() self.components.consensus()
} }
fn engine_validator(&self) -> &Self::EngineValidator {
self.components.engine_validator()
}
} }
impl<T: FullNodeTypes, C: NodeComponents<T>> Clone for NodeAdapter<T, C> { impl<T: FullNodeTypes, C: NodeComponents<T>> Clone for NodeAdapter<T, C> {

View File

@ -4,7 +4,6 @@ use std::{future::Future, marker::PhantomData};
use reth_consensus::Consensus; use reth_consensus::Consensus;
use reth_evm::execute::BlockExecutorProvider; use reth_evm::execute::BlockExecutorProvider;
use reth_node_api::{EngineValidator, NodeTypesWithEngine};
use reth_primitives::Header; use reth_primitives::Header;
use reth_transaction_pool::TransactionPool; use reth_transaction_pool::TransactionPool;
@ -16,8 +15,6 @@ use crate::{
BuilderContext, ConfigureEvm, FullNodeTypes, BuilderContext, ConfigureEvm, FullNodeTypes,
}; };
use super::EngineValidatorBuilder;
/// A generic, general purpose and customizable [`NodeComponentsBuilder`] implementation. /// A generic, general purpose and customizable [`NodeComponentsBuilder`] implementation.
/// ///
/// This type is stateful and captures the configuration of the node's components. /// This type is stateful and captures the configuration of the node's components.
@ -38,23 +35,22 @@ use super::EngineValidatorBuilder;
/// All component builders are captured in the builder state and will be consumed once the node is /// All component builders are captured in the builder state and will be consumed once the node is
/// launched. /// launched.
#[derive(Debug)] #[derive(Debug)]
pub struct ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> { pub struct ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB> {
pool_builder: PoolB, pool_builder: PoolB,
payload_builder: PayloadB, payload_builder: PayloadB,
network_builder: NetworkB, network_builder: NetworkB,
executor_builder: ExecB, executor_builder: ExecB,
consensus_builder: ConsB, consensus_builder: ConsB,
engine_validator_builder: EVB,
_marker: PhantomData<Node>, _marker: PhantomData<Node>,
} }
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
{ {
/// Configures the node types. /// Configures the node types.
pub fn node_types<Types>( pub fn node_types<Types>(
self, self,
) -> ComponentsBuilder<Types, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> ) -> ComponentsBuilder<Types, PoolB, PayloadB, NetworkB, ExecB, ConsB>
where where
Types: FullNodeTypes, Types: FullNodeTypes,
{ {
@ -64,7 +60,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
network_builder, network_builder,
executor_builder: evm_builder, executor_builder: evm_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} = self; } = self;
ComponentsBuilder { ComponentsBuilder {
@ -73,7 +68,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
payload_builder, payload_builder,
network_builder, network_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker: Default::default(), _marker: Default::default(),
} }
} }
@ -86,7 +80,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
network_builder: self.network_builder, network_builder: self.network_builder,
executor_builder: self.executor_builder, executor_builder: self.executor_builder,
consensus_builder: self.consensus_builder, consensus_builder: self.consensus_builder,
engine_validator_builder: self.engine_validator_builder,
_marker: self._marker, _marker: self._marker,
} }
} }
@ -99,7 +92,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
network_builder: self.network_builder, network_builder: self.network_builder,
executor_builder: self.executor_builder, executor_builder: self.executor_builder,
consensus_builder: self.consensus_builder, consensus_builder: self.consensus_builder,
engine_validator_builder: self.engine_validator_builder,
_marker: self._marker, _marker: self._marker,
} }
} }
@ -112,7 +104,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
network_builder: f(self.network_builder), network_builder: f(self.network_builder),
executor_builder: self.executor_builder, executor_builder: self.executor_builder,
consensus_builder: self.consensus_builder, consensus_builder: self.consensus_builder,
engine_validator_builder: self.engine_validator_builder,
_marker: self._marker, _marker: self._marker,
} }
} }
@ -125,7 +116,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
network_builder: self.network_builder, network_builder: self.network_builder,
executor_builder: f(self.executor_builder), executor_builder: f(self.executor_builder),
consensus_builder: self.consensus_builder, consensus_builder: self.consensus_builder,
engine_validator_builder: self.engine_validator_builder,
_marker: self._marker, _marker: self._marker,
} }
} }
@ -138,14 +128,13 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
network_builder: self.network_builder, network_builder: self.network_builder,
executor_builder: self.executor_builder, executor_builder: self.executor_builder,
consensus_builder: f(self.consensus_builder), consensus_builder: f(self.consensus_builder),
engine_validator_builder: self.engine_validator_builder,
_marker: self._marker, _marker: self._marker,
} }
} }
} }
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
where where
Node: FullNodeTypes, Node: FullNodeTypes,
{ {
@ -156,7 +145,7 @@ where
pub fn pool<PB>( pub fn pool<PB>(
self, self,
pool_builder: PB, pool_builder: PB,
) -> ComponentsBuilder<Node, PB, PayloadB, NetworkB, ExecB, ConsB, EVB> ) -> ComponentsBuilder<Node, PB, PayloadB, NetworkB, ExecB, ConsB>
where where
PB: PoolBuilder<Node>, PB: PoolBuilder<Node>,
{ {
@ -166,7 +155,6 @@ where
network_builder, network_builder,
executor_builder: evm_builder, executor_builder: evm_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} = self; } = self;
ComponentsBuilder { ComponentsBuilder {
@ -175,14 +163,13 @@ where
network_builder, network_builder,
executor_builder: evm_builder, executor_builder: evm_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} }
} }
} }
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
where where
Node: FullNodeTypes, Node: FullNodeTypes,
PoolB: PoolBuilder<Node>, PoolB: PoolBuilder<Node>,
@ -194,7 +181,7 @@ where
pub fn network<NB>( pub fn network<NB>(
self, self,
network_builder: NB, network_builder: NB,
) -> ComponentsBuilder<Node, PoolB, PayloadB, NB, ExecB, ConsB, EVB> ) -> ComponentsBuilder<Node, PoolB, PayloadB, NB, ExecB, ConsB>
where where
NB: NetworkBuilder<Node, PoolB::Pool>, NB: NetworkBuilder<Node, PoolB::Pool>,
{ {
@ -204,7 +191,6 @@ where
network_builder: _, network_builder: _,
executor_builder: evm_builder, executor_builder: evm_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} = self; } = self;
ComponentsBuilder { ComponentsBuilder {
@ -213,7 +199,6 @@ where
network_builder, network_builder,
executor_builder: evm_builder, executor_builder: evm_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} }
} }
@ -225,7 +210,7 @@ where
pub fn payload<PB>( pub fn payload<PB>(
self, self,
payload_builder: PB, payload_builder: PB,
) -> ComponentsBuilder<Node, PoolB, PB, NetworkB, ExecB, ConsB, EVB> ) -> ComponentsBuilder<Node, PoolB, PB, NetworkB, ExecB, ConsB>
where where
PB: PayloadServiceBuilder<Node, PoolB::Pool>, PB: PayloadServiceBuilder<Node, PoolB::Pool>,
{ {
@ -235,7 +220,6 @@ where
network_builder, network_builder,
executor_builder: evm_builder, executor_builder: evm_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} = self; } = self;
ComponentsBuilder { ComponentsBuilder {
@ -244,7 +228,6 @@ where
network_builder, network_builder,
executor_builder: evm_builder, executor_builder: evm_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} }
} }
@ -256,7 +239,7 @@ where
pub fn executor<EB>( pub fn executor<EB>(
self, self,
executor_builder: EB, executor_builder: EB,
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, EB, ConsB, EVB> ) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, EB, ConsB>
where where
EB: ExecutorBuilder<Node>, EB: ExecutorBuilder<Node>,
{ {
@ -266,7 +249,6 @@ where
network_builder, network_builder,
executor_builder: _, executor_builder: _,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} = self; } = self;
ComponentsBuilder { ComponentsBuilder {
@ -275,7 +257,6 @@ where
network_builder, network_builder,
executor_builder, executor_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} }
} }
@ -287,7 +268,7 @@ where
pub fn consensus<CB>( pub fn consensus<CB>(
self, self,
consensus_builder: CB, consensus_builder: CB,
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, CB, EVB> ) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, CB>
where where
CB: ConsensusBuilder<Node>, CB: ConsensusBuilder<Node>,
{ {
@ -297,7 +278,7 @@ where
network_builder, network_builder,
executor_builder, executor_builder,
consensus_builder: _, consensus_builder: _,
engine_validator_builder,
_marker, _marker,
} = self; } = self;
ComponentsBuilder { ComponentsBuilder {
@ -306,45 +287,13 @@ where
network_builder, network_builder,
executor_builder, executor_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker,
}
}
/// Configures the consensus builder.
///
/// This accepts a [`ConsensusBuilder`] instance that will be used to create the node's
/// components for consensus.
pub fn engine_validator<EngineVB>(
self,
engine_validator_builder: EngineVB,
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EngineVB>
where
EngineVB: EngineValidatorBuilder<Node>,
{
let Self {
pool_builder,
payload_builder,
network_builder,
executor_builder,
consensus_builder,
engine_validator_builder: _,
_marker,
} = self;
ComponentsBuilder {
pool_builder,
payload_builder,
network_builder,
executor_builder,
consensus_builder,
engine_validator_builder,
_marker, _marker,
} }
} }
} }
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> NodeComponentsBuilder<Node> impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB> NodeComponentsBuilder<Node>
for ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> for ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
where where
Node: FullNodeTypes, Node: FullNodeTypes,
PoolB: PoolBuilder<Node>, PoolB: PoolBuilder<Node>,
@ -352,16 +301,8 @@ where
PayloadB: PayloadServiceBuilder<Node, PoolB::Pool>, PayloadB: PayloadServiceBuilder<Node, PoolB::Pool>,
ExecB: ExecutorBuilder<Node>, ExecB: ExecutorBuilder<Node>,
ConsB: ConsensusBuilder<Node>, ConsB: ConsensusBuilder<Node>,
EVB: EngineValidatorBuilder<Node>,
{ {
type Components = Components< type Components = Components<Node, PoolB::Pool, ExecB::EVM, ExecB::Executor, ConsB::Consensus>;
Node,
PoolB::Pool,
ExecB::EVM,
ExecB::Executor,
ConsB::Consensus,
EVB::Validator,
>;
async fn build_components( async fn build_components(
self, self,
@ -373,7 +314,6 @@ where
network_builder, network_builder,
executor_builder: evm_builder, executor_builder: evm_builder,
consensus_builder, consensus_builder,
engine_validator_builder,
_marker, _marker,
} = self; } = self;
@ -382,7 +322,6 @@ where
let network = network_builder.build_network(context, pool.clone()).await?; let network = network_builder.build_network(context, pool.clone()).await?;
let payload_builder = payload_builder.spawn_payload_service(context, pool.clone()).await?; let payload_builder = payload_builder.spawn_payload_service(context, pool.clone()).await?;
let consensus = consensus_builder.build_consensus(context).await?; let consensus = consensus_builder.build_consensus(context).await?;
let engine_validator = engine_validator_builder.build_validator(context).await?;
Ok(Components { Ok(Components {
transaction_pool: pool, transaction_pool: pool,
@ -391,12 +330,11 @@ where
payload_builder, payload_builder,
executor, executor,
consensus, consensus,
engine_validator,
}) })
} }
} }
impl Default for ComponentsBuilder<(), (), (), (), (), (), ()> { impl Default for ComponentsBuilder<(), (), (), (), (), ()> {
fn default() -> Self { fn default() -> Self {
Self { Self {
pool_builder: (), pool_builder: (),
@ -404,7 +342,6 @@ impl Default for ComponentsBuilder<(), (), (), (), (), (), ()> {
network_builder: (), network_builder: (),
executor_builder: (), executor_builder: (),
consensus_builder: (), consensus_builder: (),
engine_validator_builder: (),
_marker: Default::default(), _marker: Default::default(),
} }
} }
@ -430,18 +367,17 @@ pub trait NodeComponentsBuilder<Node: FullNodeTypes>: Send {
) -> impl Future<Output = eyre::Result<Self::Components>> + Send; ) -> impl Future<Output = eyre::Result<Self::Components>> + Send;
} }
impl<Node, F, Fut, Pool, EVM, Executor, Cons, Val> NodeComponentsBuilder<Node> for F impl<Node, F, Fut, Pool, EVM, Executor, Cons> NodeComponentsBuilder<Node> for F
where where
Node: FullNodeTypes, Node: FullNodeTypes,
F: FnOnce(&BuilderContext<Node>) -> Fut + Send, F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
Fut: Future<Output = eyre::Result<Components<Node, Pool, EVM, Executor, Cons, Val>>> + Send, Fut: Future<Output = eyre::Result<Components<Node, Pool, EVM, Executor, Cons>>> + Send,
Pool: TransactionPool + Unpin + 'static, Pool: TransactionPool + Unpin + 'static,
EVM: ConfigureEvm<Header = Header>, EVM: ConfigureEvm<Header = Header>,
Executor: BlockExecutorProvider, Executor: BlockExecutorProvider,
Cons: Consensus + Clone + Unpin + 'static, Cons: Consensus + Clone + Unpin + 'static,
Val: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine> + Clone + Unpin + 'static,
{ {
type Components = Components<Node, Pool, EVM, Executor, Cons, Val>; type Components = Components<Node, Pool, EVM, Executor, Cons>;
fn build_components( fn build_components(
self, self,

View File

@ -1,38 +0,0 @@
//! Consensus component for the node builder.
use reth_node_api::{EngineValidator, NodeTypesWithEngine};
use crate::{BuilderContext, FullNodeTypes};
use std::future::Future;
/// A type that knows how to build the engine validator.
pub trait EngineValidatorBuilder<Node: FullNodeTypes>: Send {
/// The consensus implementation to build.
type Validator: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine>
+ Clone
+ Unpin
+ 'static;
/// Creates the engine validator.
fn build_validator(
self,
ctx: &BuilderContext<Node>,
) -> impl Future<Output = eyre::Result<Self::Validator>> + Send;
}
impl<Node, F, Fut, Validator> EngineValidatorBuilder<Node> for F
where
Node: FullNodeTypes,
Validator:
EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine> + Clone + Unpin + 'static,
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
Fut: Future<Output = eyre::Result<Validator>> + Send,
{
type Validator = Validator;
fn build_validator(
self,
ctx: &BuilderContext<Node>,
) -> impl Future<Output = eyre::Result<Self::Validator>> {
self(ctx)
}
}

View File

@ -9,7 +9,6 @@
mod builder; mod builder;
mod consensus; mod consensus;
mod engine;
mod execute; mod execute;
mod network; mod network;
mod payload; mod payload;
@ -17,7 +16,6 @@ mod pool;
pub use builder::*; pub use builder::*;
pub use consensus::*; pub use consensus::*;
pub use engine::*;
pub use execute::*; pub use execute::*;
pub use network::*; pub use network::*;
pub use payload::*; pub use payload::*;
@ -27,7 +25,7 @@ use reth_consensus::Consensus;
use reth_evm::execute::BlockExecutorProvider; use reth_evm::execute::BlockExecutorProvider;
use reth_network::NetworkHandle; use reth_network::NetworkHandle;
use reth_network_api::FullNetwork; use reth_network_api::FullNetwork;
use reth_node_api::{EngineValidator, NodeTypesWithEngine}; use reth_node_api::NodeTypesWithEngine;
use reth_payload_builder::PayloadBuilderHandle; use reth_payload_builder::PayloadBuilderHandle;
use reth_primitives::Header; use reth_primitives::Header;
use reth_transaction_pool::TransactionPool; use reth_transaction_pool::TransactionPool;
@ -55,9 +53,6 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
/// Network API. /// Network API.
type Network: FullNetwork; type Network: FullNetwork;
/// Validator for the engine API.
type EngineValidator: EngineValidator<<T::Types as NodeTypesWithEngine>::Engine>;
/// Returns the transaction pool of the node. /// Returns the transaction pool of the node.
fn pool(&self) -> &Self::Pool; fn pool(&self) -> &Self::Pool;
@ -75,16 +70,13 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
/// Returns the handle to the payload builder service. /// Returns the handle to the payload builder service.
fn payload_builder(&self) -> &PayloadBuilderHandle<<T::Types as NodeTypesWithEngine>::Engine>; fn payload_builder(&self) -> &PayloadBuilderHandle<<T::Types as NodeTypesWithEngine>::Engine>;
/// Returns the engine validator.
fn engine_validator(&self) -> &Self::EngineValidator;
} }
/// All the components of the node. /// All the components of the node.
/// ///
/// This provides access to all the components of the node. /// This provides access to all the components of the node.
#[derive(Debug)] #[derive(Debug)]
pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus, Validator> { pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus> {
/// The transaction pool of the node. /// The transaction pool of the node.
pub transaction_pool: Pool, pub transaction_pool: Pool,
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine. /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
@ -97,26 +89,22 @@ pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus, Valid
pub network: NetworkHandle, pub network: NetworkHandle,
/// The handle to the payload builder service. /// The handle to the payload builder service.
pub payload_builder: PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>, pub payload_builder: PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>,
/// The validator for the engine API.
pub engine_validator: Validator,
} }
impl<Node, Pool, EVM, Executor, Cons, Val> NodeComponents<Node> impl<Node, Pool, EVM, Executor, Cons> NodeComponents<Node>
for Components<Node, Pool, EVM, Executor, Cons, Val> for Components<Node, Pool, EVM, Executor, Cons>
where where
Node: FullNodeTypes, Node: FullNodeTypes,
Pool: TransactionPool + Unpin + 'static, Pool: TransactionPool + Unpin + 'static,
EVM: ConfigureEvm<Header = Header>, EVM: ConfigureEvm<Header = Header>,
Executor: BlockExecutorProvider, Executor: BlockExecutorProvider,
Cons: Consensus + Clone + Unpin + 'static, Cons: Consensus + Clone + Unpin + 'static,
Val: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine> + Clone + Unpin + 'static,
{ {
type Pool = Pool; type Pool = Pool;
type Evm = EVM; type Evm = EVM;
type Executor = Executor; type Executor = Executor;
type Consensus = Cons; type Consensus = Cons;
type Network = NetworkHandle; type Network = NetworkHandle;
type EngineValidator = Val;
fn pool(&self) -> &Self::Pool { fn pool(&self) -> &Self::Pool {
&self.transaction_pool &self.transaction_pool
@ -143,21 +131,15 @@ where
) -> &PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine> { ) -> &PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine> {
&self.payload_builder &self.payload_builder
} }
fn engine_validator(&self) -> &Self::EngineValidator {
&self.engine_validator
}
} }
impl<Node, Pool, EVM, Executor, Cons, Val> Clone impl<Node, Pool, EVM, Executor, Cons> Clone for Components<Node, Pool, EVM, Executor, Cons>
for Components<Node, Pool, EVM, Executor, Cons, Val>
where where
Node: FullNodeTypes, Node: FullNodeTypes,
Pool: TransactionPool, Pool: TransactionPool,
EVM: ConfigureEvm<Header = Header>, EVM: ConfigureEvm<Header = Header>,
Executor: BlockExecutorProvider, Executor: BlockExecutorProvider,
Cons: Consensus + Clone, Cons: Consensus + Clone,
Val: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine>,
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
@ -167,7 +149,6 @@ where
consensus: self.consensus.clone(), consensus: self.consensus.clone(),
network: self.network.clone(), network: self.network.clone(),
payload_builder: self.payload_builder.clone(), payload_builder: self.payload_builder.clone(),
engine_validator: self.engine_validator.clone(),
} }
} }
} }

View File

@ -2,6 +2,7 @@
use std::{ use std::{
fmt::{self, Debug}, fmt::{self, Debug},
future::Future,
marker::PhantomData, marker::PhantomData,
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
}; };
@ -9,7 +10,7 @@ use std::{
use alloy_rpc_types::engine::ClientVersionV1; use alloy_rpc_types::engine::ClientVersionV1;
use futures::TryFutureExt; use futures::TryFutureExt;
use reth_node_api::{ use reth_node_api::{
AddOnsContext, FullNodeComponents, NodeAddOns, NodeTypes, NodeTypesWithEngine, AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodeTypes, NodeTypesWithEngine,
}; };
use reth_node_core::{ use reth_node_core::{
node_config::NodeConfig, node_config::NodeConfig,
@ -327,31 +328,38 @@ where
/// Node add-ons containing RPC server configuration, with customizable eth API handler. /// Node add-ons containing RPC server configuration, with customizable eth API handler.
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
pub struct RpcAddOns<Node: FullNodeComponents, EthApi: EthApiTypes> { pub struct RpcAddOns<Node: FullNodeComponents, EthApi: EthApiTypes, EV> {
/// Additional RPC add-ons. /// Additional RPC add-ons.
pub hooks: RpcHooks<Node, EthApi>, pub hooks: RpcHooks<Node, EthApi>,
/// Builder for `EthApi` /// Builder for `EthApi`
eth_api_builder: Box<dyn FnOnce(&EthApiBuilderCtx<Node>) -> EthApi + Send + Sync>, eth_api_builder: Box<dyn FnOnce(&EthApiBuilderCtx<Node>) -> EthApi + Send + Sync>,
/// Engine validator
engine_validator_builder: EV,
_pd: PhantomData<(Node, EthApi)>, _pd: PhantomData<(Node, EthApi)>,
} }
impl<Node: FullNodeComponents, EthApi: EthApiTypes> Debug for RpcAddOns<Node, EthApi> { impl<Node: FullNodeComponents, EthApi: EthApiTypes, EV: Debug> Debug
for RpcAddOns<Node, EthApi, EV>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RpcAddOns") f.debug_struct("RpcAddOns")
.field("hooks", &self.hooks) .field("hooks", &self.hooks)
.field("eth_api_builder", &"...") .field("eth_api_builder", &"...")
.field("engine_validator_builder", &self.engine_validator_builder)
.finish() .finish()
} }
} }
impl<Node: FullNodeComponents, EthApi: EthApiTypes> RpcAddOns<Node, EthApi> { impl<Node: FullNodeComponents, EthApi: EthApiTypes, EV> RpcAddOns<Node, EthApi, EV> {
/// Creates a new instance of the RPC add-ons. /// Creates a new instance of the RPC add-ons.
pub fn new( pub fn new(
eth_api_builder: impl FnOnce(&EthApiBuilderCtx<Node>) -> EthApi + Send + Sync + 'static, eth_api_builder: impl FnOnce(&EthApiBuilderCtx<Node>) -> EthApi + Send + Sync + 'static,
engine_validator_builder: EV,
) -> Self { ) -> Self {
Self { Self {
hooks: RpcHooks::default(), hooks: RpcHooks::default(),
eth_api_builder: Box::new(eth_api_builder), eth_api_builder: Box::new(eth_api_builder),
engine_validator_builder,
_pd: PhantomData, _pd: PhantomData,
} }
} }
@ -377,23 +385,28 @@ impl<Node: FullNodeComponents, EthApi: EthApiTypes> RpcAddOns<Node, EthApi> {
} }
} }
impl<Node: FullNodeComponents, EthApi: EthApiTypes + EthApiBuilder<Node>> Default impl<Node, EthApi, EV> Default for RpcAddOns<Node, EthApi, EV>
for RpcAddOns<Node, EthApi> where
Node: FullNodeComponents,
EthApi: EthApiTypes + EthApiBuilder<Node>,
EV: Default,
{ {
fn default() -> Self { fn default() -> Self {
Self::new(EthApi::build) Self::new(EthApi::build, EV::default())
} }
} }
impl<N, EthApi> NodeAddOns<N> for RpcAddOns<N, EthApi> impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV>
where where
N: FullNodeComponents<Types: ProviderNodeTypes>, N: FullNodeComponents<Types: ProviderNodeTypes>,
EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static, EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static,
EV: EngineValidatorBuilder<N>,
{ {
type Handle = RpcHandle<N, EthApi>; type Handle = RpcHandle<N, EthApi>;
async fn launch_add_ons(self, ctx: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> { async fn launch_add_ons(self, ctx: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
let AddOnsContext { node, config, beacon_engine_handle, jwt_secret } = ctx; let AddOnsContext { node, config, beacon_engine_handle, jwt_secret } = ctx;
let Self { eth_api_builder, engine_validator_builder, hooks, _pd: _ } = self;
let client = ClientVersionV1 { let client = ClientVersionV1 {
code: CLIENT_CODE, code: CLIENT_CODE,
@ -411,7 +424,7 @@ where
Box::new(node.task_executor().clone()), Box::new(node.task_executor().clone()),
client, client,
EngineCapabilities::default(), EngineCapabilities::default(),
node.engine_validator().clone(), engine_validator_builder.build(&ctx).await?,
); );
info!(target: "reth::cli", "Engine API handler initialized"); info!(target: "reth::cli", "Engine API handler initialized");
@ -427,7 +440,7 @@ where
.with_executor(node.task_executor().clone()) .with_executor(node.task_executor().clone())
.with_evm_config(node.evm_config().clone()) .with_evm_config(node.evm_config().clone())
.with_block_executor(node.block_executor().clone()) .with_block_executor(node.block_executor().clone())
.build_with_auth_server(module_config, engine_api, self.eth_api_builder); .build_with_auth_server(module_config, engine_api, eth_api_builder);
// in dev mode we generate 20 random dev-signer accounts // in dev mode we generate 20 random dev-signer accounts
if config.dev.dev { if config.dev.dev {
@ -443,7 +456,7 @@ where
auth_module: &mut auth_module, auth_module: &mut auth_module,
}; };
let RpcHooks { on_rpc_started, extend_rpc_modules } = self.hooks; let RpcHooks { on_rpc_started, extend_rpc_modules } = hooks;
extend_rpc_modules.extend_rpc_modules(ctx)?; extend_rpc_modules.extend_rpc_modules(ctx)?;
@ -503,7 +516,7 @@ pub trait RethRpcAddOns<N: FullNodeComponents>:
fn hooks_mut(&mut self) -> &mut RpcHooks<N, Self::EthApi>; fn hooks_mut(&mut self) -> &mut RpcHooks<N, Self::EthApi>;
} }
impl<N: FullNodeComponents, EthApi: EthApiTypes> RethRpcAddOns<N> for RpcAddOns<N, EthApi> impl<N: FullNodeComponents, EthApi: EthApiTypes, EV> RethRpcAddOns<N> for RpcAddOns<N, EthApi, EV>
where where
Self: NodeAddOns<N, Handle = RpcHandle<N, EthApi>>, Self: NodeAddOns<N, Handle = RpcHandle<N, EthApi>>,
{ {
@ -525,3 +538,36 @@ impl<N: FullNodeComponents> EthApiBuilder<N> for EthApi<N::Provider, N::Pool, N:
Self::with_spawner(ctx) Self::with_spawner(ctx)
} }
} }
/// A type that knows how to build the engine validator.
pub trait EngineValidatorBuilder<Node: FullNodeComponents>: Send {
/// The consensus implementation to build.
type Validator: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine>
+ Clone
+ Unpin
+ 'static;
/// Creates the engine validator.
fn build(
self,
ctx: &AddOnsContext<'_, Node>,
) -> impl Future<Output = eyre::Result<Self::Validator>> + Send;
}
impl<Node, F, Fut, Validator> EngineValidatorBuilder<Node> for F
where
Node: FullNodeComponents,
Validator:
EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine> + Clone + Unpin + 'static,
F: FnOnce(&AddOnsContext<'_, Node>) -> Fut + Send,
Fut: Future<Output = eyre::Result<Validator>> + Send,
{
type Validator = Validator;
fn build(
self,
ctx: &AddOnsContext<'_, Node>,
) -> impl Future<Output = eyre::Result<Self::Validator>> {
self(ctx)
}
}

View File

@ -6,14 +6,16 @@ use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGenera
use reth_chainspec::{EthChainSpec, Hardforks}; use reth_chainspec::{EthChainSpec, Hardforks};
use reth_evm::ConfigureEvm; use reth_evm::ConfigureEvm;
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager}; use reth_network::{NetworkConfig, NetworkHandle, NetworkManager};
use reth_node_api::{EngineValidator, FullNodeComponents, NodeAddOns, NodePrimitives}; use reth_node_api::{
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodePrimitives,
};
use reth_node_builder::{ use reth_node_builder::{
components::{ components::{
ComponentsBuilder, ConsensusBuilder, EngineValidatorBuilder, ExecutorBuilder, ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
NetworkBuilder, PayloadServiceBuilder, PoolBuilder, PoolBuilderConfigOverrides, PayloadServiceBuilder, PoolBuilder, PoolBuilderConfigOverrides,
}, },
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine}, node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
rpc::{RethRpcAddOns, RpcAddOns, RpcHandle}, rpc::{EngineValidatorBuilder, RethRpcAddOns, RpcAddOns, RpcHandle},
BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig,
}; };
use reth_optimism_chainspec::OpChainSpec; use reth_optimism_chainspec::OpChainSpec;
@ -68,7 +70,6 @@ impl OptimismNode {
OptimismNetworkBuilder, OptimismNetworkBuilder,
OptimismExecutorBuilder, OptimismExecutorBuilder,
OptimismConsensusBuilder, OptimismConsensusBuilder,
OptimismEngineValidatorBuilder,
> >
where where
Node: FullNodeTypes< Node: FullNodeTypes<
@ -86,7 +87,6 @@ impl OptimismNode {
}) })
.executor(OptimismExecutorBuilder::default()) .executor(OptimismExecutorBuilder::default())
.consensus(OptimismConsensusBuilder::default()) .consensus(OptimismConsensusBuilder::default())
.engine_validator(OptimismEngineValidatorBuilder::default())
} }
} }
@ -103,7 +103,6 @@ where
OptimismNetworkBuilder, OptimismNetworkBuilder,
OptimismExecutorBuilder, OptimismExecutorBuilder,
OptimismConsensusBuilder, OptimismConsensusBuilder,
OptimismEngineValidatorBuilder,
>; >;
type AddOns = OptimismAddOns< type AddOns = OptimismAddOns<
@ -131,7 +130,9 @@ impl NodeTypesWithEngine for OptimismNode {
/// Add-ons w.r.t. optimism. /// Add-ons w.r.t. optimism.
#[derive(Debug)] #[derive(Debug)]
pub struct OptimismAddOns<N: FullNodeComponents>(pub RpcAddOns<N, OpEthApi<N>>); pub struct OptimismAddOns<N: FullNodeComponents>(
pub RpcAddOns<N, OpEthApi<N>, OptimismEngineValidatorBuilder>,
);
impl<N: FullNodeComponents> Default for OptimismAddOns<N> { impl<N: FullNodeComponents> Default for OptimismAddOns<N> {
fn default() -> Self { fn default() -> Self {
@ -142,12 +143,14 @@ impl<N: FullNodeComponents> Default for OptimismAddOns<N> {
impl<N: FullNodeComponents> OptimismAddOns<N> { impl<N: FullNodeComponents> OptimismAddOns<N> {
/// Create a new instance with the given `sequencer_http` URL. /// Create a new instance with the given `sequencer_http` URL.
pub fn new(sequencer_http: Option<String>) -> Self { pub fn new(sequencer_http: Option<String>) -> Self {
Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http))) Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http), Default::default()))
} }
} }
impl<N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>> NodeAddOns<N> impl<N> NodeAddOns<N> for OptimismAddOns<N>
for OptimismAddOns<N> where
N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>,
OptimismEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
{ {
type Handle = RpcHandle<N, OpEthApi<N>>; type Handle = RpcHandle<N, OpEthApi<N>>;
@ -159,8 +162,10 @@ impl<N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>> NodeAddOn
} }
} }
impl<N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>> RethRpcAddOns<N> impl<N> RethRpcAddOns<N> for OptimismAddOns<N>
for OptimismAddOns<N> where
N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>,
OptimismEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
{ {
type EthApi = OpEthApi<N>; type EthApi = OpEthApi<N>;
@ -458,12 +463,12 @@ pub struct OptimismEngineValidatorBuilder;
impl<Node, Types> EngineValidatorBuilder<Node> for OptimismEngineValidatorBuilder impl<Node, Types> EngineValidatorBuilder<Node> for OptimismEngineValidatorBuilder
where where
Types: NodeTypesWithEngine<ChainSpec = OpChainSpec>, Types: NodeTypesWithEngine<ChainSpec = OpChainSpec>,
Node: FullNodeTypes<Types = Types>, Node: FullNodeComponents<Types = Types>,
OptimismEngineValidator: EngineValidator<Types::Engine>, OptimismEngineValidator: EngineValidator<Types::Engine>,
{ {
type Validator = OptimismEngineValidator; type Validator = OptimismEngineValidator;
async fn build_validator(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Validator> { async fn build(self, ctx: &AddOnsContext<'_, Node>) -> eyre::Result<Self::Validator> {
Ok(OptimismEngineValidator::new(ctx.chain_spec())) Ok(OptimismEngineValidator::new(ctx.config.chain.clone()))
} }
} }

View File

@ -34,12 +34,15 @@ use alloy_rpc_types::{
use reth::{ use reth::{
api::PayloadTypes, api::PayloadTypes,
builder::{ builder::{
components::{ComponentsBuilder, EngineValidatorBuilder, PayloadServiceBuilder}, components::{ComponentsBuilder, PayloadServiceBuilder},
node::{NodeTypes, NodeTypesWithEngine}, node::{NodeTypes, NodeTypesWithEngine},
rpc::{EngineValidatorBuilder, RpcAddOns},
BuilderContext, FullNodeTypes, Node, NodeAdapter, NodeBuilder, NodeComponentsBuilder, BuilderContext, FullNodeTypes, Node, NodeAdapter, NodeBuilder, NodeComponentsBuilder,
PayloadBuilderConfig, PayloadBuilderConfig,
}, },
network::NetworkHandle,
providers::{CanonStateSubscriptions, StateProviderFactory}, providers::{CanonStateSubscriptions, StateProviderFactory},
rpc::eth::EthApi,
tasks::TaskManager, tasks::TaskManager,
transaction_pool::TransactionPool, transaction_pool::TransactionPool,
}; };
@ -50,13 +53,13 @@ use reth_basic_payload_builder::{
use reth_chainspec::{Chain, ChainSpec, ChainSpecProvider}; use reth_chainspec::{Chain, ChainSpec, ChainSpecProvider};
use reth_node_api::{ use reth_node_api::{
payload::{EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes}, payload::{EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes},
validate_version_specific_fields, EngineTypes, EngineValidator, PayloadAttributes, validate_version_specific_fields, AddOnsContext, EngineTypes, EngineValidator,
PayloadBuilderAttributes, FullNodeComponents, PayloadAttributes, PayloadBuilderAttributes,
}; };
use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig}; use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig};
use reth_node_ethereum::{ use reth_node_ethereum::{
node::{ node::{
EthereumAddOns, EthereumConsensusBuilder, EthereumExecutorBuilder, EthereumNetworkBuilder, EthereumConsensusBuilder, EthereumExecutorBuilder, EthereumNetworkBuilder,
EthereumPoolBuilder, EthereumPoolBuilder,
}, },
EthEvmConfig, EthEvmConfig,
@ -202,12 +205,14 @@ pub struct CustomEngineValidatorBuilder;
impl<N> EngineValidatorBuilder<N> for CustomEngineValidatorBuilder impl<N> EngineValidatorBuilder<N> for CustomEngineValidatorBuilder
where where
N: FullNodeTypes<Types: NodeTypesWithEngine<Engine = CustomEngineTypes, ChainSpec = ChainSpec>>, N: FullNodeComponents<
Types: NodeTypesWithEngine<Engine = CustomEngineTypes, ChainSpec = ChainSpec>,
>,
{ {
type Validator = CustomEngineValidator; type Validator = CustomEngineValidator;
async fn build_validator(self, ctx: &BuilderContext<N>) -> eyre::Result<Self::Validator> { async fn build(self, ctx: &AddOnsContext<'_, N>) -> eyre::Result<Self::Validator> {
Ok(CustomEngineValidator { chain_spec: ctx.chain_spec() }) Ok(CustomEngineValidator { chain_spec: ctx.config.chain.clone() })
} }
} }
@ -226,6 +231,18 @@ impl NodeTypesWithEngine for MyCustomNode {
type Engine = CustomEngineTypes; type Engine = CustomEngineTypes;
} }
/// Custom addons configuring RPC types
pub type MyNodeAddOns<N> = RpcAddOns<
N,
EthApi<
<N as FullNodeTypes>::Provider,
<N as FullNodeComponents>::Pool,
NetworkHandle,
<N as FullNodeComponents>::Evm,
>,
CustomEngineValidatorBuilder,
>;
/// Implement the Node trait for the custom node /// Implement the Node trait for the custom node
/// ///
/// This provides a preset configuration for the node /// This provides a preset configuration for the node
@ -240,9 +257,8 @@ where
EthereumNetworkBuilder, EthereumNetworkBuilder,
EthereumExecutorBuilder, EthereumExecutorBuilder,
EthereumConsensusBuilder, EthereumConsensusBuilder,
CustomEngineValidatorBuilder,
>; >;
type AddOns = EthereumAddOns< type AddOns = MyNodeAddOns<
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>, NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
>; >;
@ -254,11 +270,10 @@ where
.network(EthereumNetworkBuilder::default()) .network(EthereumNetworkBuilder::default())
.executor(EthereumExecutorBuilder::default()) .executor(EthereumExecutorBuilder::default())
.consensus(EthereumConsensusBuilder::default()) .consensus(EthereumConsensusBuilder::default())
.engine_validator(CustomEngineValidatorBuilder::default())
} }
fn add_ons(&self) -> Self::AddOns { fn add_ons(&self) -> Self::AddOns {
EthereumAddOns::default() MyNodeAddOns::default()
} }
} }