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::{ConsensusError, 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, Error = ConsensusError>
47        + Clone
48        + Unpin
49        + 'static;
50
51    /// Network API.
52    type Network: FullNetwork<Primitives: NetPrimitivesFor<<T::Types as NodeTypes>::Primitives>>;
53
54    /// Returns the transaction pool of the node.
55    fn pool(&self) -> &Self::Pool;
56
57    /// Returns the node's evm config.
58    fn evm_config(&self) -> &Self::Evm;
59
60    /// Returns the node's consensus type.
61    fn consensus(&self) -> &Self::Consensus;
62
63    /// Returns the handle to the network
64    fn network(&self) -> &Self::Network;
65
66    /// Returns the handle to the payload builder service handling payload building requests from
67    /// the engine.
68    fn payload_builder_handle(&self) -> &PayloadBuilderHandle<<T::Types as NodeTypes>::Payload>;
69}
70
71/// All the components of the node.
72///
73/// This provides access to all the components of the node.
74#[derive(Debug)]
75pub struct Components<Node: FullNodeTypes, Network, Pool, EVM, Consensus> {
76    /// The transaction pool of the node.
77    pub transaction_pool: Pool,
78    /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
79    pub evm_config: EVM,
80    /// The consensus implementation of the node.
81    pub consensus: Consensus,
82    /// The network implementation of the node.
83    pub network: Network,
84    /// The handle to the payload builder service.
85    pub payload_builder_handle: PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload>,
86}
87
88impl<Node, Pool, EVM, Cons, Network> NodeComponents<Node>
89    for Components<Node, Network, Pool, EVM, Cons>
90where
91    Node: FullNodeTypes,
92    Network: FullNetwork<
93        Primitives: NetPrimitivesFor<
94            PrimitivesTy<Node::Types>,
95            PooledTransaction = PoolPooledTx<Pool>,
96        >,
97    >,
98    Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
99        + Unpin
100        + 'static,
101    EVM: ConfigureEvm<Primitives = PrimitivesTy<Node::Types>> + 'static,
102    Cons:
103        FullConsensus<PrimitivesTy<Node::Types>, Error = ConsensusError> + Clone + Unpin + 'static,
104{
105    type Pool = Pool;
106    type Evm = EVM;
107    type Consensus = Cons;
108    type Network = Network;
109
110    fn pool(&self) -> &Self::Pool {
111        &self.transaction_pool
112    }
113
114    fn evm_config(&self) -> &Self::Evm {
115        &self.evm_config
116    }
117
118    fn consensus(&self) -> &Self::Consensus {
119        &self.consensus
120    }
121
122    fn network(&self) -> &Self::Network {
123        &self.network
124    }
125
126    fn payload_builder_handle(&self) -> &PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload> {
127        &self.payload_builder_handle
128    }
129}
130
131impl<Node, N, Pool, EVM, Cons> Clone for Components<Node, N, Pool, EVM, Cons>
132where
133    N: Clone,
134    Node: FullNodeTypes,
135    Pool: TransactionPool,
136    EVM: ConfigureEvm,
137    Cons: Clone,
138{
139    fn clone(&self) -> Self {
140        Self {
141            transaction_pool: self.transaction_pool.clone(),
142            evm_config: self.evm_config.clone(),
143            consensus: self.consensus.clone(),
144            network: self.network.clone(),
145            payload_builder_handle: self.payload_builder_handle.clone(),
146        }
147    }
148}