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::*;
23
24use crate::{ConfigureEvm, FullNodeTypes};
25use reth_consensus::FullConsensus;
26use reth_network::types::NetPrimitivesFor;
27use reth_network_api::FullNetwork;
28use reth_node_api::{NodeTypes, PrimitivesTy, TxTy};
29use reth_payload_builder::PayloadBuilderHandle;
30use reth_transaction_pool::{PoolPooledTx, PoolTransaction, TransactionPool};
31use std::fmt::Debug;
32
33/// An abstraction over the components of a node, consisting of:
34///  - evm and executor
35///  - transaction pool
36///  - network
37///  - payload builder.
38pub trait NodeComponents<T: FullNodeTypes>: Clone + Debug + Unpin + Send + Sync + 'static {
39    /// The transaction pool of the node.
40    type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<T::Types>>> + Unpin;
41
42    /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
43    type Evm: ConfigureEvm<Primitives = <T::Types as NodeTypes>::Primitives>;
44
45    /// The consensus type of the node.
46    type Consensus: FullConsensus<<T::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static;
47
48    /// Network API.
49    type Network: FullNetwork<Primitives: NetPrimitivesFor<<T::Types as NodeTypes>::Primitives>>;
50
51    /// Returns the transaction pool of the node.
52    fn pool(&self) -> &Self::Pool;
53
54    /// Returns the node's evm config.
55    fn evm_config(&self) -> &Self::Evm;
56
57    /// Returns the node's consensus type.
58    fn consensus(&self) -> &Self::Consensus;
59
60    /// Returns the handle to the network
61    fn network(&self) -> &Self::Network;
62
63    /// Returns the handle to the payload builder service handling payload building requests from
64    /// the engine.
65    fn payload_builder_handle(&self) -> &PayloadBuilderHandle<<T::Types as NodeTypes>::Payload>;
66}
67
68/// All the components of the node.
69///
70/// This provides access to all the components of the node.
71#[derive(Debug)]
72pub struct Components<Node: FullNodeTypes, Network, Pool, EVM, Consensus> {
73    /// The transaction pool of the node.
74    pub transaction_pool: Pool,
75    /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
76    pub evm_config: EVM,
77    /// The consensus implementation of the node.
78    pub consensus: Consensus,
79    /// The network implementation of the node.
80    pub network: Network,
81    /// The handle to the payload builder service.
82    pub payload_builder_handle: PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload>,
83}
84
85impl<Node, Pool, EVM, Cons, Network> NodeComponents<Node>
86    for Components<Node, Network, Pool, EVM, Cons>
87where
88    Node: FullNodeTypes,
89    Network: FullNetwork<
90        Primitives: NetPrimitivesFor<
91            PrimitivesTy<Node::Types>,
92            PooledTransaction = PoolPooledTx<Pool>,
93        >,
94    >,
95    Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
96        + Unpin
97        + 'static,
98    EVM: ConfigureEvm<Primitives = PrimitivesTy<Node::Types>> + 'static,
99    Cons: FullConsensus<PrimitivesTy<Node::Types>> + Clone + Unpin + 'static,
100{
101    type Pool = Pool;
102    type Evm = EVM;
103    type Consensus = Cons;
104    type Network = Network;
105
106    fn pool(&self) -> &Self::Pool {
107        &self.transaction_pool
108    }
109
110    fn evm_config(&self) -> &Self::Evm {
111        &self.evm_config
112    }
113
114    fn consensus(&self) -> &Self::Consensus {
115        &self.consensus
116    }
117
118    fn network(&self) -> &Self::Network {
119        &self.network
120    }
121
122    fn payload_builder_handle(&self) -> &PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload> {
123        &self.payload_builder_handle
124    }
125}
126
127impl<Node, N, Pool, EVM, Cons> Clone for Components<Node, N, Pool, EVM, Cons>
128where
129    N: Clone,
130    Node: FullNodeTypes,
131    Pool: TransactionPool,
132    EVM: ConfigureEvm,
133    Cons: Clone,
134{
135    fn clone(&self) -> Self {
136        Self {
137            transaction_pool: self.transaction_pool.clone(),
138            evm_config: self.evm_config.clone(),
139            consensus: self.consensus.clone(),
140            network: self.network.clone(),
141            payload_builder_handle: self.payload_builder_handle.clone(),
142        }
143    }
144}