reth_node_builder/components/
mod.rs

1//! Support for configuring the components of a node.
2//!
3//! Customizable components of the node include:
4//!  - The transaction pool.
5//!  - The network implementation.
6//!  - The payload builder service.
7//!
8//! Components depend on a fully type configured node: [FullNodeTypes](crate::node::FullNodeTypes).
9
10mod builder;
11mod consensus;
12mod execute;
13mod network;
14mod payload;
15mod pool;
16
17pub use builder::*;
18pub use consensus::*;
19pub use execute::*;
20pub use network::*;
21pub use payload::*;
22pub use pool::*;
23use reth_network_p2p::BlockClient;
24use reth_payload_builder::PayloadBuilderHandle;
25use std::fmt::Debug;
26
27use crate::{ConfigureEvm, FullNodeTypes};
28use reth_consensus::{ConsensusError, FullConsensus};
29use reth_evm::execute::BlockExecutorProvider;
30use reth_network::{NetworkHandle, NetworkPrimitives};
31use reth_network_api::FullNetwork;
32use reth_node_api::{BlockTy, BodyTy, HeaderTy, NodeTypes, PrimitivesTy, TxTy};
33use reth_transaction_pool::{PoolTransaction, TransactionPool};
34
35/// An abstraction over the components of a node, consisting of:
36///  - evm and executor
37///  - transaction pool
38///  - network
39///  - payload builder.
40pub trait NodeComponents<T: FullNodeTypes>: Clone + Debug + Unpin + Send + Sync + 'static {
41    /// The transaction pool of the node.
42    type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<T::Types>>> + Unpin;
43
44    /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
45    type Evm: ConfigureEvm<Primitives = <T::Types as NodeTypes>::Primitives>;
46
47    /// The type that knows how to execute blocks.
48    type Executor: BlockExecutorProvider<Primitives = <T::Types as NodeTypes>::Primitives>;
49
50    /// The consensus type of the node.
51    type Consensus: FullConsensus<<T::Types as NodeTypes>::Primitives, Error = ConsensusError>
52        + Clone
53        + Unpin
54        + 'static;
55
56    /// Network API.
57    type Network: FullNetwork<Client: BlockClient<Block = BlockTy<T::Types>>>;
58
59    /// Returns the transaction pool of the node.
60    fn pool(&self) -> &Self::Pool;
61
62    /// Returns the node's evm config.
63    fn evm_config(&self) -> &Self::Evm;
64
65    /// Returns the node's executor type.
66    fn block_executor(&self) -> &Self::Executor;
67
68    /// Returns the node's consensus type.
69    fn consensus(&self) -> &Self::Consensus;
70
71    /// Returns the handle to the network
72    fn network(&self) -> &Self::Network;
73
74    /// Returns the handle to the payload builder service handling payload building requests from
75    /// the engine.
76    fn payload_builder_handle(&self) -> &PayloadBuilderHandle<<T::Types as NodeTypes>::Payload>;
77}
78
79/// All the components of the node.
80///
81/// This provides access to all the components of the node.
82#[derive(Debug)]
83pub struct Components<Node: FullNodeTypes, N: NetworkPrimitives, Pool, EVM, Executor, Consensus> {
84    /// The transaction pool of the node.
85    pub transaction_pool: Pool,
86    /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
87    pub evm_config: EVM,
88    /// The node's executor type used to execute individual blocks and batches of blocks.
89    pub executor: Executor,
90    /// The consensus implementation of the node.
91    pub consensus: Consensus,
92    /// The network implementation of the node.
93    pub network: NetworkHandle<N>,
94    /// The handle to the payload builder service.
95    pub payload_builder_handle: PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload>,
96}
97
98impl<Node, Pool, EVM, Executor, Cons, N> NodeComponents<Node>
99    for Components<Node, N, Pool, EVM, Executor, Cons>
100where
101    Node: FullNodeTypes,
102    N: NetworkPrimitives<
103        BlockHeader = HeaderTy<Node::Types>,
104        BlockBody = BodyTy<Node::Types>,
105        Block = BlockTy<Node::Types>,
106    >,
107    Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
108        + Unpin
109        + 'static,
110    EVM: ConfigureEvm<Primitives = PrimitivesTy<Node::Types>> + 'static,
111    Executor: BlockExecutorProvider<Primitives = PrimitivesTy<Node::Types>>,
112    Cons:
113        FullConsensus<PrimitivesTy<Node::Types>, Error = ConsensusError> + Clone + Unpin + 'static,
114{
115    type Pool = Pool;
116    type Evm = EVM;
117    type Executor = Executor;
118    type Consensus = Cons;
119    type Network = NetworkHandle<N>;
120
121    fn pool(&self) -> &Self::Pool {
122        &self.transaction_pool
123    }
124
125    fn evm_config(&self) -> &Self::Evm {
126        &self.evm_config
127    }
128
129    fn block_executor(&self) -> &Self::Executor {
130        &self.executor
131    }
132
133    fn consensus(&self) -> &Self::Consensus {
134        &self.consensus
135    }
136
137    fn network(&self) -> &Self::Network {
138        &self.network
139    }
140
141    fn payload_builder_handle(&self) -> &PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload> {
142        &self.payload_builder_handle
143    }
144}
145
146impl<Node, N, Pool, EVM, Executor, Cons> Clone for Components<Node, N, Pool, EVM, Executor, Cons>
147where
148    N: NetworkPrimitives,
149    Node: FullNodeTypes,
150    Pool: TransactionPool,
151    EVM: ConfigureEvm,
152    Executor: BlockExecutorProvider,
153    Cons: Clone,
154{
155    fn clone(&self) -> Self {
156        Self {
157            transaction_pool: self.transaction_pool.clone(),
158            evm_config: self.evm_config.clone(),
159            executor: self.executor.clone(),
160            consensus: self.consensus.clone(),
161            network: self.network.clone(),
162            payload_builder_handle: self.payload_builder_handle.clone(),
163        }
164    }
165}