diff --git a/crates/e2e-test-utils/src/lib.rs b/crates/e2e-test-utils/src/lib.rs index 25fb77f01e73..942f9e869728 100644 --- a/crates/e2e-test-utils/src/lib.rs +++ b/crates/e2e-test-utils/src/lib.rs @@ -15,7 +15,7 @@ use reth_chainspec::ChainSpec; use reth_db::{test_utils::TempDatabase, DatabaseEnv}; use reth_node_builder::{ components::NodeComponentsBuilder, rpc::EthApiBuilderProvider, FullNodeTypesAdapter, Node, - NodeAdapter, NodeAddOns, NodeComponents, NodeTypes, RethFullAdapter, + NodeAdapter, NodeAddOns, NodeComponents, NodeTypesWithEngine, RethFullAdapter, }; use reth_provider::providers::BlockchainProvider; use tracing::{span, Level}; @@ -51,7 +51,7 @@ pub async fn setup( is_dev: bool, ) -> eyre::Result<(Vec>, TaskManager, Wallet)> where - N: Default + Node> + NodeTypes, + N: Default + Node> + NodeTypesWithEngine, N::ComponentsBuilder: NodeComponentsBuilder< TmpNodeAdapter, Components: NodeComponents, Network: PeersHandleProvider>, diff --git a/crates/e2e-test-utils/src/node.rs b/crates/e2e-test-utils/src/node.rs index 0040801fa3fa..f5452198397a 100644 --- a/crates/e2e-test-utils/src/node.rs +++ b/crates/e2e-test-utils/src/node.rs @@ -15,7 +15,7 @@ use reth::{ types::engine::PayloadStatusEnum, }, }; -use reth_node_builder::{EthApiTypes, NodeAddOns, NodeTypes}; +use reth_node_builder::{EthApiTypes, NodeAddOns, NodeTypesWithEngine}; use reth_primitives::{BlockHash, BlockNumber, Bytes, B256}; use reth_rpc_types::WithOtherFields; use reth_stages_types::StageId; @@ -118,8 +118,8 @@ where &mut self, attributes_generator: impl Fn(u64) -> ::PayloadBuilderAttributes, ) -> eyre::Result<( - <::Engine as PayloadTypes>::BuiltPayload, - <::Engine as PayloadTypes>::PayloadBuilderAttributes, + <::Engine as PayloadTypes>::BuiltPayload, + <::Engine as PayloadTypes>::PayloadBuilderAttributes, )> where ::ExecutionPayloadV3: @@ -144,7 +144,7 @@ where attributes_generator: impl Fn(u64) -> ::PayloadBuilderAttributes, ) -> eyre::Result<( ::BuiltPayload, - <::Engine as PayloadTypes>::PayloadBuilderAttributes, + <::Engine as PayloadTypes>::PayloadBuilderAttributes, )> where ::ExecutionPayloadV3: diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index ce1498a15f33..24628019bb8f 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -17,7 +17,7 @@ use reth_node_builder::{ ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, PayloadServiceBuilder, PoolBuilder, }, - node::{FullNodeTypes, NodeTypes}, + node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine}, BuilderContext, ConfigureEvm, Node, PayloadBuilderConfig, PayloadTypes, }; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; @@ -48,7 +48,7 @@ impl EthereumNode { > where Node: FullNodeTypes, - ::Engine: PayloadTypes< + ::Engine: PayloadTypes< BuiltPayload = EthBuiltPayload, PayloadAttributes = EthPayloadAttributes, PayloadBuilderAttributes = EthPayloadBuilderAttributes, @@ -66,10 +66,13 @@ impl EthereumNode { impl NodeTypes for EthereumNode { type Primitives = (); - type Engine = EthEngineTypes; type ChainSpec = ChainSpec; } +impl NodeTypesWithEngine for EthereumNode { + type Engine = EthEngineTypes; +} + /// Add-ons w.r.t. l1 ethereum. #[derive(Debug, Clone)] pub struct EthereumAddOns; @@ -215,7 +218,7 @@ where Node: FullNodeTypes, Evm: ConfigureEvm, Pool: TransactionPool + Unpin + 'static, - ::Engine: PayloadTypes< + ::Engine: PayloadTypes< BuiltPayload = EthBuiltPayload, PayloadAttributes = EthPayloadAttributes, PayloadBuilderAttributes = EthPayloadBuilderAttributes, diff --git a/crates/exex/test-utils/src/lib.rs b/crates/exex/test-utils/src/lib.rs index b363823eab04..c470cd1d9cbe 100644 --- a/crates/exex/test-utils/src/lib.rs +++ b/crates/exex/test-utils/src/lib.rs @@ -18,7 +18,7 @@ use reth_evm::test_utils::MockExecutorProvider; use reth_execution_types::Chain; use reth_exex::{ExExContext, ExExEvent, ExExNotification}; use reth_network::{config::SecretKey, NetworkConfigBuilder, NetworkManager}; -use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes}; +use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes, NodeTypesWithEngine}; use reth_node_builder::{ components::{ Components, ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NodeComponentsBuilder, @@ -110,10 +110,13 @@ pub struct TestNode; impl NodeTypes for TestNode { type Primitives = (); - type Engine = EthEngineTypes; type ChainSpec = ChainSpec; } +impl NodeTypesWithEngine for TestNode { + type Engine = EthEngineTypes; +} + impl Node for TestNode where N: FullNodeTypes, diff --git a/crates/node/api/src/node.rs b/crates/node/api/src/node.rs index 50e87f98b7c3..275cdc5a1f65 100644 --- a/crates/node/api/src/node.rs +++ b/crates/node/api/src/node.rs @@ -17,55 +17,99 @@ use reth_transaction_pool::TransactionPool; use crate::{primitives::NodePrimitives, ConfigureEvm, EngineTypes}; -/// The type that configures the essential types of an ethereum like node. +/// The type that configures the essential types of an Ethereum-like node. /// -/// This includes the primitive types of a node, the engine API types for communication with the -/// consensus layer. +/// This includes the primitive types of a node. /// /// This trait is intended to be stateless and only define the types of the node. pub trait NodeTypes: Send + Sync + Unpin + 'static { /// The node's primitive types, defining basic operations and structures. type Primitives: NodePrimitives; - /// The node's engine types, defining the interaction with the consensus engine. - type Engine: EngineTypes; /// The type used for configuration of the EVM. type ChainSpec: EthChainSpec; } -/// A [`NodeTypes`] type builder +/// The type that configures an Ethereum-like node with an engine for consensus. +pub trait NodeTypesWithEngine: NodeTypes { + /// The node's engine types, defining the interaction with the consensus engine. + type Engine: EngineTypes; +} + +/// A [`NodeTypes`] type builder. +#[derive(Default, Debug)] +pub struct AnyNodeTypes

(PhantomData

, PhantomData); + +impl AnyNodeTypes { + /// Sets the `Primitives` associated type. + pub const fn primitives(self) -> AnyNodeTypes { + AnyNodeTypes::(PhantomData::, PhantomData::) + } + + /// Sets the `ChainSpec` associated type. + pub const fn chain_spec(self) -> AnyNodeTypes { + AnyNodeTypes::(PhantomData::

, PhantomData::) + } +} + +impl NodeTypes for AnyNodeTypes +where + P: NodePrimitives + Send + Sync + Unpin + 'static, + C: EthChainSpec, +{ + type Primitives = P; + type ChainSpec = C; +} + +/// A [`NodeTypesWithEngine`] type builder. #[derive(Default, Debug)] -pub struct AnyNodeTypes

(PhantomData

, PhantomData, PhantomData); +pub struct AnyNodeTypesWithEngine

{ + /// Embedding the basic node types. + base: AnyNodeTypes, + /// Phantom data for the engine. + _engine: PhantomData, +} -impl AnyNodeTypes { +impl AnyNodeTypesWithEngine { /// Sets the `Primitives` associated type. - pub const fn primitives(self) -> AnyNodeTypes { - AnyNodeTypes::(PhantomData::, PhantomData::, PhantomData::) + pub const fn primitives(self) -> AnyNodeTypesWithEngine { + AnyNodeTypesWithEngine { base: self.base.primitives::(), _engine: PhantomData } } /// Sets the `Engine` associated type. - pub const fn engine(self) -> AnyNodeTypes { - AnyNodeTypes::(PhantomData::

, PhantomData::, PhantomData::) + pub const fn engine(self) -> AnyNodeTypesWithEngine { + AnyNodeTypesWithEngine { base: self.base, _engine: PhantomData:: } + } + + /// Sets the `ChainSpec` associated type. + pub const fn chain_spec(self) -> AnyNodeTypesWithEngine { + AnyNodeTypesWithEngine { base: self.base.chain_spec::(), _engine: PhantomData } } } -impl NodeTypes for AnyNodeTypes +impl NodeTypes for AnyNodeTypesWithEngine where P: NodePrimitives + Send + Sync + Unpin + 'static, E: EngineTypes + Send + Sync + Unpin, C: EthChainSpec, { type Primitives = P; + type ChainSpec = C; +} +impl NodeTypesWithEngine for AnyNodeTypesWithEngine +where + P: NodePrimitives + Send + Sync + Unpin + 'static, + E: EngineTypes + Send + Sync + Unpin, + C: EthChainSpec, +{ type Engine = E; - - type ChainSpec = C; } -/// A helper trait that is downstream of the [`NodeTypes`] trait and adds stateful components to the -/// node. +/// A helper trait that is downstream of the [`NodeTypesWithEngine`] trait and adds stateful +/// components to the node. /// /// Its types are configured by node internally and are not intended to be user configurable. -pub trait FullNodeTypes: NodeTypes + 'static { +pub trait FullNodeTypes: NodeTypesWithEngine + 'static { /// Underlying database type used by the node to store and retrieve data. type DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static; /// The provider type used to interact with the node. @@ -104,18 +148,26 @@ impl Clone for FullNodeTypesAdapter { impl NodeTypes for FullNodeTypesAdapter where - Types: NodeTypes, + Types: NodeTypesWithEngine, DB: Send + Sync + Unpin + 'static, Provider: Send + Sync + Unpin + 'static, { type Primitives = Types::Primitives; - type Engine = Types::Engine; type ChainSpec = Types::ChainSpec; } +impl NodeTypesWithEngine for FullNodeTypesAdapter +where + Types: NodeTypesWithEngine, + DB: Send + Sync + Unpin + 'static, + Provider: Send + Sync + Unpin + 'static, +{ + type Engine = Types::Engine; +} + impl FullNodeTypes for FullNodeTypesAdapter where - Types: NodeTypes, + Types: NodeTypesWithEngine, Provider: FullProvider, DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, { diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index 52af467cb5cd..7f6338eadd7d 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -21,7 +21,7 @@ use reth_exex::ExExContext; use reth_network::{ NetworkBuilder, NetworkConfig, NetworkConfigBuilder, NetworkHandle, NetworkManager, }; -use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeAddOns, NodeTypes}; +use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeAddOns, NodeTypesWithEngine}; use reth_node_core::{ cli::config::{PayloadBuilderConfig, RethTransactionPoolConfig}, dirs::{ChainPath, DataDirPath}, @@ -58,8 +58,8 @@ pub type RethFullAdapter = FullNodeTypesAdapter = FullNodeTypesAdapter(self) -> NodeBuilderWithTypes> where - T: NodeTypes, + T: NodeTypesWithEngine, { self.with_types_and_provider() } @@ -218,7 +218,7 @@ where self, ) -> NodeBuilderWithTypes> where - T: NodeTypes, + T: NodeTypesWithEngine, P: FullProvider, { NodeBuilderWithTypes::new(self.config, self.database) @@ -266,7 +266,7 @@ where /// Configures the types of the node. pub fn with_types(self) -> WithLaunchContext>> where - T: NodeTypes, + T: NodeTypesWithEngine, { WithLaunchContext { builder: self.builder.with_types(), task_executor: self.task_executor } } @@ -276,7 +276,7 @@ where self, ) -> WithLaunchContext>> where - T: NodeTypes, + T: NodeTypesWithEngine, P: FullProvider, { WithLaunchContext { @@ -475,7 +475,7 @@ where impl WithLaunchContext, CB, AO>> where DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static, - T: NodeTypes, + T: NodeTypesWithEngine, CB: NodeComponentsBuilder>, AO: NodeAddOns< NodeAdapter, CB::Components>, diff --git a/crates/node/builder/src/builder/states.rs b/crates/node/builder/src/builder/states.rs index f6915a3db392..e31ea363f996 100644 --- a/crates/node/builder/src/builder/states.rs +++ b/crates/node/builder/src/builder/states.rs @@ -8,7 +8,9 @@ use std::{fmt, future::Future, marker::PhantomData}; use reth_exex::ExExContext; -use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes}; +use reth_node_api::{ + FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithEngine, +}; use reth_node_core::{ node_config::NodeConfig, rpc::eth::{helpers::AddDevSigners, FullEthApiServer}, @@ -90,10 +92,13 @@ pub struct NodeAdapter> { impl> NodeTypes for NodeAdapter { type Primitives = T::Primitives; - type Engine = T::Engine; type ChainSpec = T::ChainSpec; } +impl> NodeTypesWithEngine for NodeAdapter { + type Engine = T::Engine; +} + impl> FullNodeTypes for NodeAdapter { type DB = T::DB; type Provider = T::Provider; diff --git a/crates/node/builder/src/components/mod.rs b/crates/node/builder/src/components/mod.rs index e2d35c470661..0d2af5b976b7 100644 --- a/crates/node/builder/src/components/mod.rs +++ b/crates/node/builder/src/components/mod.rs @@ -35,7 +35,9 @@ use crate::{ConfigureEvm, FullNodeTypes}; /// - transaction pool /// - network /// - payload builder. -pub trait NodeComponents: Clone + Unpin + Send + Sync + 'static { +pub trait NodeComponents: + Clone + Unpin + Send + Sync + 'static +{ /// The transaction pool of the node. type Pool: TransactionPool + Unpin; @@ -67,7 +69,7 @@ pub trait NodeComponents: Clone + Unpin + Send + Sync fn network(&self) -> &Self::Network; /// Returns the handle to the payload builder service. - fn payload_builder(&self) -> &PayloadBuilderHandle; + fn payload_builder(&self) -> &PayloadBuilderHandle; } /// All the components of the node. diff --git a/crates/node/builder/src/node.rs b/crates/node/builder/src/node.rs index 4b54b09cdf84..c27b85d41ed5 100644 --- a/crates/node/builder/src/node.rs +++ b/crates/node/builder/src/node.rs @@ -1,5 +1,5 @@ // re-export the node api types -pub use reth_node_api::{FullNodeTypes, NodeTypes}; +pub use reth_node_api::{FullNodeTypes, NodeTypes, NodeTypesWithEngine}; use std::{marker::PhantomData, sync::Arc}; @@ -20,10 +20,10 @@ use crate::{ NodeAdapter, NodeAddOns, }; -/// A [`crate::Node`] is a [`NodeTypes`] that comes with preconfigured components. +/// A [`crate::Node`] is a [`NodeTypesWithEngine`] that comes with preconfigured components. /// /// This can be used to configure the builder with a preset of components. -pub trait Node: NodeTypes + Clone { +pub trait Node: NodeTypesWithEngine + Clone { /// The type that builds the node's components. type ComponentsBuilder: NodeComponentsBuilder; @@ -60,11 +60,18 @@ where { type Primitives = N::Primitives; - type Engine = N::Engine; - type ChainSpec = N::ChainSpec; } +impl NodeTypesWithEngine for AnyNode +where + N: FullNodeTypes, + C: Send + Sync + Unpin + 'static, + AO: Send + Sync + Unpin + Clone + 'static, +{ + type Engine = N::Engine; +} + impl Node for AnyNode where N: FullNodeTypes + Clone, diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 823395d4ac08..377038472087 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -13,7 +13,7 @@ use reth_node_builder::{ ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, PayloadServiceBuilder, PoolBuilder, }, - node::{FullNodeTypes, NodeTypes}, + node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine}, BuilderContext, Node, PayloadBuilderConfig, }; use reth_optimism_consensus::OptimismBeaconConsensus; @@ -100,10 +100,13 @@ where impl NodeTypes for OptimismNode { type Primitives = (); - type Engine = OptimismEngineTypes; type ChainSpec = ChainSpec; } +impl NodeTypesWithEngine for OptimismNode { + type Engine = OptimismEngineTypes; +} + /// Add-ons w.r.t. optimism. #[derive(Debug, Clone)] pub struct OptimismAddOns; diff --git a/examples/custom-engine-types/src/main.rs b/examples/custom-engine-types/src/main.rs index 9980be374f40..c58111f86deb 100644 --- a/examples/custom-engine-types/src/main.rs +++ b/examples/custom-engine-types/src/main.rs @@ -27,7 +27,7 @@ use reth::{ api::PayloadTypes, builder::{ components::{ComponentsBuilder, PayloadServiceBuilder}, - node::NodeTypes, + node::{NodeTypes, NodeTypesWithEngine}, BuilderContext, FullNodeTypes, Node, NodeBuilder, PayloadBuilderConfig, }, primitives::revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg}, @@ -194,11 +194,14 @@ struct MyCustomNode; /// Configure the node types impl NodeTypes for MyCustomNode { type Primitives = (); - // use the custom engine types - type Engine = CustomEngineTypes; type ChainSpec = ChainSpec; } +/// Configure the node types with the custom engine types +impl NodeTypesWithEngine for MyCustomNode { + type Engine = CustomEngineTypes; +} + /// Implement the Node trait for the custom node /// /// This provides a preset configuration for the node