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