reth_rpc_eth_api/
node.rs

1//! Helper trait for interfacing with [`FullNodeComponents`].
2
3use reth_node_api::{FullNodeComponents, NodeTypes, PrimitivesTy};
4use reth_payload_builder::PayloadBuilderHandle;
5use reth_provider::{BlockReader, ProviderBlock, ProviderReceipt};
6use reth_rpc_eth_types::EthStateCache;
7
8/// Helper trait to relax trait bounds on [`FullNodeComponents`].
9///
10/// Helpful when defining types that would otherwise have a generic `N: FullNodeComponents`. Using
11/// `N: RpcNodeCore` instead, allows access to all the associated types on [`FullNodeComponents`]
12/// that are used in RPC, but with more flexibility since they have no trait bounds (asides auto
13/// traits).
14pub trait RpcNodeCore: Clone + Send + Sync {
15    /// Blockchain data primitives.
16    type Primitives: Send + Sync + Clone + Unpin;
17    /// The provider type used to interact with the node.
18    type Provider: Send + Sync + Clone + Unpin;
19    /// The transaction pool of the node.
20    type Pool: Send + Sync + Clone + Unpin;
21    /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
22    type Evm: Send + Sync + Clone + Unpin;
23    /// Network API.
24    type Network: Send + Sync + Clone;
25
26    /// Builds new blocks.
27    type PayloadBuilder: Send + Sync + Clone;
28
29    /// Returns the transaction pool of the node.
30    fn pool(&self) -> &Self::Pool;
31
32    /// Returns the node's evm config.
33    fn evm_config(&self) -> &Self::Evm;
34
35    /// Returns the handle to the network
36    fn network(&self) -> &Self::Network;
37
38    /// Returns the handle to the payload builder service.
39    fn payload_builder(&self) -> &Self::PayloadBuilder;
40
41    /// Returns the provider of the node.
42    fn provider(&self) -> &Self::Provider;
43}
44
45impl<T> RpcNodeCore for T
46where
47    T: FullNodeComponents,
48{
49    type Primitives = PrimitivesTy<T::Types>;
50    type Provider = T::Provider;
51    type Pool = T::Pool;
52    type Evm = T::Evm;
53    type Network = T::Network;
54    type PayloadBuilder = PayloadBuilderHandle<<T::Types as NodeTypes>::Payload>;
55
56    #[inline]
57    fn pool(&self) -> &Self::Pool {
58        FullNodeComponents::pool(self)
59    }
60
61    #[inline]
62    fn evm_config(&self) -> &Self::Evm {
63        FullNodeComponents::evm_config(self)
64    }
65
66    #[inline]
67    fn network(&self) -> &Self::Network {
68        FullNodeComponents::network(self)
69    }
70
71    #[inline]
72    fn payload_builder(&self) -> &Self::PayloadBuilder {
73        FullNodeComponents::payload_builder_handle(self)
74    }
75
76    #[inline]
77    fn provider(&self) -> &Self::Provider {
78        FullNodeComponents::provider(self)
79    }
80}
81
82/// Additional components, asides the core node components, needed to run `eth_` namespace API
83/// server.
84pub trait RpcNodeCoreExt: RpcNodeCore<Provider: BlockReader> {
85    /// Returns handle to RPC cache service.
86    fn cache(
87        &self,
88    ) -> &EthStateCache<ProviderBlock<Self::Provider>, ProviderReceipt<Self::Provider>>;
89}