reth_rpc_eth_api/
node.rs

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