mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: simplify and relax some RPC bounds (#13202)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use alloy_consensus::Header;
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_primitives::EthPrimitives;
|
||||
use reth_primitives::NodePrimitives;
|
||||
use reth_provider::{BlockReader, CanonStateSubscriptions, EvmEnvProvider, StateProviderFactory};
|
||||
use reth_rpc::{EthFilter, EthPubSub};
|
||||
use reth_rpc_eth_api::EthApiTypes;
|
||||
@ -15,38 +15,35 @@ pub type DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth
|
||||
|
||||
/// Handlers for core, filter and pubsub `eth` namespace APIs.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EthHandlers<Provider: BlockReader, Pool, Network, Events, EthApi: EthApiTypes> {
|
||||
pub struct EthHandlers<Provider: BlockReader, Events, EthApi: EthApiTypes> {
|
||||
/// Main `eth_` request handler
|
||||
pub api: EthApi,
|
||||
/// The async caching layer used by the eth handlers
|
||||
pub cache: EthStateCache<Provider::Block, Provider::Receipt>,
|
||||
/// Polling based filter handler available on all transports
|
||||
pub filter: EthFilter<Provider, Pool, EthApi>,
|
||||
pub filter: EthFilter<EthApi>,
|
||||
/// Handler for subscriptions only available for transports that support it (ws, ipc)
|
||||
pub pubsub: EthPubSub<Provider, Pool, Events, Network, EthApi::TransactionCompat>,
|
||||
pub pubsub: EthPubSub<EthApi, Events>,
|
||||
}
|
||||
|
||||
impl<Provider, Pool, Network, Events, EthApi> EthHandlers<Provider, Pool, Network, Events, EthApi>
|
||||
impl<Provider, Events, EthApi> EthHandlers<Provider, Events, EthApi>
|
||||
where
|
||||
Provider: StateProviderFactory
|
||||
+ BlockReader<
|
||||
Block = reth_primitives::Block,
|
||||
Receipt = reth_primitives::Receipt,
|
||||
Header = reth_primitives::Header,
|
||||
Block = <Events::Primitives as NodePrimitives>::Block,
|
||||
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
|
||||
> + EvmEnvProvider
|
||||
+ Clone
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
Pool: Send + Sync + Clone + 'static,
|
||||
Network: Clone + 'static,
|
||||
Events: CanonStateSubscriptions<Primitives = EthPrimitives> + Clone + 'static,
|
||||
Events: CanonStateSubscriptions + Clone + 'static,
|
||||
EthApi: EthApiTypes + 'static,
|
||||
{
|
||||
/// Returns a new instance with handlers for `eth` namespace.
|
||||
///
|
||||
/// This will spawn all necessary tasks for the handlers.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn bootstrap<EvmConfig, Tasks>(
|
||||
pub fn bootstrap<EvmConfig, Tasks, Pool, Network>(
|
||||
provider: Provider,
|
||||
pool: Pool,
|
||||
network: Network,
|
||||
@ -92,22 +89,13 @@ where
|
||||
|
||||
let api = eth_api_builder(&ctx);
|
||||
|
||||
let filter = EthFilter::new(
|
||||
ctx.provider.clone(),
|
||||
ctx.pool.clone(),
|
||||
ctx.cache.clone(),
|
||||
ctx.config.filter_config(),
|
||||
Box::new(ctx.executor.clone()),
|
||||
api.tx_resp_builder().clone(),
|
||||
);
|
||||
let filter =
|
||||
EthFilter::new(api.clone(), ctx.config.filter_config(), Box::new(ctx.executor.clone()));
|
||||
|
||||
let pubsub = EthPubSub::with_spawner(
|
||||
ctx.provider.clone(),
|
||||
ctx.pool.clone(),
|
||||
api.clone(),
|
||||
ctx.events.clone(),
|
||||
ctx.network.clone(),
|
||||
Box::new(ctx.executor.clone()),
|
||||
api.tx_resp_builder().clone(),
|
||||
);
|
||||
|
||||
Self { api, cache: ctx.cache, filter, pubsub }
|
||||
|
||||
@ -204,11 +204,11 @@ use reth_consensus::FullConsensus;
|
||||
use reth_engine_primitives::EngineTypes;
|
||||
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
|
||||
use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers};
|
||||
use reth_primitives::{EthPrimitives, NodePrimitives};
|
||||
use reth_primitives::NodePrimitives;
|
||||
use reth_provider::{
|
||||
AccountReader, BlockReader, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
|
||||
EvmEnvProvider, FullRpcProvider, HeaderProvider, ProviderBlock, ProviderHeader,
|
||||
ProviderReceipt, ReceiptProvider, StateProviderFactory,
|
||||
EvmEnvProvider, FullRpcProvider, ProviderBlock, ProviderHeader, ProviderReceipt,
|
||||
ReceiptProvider, StateProviderFactory,
|
||||
};
|
||||
use reth_rpc::{
|
||||
AdminApi, DebugApi, EngineEthApi, EthBundle, MinerApi, NetApi, OtterscanApi, RPCApi, RethApi,
|
||||
@ -273,7 +273,7 @@ pub async fn launch<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi, B
|
||||
evm_config: EvmConfig,
|
||||
eth: DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, Events, EthApi>,
|
||||
block_executor: BlockExecutor,
|
||||
consensus: Arc<dyn FullConsensus>,
|
||||
consensus: Arc<dyn FullConsensus<BlockExecutor::Primitives>>,
|
||||
) -> Result<RpcServerHandle, RpcError>
|
||||
where
|
||||
Provider: FullRpcProvider<
|
||||
@ -285,7 +285,7 @@ where
|
||||
Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction> + 'static,
|
||||
Network: NetworkInfo + Peers + Clone + 'static,
|
||||
Tasks: TaskSpawner + Clone + 'static,
|
||||
Events: CanonStateSubscriptions<Primitives = EthPrimitives> + Clone + 'static,
|
||||
Events: CanonStateSubscriptions<Primitives = BlockExecutor::Primitives> + Clone + 'static,
|
||||
EvmConfig: ConfigureEvm<Header = alloy_consensus::Header>,
|
||||
EthApi: FullEthApiServer<
|
||||
Provider: BlockReader<
|
||||
@ -298,6 +298,8 @@ where
|
||||
Primitives: NodePrimitives<
|
||||
Block = reth_primitives::Block,
|
||||
Receipt = reth_primitives::Receipt,
|
||||
BlockHeader = reth_primitives::Header,
|
||||
BlockBody = reth_primitives::BlockBody,
|
||||
>,
|
||||
>,
|
||||
{
|
||||
@ -649,15 +651,17 @@ where
|
||||
Pool: TransactionPool + 'static,
|
||||
Network: NetworkInfo + Peers + Clone + 'static,
|
||||
Tasks: TaskSpawner + Clone + 'static,
|
||||
Events: CanonStateSubscriptions<Primitives = EthPrimitives> + Clone + 'static,
|
||||
Events: CanonStateSubscriptions<Primitives = BlockExecutor::Primitives> + Clone + 'static,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
BlockExecutor: BlockExecutorProvider<
|
||||
Primitives: NodePrimitives<
|
||||
Block = reth_primitives::Block,
|
||||
Receipt = reth_primitives::Receipt,
|
||||
BlockHeader = reth_primitives::Header,
|
||||
BlockBody = reth_primitives::BlockBody,
|
||||
>,
|
||||
>,
|
||||
Consensus: reth_consensus::FullConsensus + Clone + 'static,
|
||||
Consensus: reth_consensus::FullConsensus<BlockExecutor::Primitives> + Clone + 'static,
|
||||
{
|
||||
/// Configures all [`RpcModule`]s specific to the given [`TransportRpcModuleConfig`] which can
|
||||
/// be used to start the transport server(s).
|
||||
@ -687,11 +691,9 @@ where
|
||||
>,
|
||||
>,
|
||||
Provider: BlockReader<
|
||||
Block = <EthApi::Provider as BlockReader>::Block,
|
||||
Receipt = <EthApi::Provider as ReceiptProvider>::Receipt,
|
||||
Header = <EthApi::Provider as HeaderProvider>::Header,
|
||||
Block = <Events::Primitives as NodePrimitives>::Block,
|
||||
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
|
||||
>,
|
||||
Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction>,
|
||||
{
|
||||
let Self {
|
||||
provider,
|
||||
@ -815,7 +817,6 @@ where
|
||||
Provider: BlockReader<
|
||||
Block = <EthApi::Provider as BlockReader>::Block,
|
||||
Receipt = <EthApi::Provider as ReceiptProvider>::Receipt,
|
||||
Header = <EthApi::Provider as HeaderProvider>::Header,
|
||||
>,
|
||||
Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction>,
|
||||
{
|
||||
@ -963,7 +964,7 @@ pub struct RpcRegistryInner<
|
||||
/// Holds the configuration for the RPC modules
|
||||
config: RpcModuleConfig,
|
||||
/// Holds a all `eth_` namespace handlers
|
||||
eth: EthHandlers<Provider, Pool, Network, Events, EthApi>,
|
||||
eth: EthHandlers<Provider, Events, EthApi>,
|
||||
/// to put trace calls behind semaphore
|
||||
blocking_pool_guard: BlockingTaskGuard,
|
||||
/// Contains the [Methods] of a module
|
||||
@ -977,16 +978,15 @@ impl<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
|
||||
where
|
||||
Provider: StateProviderFactory
|
||||
+ BlockReader<
|
||||
Block = reth_primitives::Block,
|
||||
Receipt = reth_primitives::Receipt,
|
||||
Header = reth_primitives::Header,
|
||||
Block = <Events::Primitives as NodePrimitives>::Block,
|
||||
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
|
||||
> + EvmEnvProvider
|
||||
+ Clone
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
Pool: Send + Sync + Clone + 'static,
|
||||
Network: Clone + 'static,
|
||||
Events: CanonStateSubscriptions<Primitives = EthPrimitives> + Clone + 'static,
|
||||
Events: CanonStateSubscriptions + Clone + 'static,
|
||||
Tasks: TaskSpawner + Clone + 'static,
|
||||
EthApi: EthApiTypes + 'static,
|
||||
BlockExecutor: BlockExecutorProvider,
|
||||
@ -1057,7 +1057,7 @@ where
|
||||
}
|
||||
|
||||
/// Returns a reference to the installed [`EthHandlers`].
|
||||
pub const fn eth_handlers(&self) -> &EthHandlers<Provider, Pool, Network, Events, EthApi> {
|
||||
pub const fn eth_handlers(&self) -> &EthHandlers<Provider, Events, EthApi> {
|
||||
&self.eth
|
||||
}
|
||||
|
||||
@ -1215,7 +1215,6 @@ where
|
||||
pub fn register_trace(&mut self) -> &mut Self
|
||||
where
|
||||
EthApi: TraceExt,
|
||||
Provider: BlockReader<Block = <EthApi::Provider as BlockReader>::Block>,
|
||||
{
|
||||
let trace_api = self.trace_api();
|
||||
self.modules.insert(RethRpcModule::Trace, trace_api.into_rpc().into());
|
||||
@ -1276,15 +1275,11 @@ where
|
||||
/// # Panics
|
||||
///
|
||||
/// If called outside of the tokio runtime. See also [`Self::eth_api`]
|
||||
pub fn trace_api(&self) -> TraceApi<Provider, EthApi>
|
||||
pub fn trace_api(&self) -> TraceApi<EthApi>
|
||||
where
|
||||
EthApi: TraceExt,
|
||||
{
|
||||
TraceApi::new(
|
||||
self.provider.clone(),
|
||||
self.eth_api().clone(),
|
||||
self.blocking_pool_guard.clone(),
|
||||
)
|
||||
TraceApi::new(self.eth_api().clone(), self.blocking_pool_guard.clone())
|
||||
}
|
||||
|
||||
/// Instantiates [`EthBundle`] Api
|
||||
@ -1305,14 +1300,13 @@ where
|
||||
/// # Panics
|
||||
///
|
||||
/// If called outside of the tokio runtime. See also [`Self::eth_api`]
|
||||
pub fn debug_api(&self) -> DebugApi<Provider, EthApi, BlockExecutor>
|
||||
pub fn debug_api(&self) -> DebugApi<EthApi, BlockExecutor>
|
||||
where
|
||||
EthApi: EthApiSpec + EthTransactions + TraceExt,
|
||||
BlockExecutor:
|
||||
BlockExecutorProvider<Primitives: NodePrimitives<Block = reth_primitives::Block>>,
|
||||
{
|
||||
DebugApi::new(
|
||||
self.provider.clone(),
|
||||
self.eth_api().clone(),
|
||||
self.blocking_pool_guard.clone(),
|
||||
self.block_executor.clone(),
|
||||
@ -1340,7 +1334,7 @@ where
|
||||
/// Instantiates `ValidationApi`
|
||||
pub fn validation_api(&self) -> ValidationApi<Provider, BlockExecutor>
|
||||
where
|
||||
Consensus: reth_consensus::FullConsensus + Clone + 'static,
|
||||
Consensus: reth_consensus::FullConsensus<BlockExecutor::Primitives> + Clone + 'static,
|
||||
{
|
||||
ValidationApi::new(
|
||||
self.provider.clone(),
|
||||
@ -1355,30 +1349,27 @@ where
|
||||
impl<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
|
||||
RpcRegistryInner<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor, Consensus>
|
||||
where
|
||||
Provider: FullRpcProvider<
|
||||
Block = <EthApi::Provider as BlockReader>::Block,
|
||||
Receipt = <EthApi::Provider as ReceiptProvider>::Receipt,
|
||||
Header = <EthApi::Provider as HeaderProvider>::Header,
|
||||
> + AccountReader
|
||||
+ ChangeSetReader,
|
||||
Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction> + 'static,
|
||||
Provider: FullRpcProvider + AccountReader + ChangeSetReader,
|
||||
Pool: TransactionPool + 'static,
|
||||
Network: NetworkInfo + Peers + Clone + 'static,
|
||||
Tasks: TaskSpawner + Clone + 'static,
|
||||
Events: CanonStateSubscriptions<Primitives = EthPrimitives> + Clone + 'static,
|
||||
Events: CanonStateSubscriptions<Primitives = BlockExecutor::Primitives> + Clone + 'static,
|
||||
EthApi: FullEthApiServer<
|
||||
Provider: BlockReader<
|
||||
Block = reth_primitives::Block,
|
||||
Receipt = reth_primitives::Receipt,
|
||||
Header = reth_primitives::Header,
|
||||
Block = <BlockExecutor::Primitives as NodePrimitives>::Block,
|
||||
Receipt = <BlockExecutor::Primitives as NodePrimitives>::Receipt,
|
||||
Header = <BlockExecutor::Primitives as NodePrimitives>::BlockHeader,
|
||||
>,
|
||||
>,
|
||||
BlockExecutor: BlockExecutorProvider<
|
||||
Primitives: NodePrimitives<
|
||||
Block = reth_primitives::Block,
|
||||
BlockHeader = reth_primitives::Header,
|
||||
BlockBody = reth_primitives::BlockBody,
|
||||
Receipt = reth_primitives::Receipt,
|
||||
>,
|
||||
>,
|
||||
Consensus: reth_consensus::FullConsensus + Clone + 'static,
|
||||
Consensus: reth_consensus::FullConsensus<BlockExecutor::Primitives> + Clone + 'static,
|
||||
{
|
||||
/// Configures the auth module that includes the
|
||||
/// * `engine_` namespace
|
||||
@ -1468,7 +1459,6 @@ where
|
||||
.into()
|
||||
}
|
||||
RethRpcModule::Debug => DebugApi::new(
|
||||
self.provider.clone(),
|
||||
eth_api.clone(),
|
||||
self.blocking_pool_guard.clone(),
|
||||
self.block_executor.clone(),
|
||||
@ -1495,16 +1485,14 @@ where
|
||||
RethRpcModule::Net => {
|
||||
NetApi::new(self.network.clone(), eth_api.clone()).into_rpc().into()
|
||||
}
|
||||
RethRpcModule::Trace => TraceApi::new(
|
||||
self.provider.clone(),
|
||||
eth_api.clone(),
|
||||
self.blocking_pool_guard.clone(),
|
||||
)
|
||||
.into_rpc()
|
||||
.into(),
|
||||
RethRpcModule::Trace => {
|
||||
TraceApi::new(eth_api.clone(), self.blocking_pool_guard.clone())
|
||||
.into_rpc()
|
||||
.into()
|
||||
}
|
||||
RethRpcModule::Web3 => Web3Api::new(self.network.clone()).into_rpc().into(),
|
||||
RethRpcModule::Txpool => TxPoolApi::new(
|
||||
self.pool.clone(),
|
||||
self.eth.api.pool().clone(),
|
||||
self.eth.api.tx_resp_builder().clone(),
|
||||
)
|
||||
.into_rpc()
|
||||
@ -1524,7 +1512,7 @@ where
|
||||
.into()
|
||||
}
|
||||
RethRpcModule::Flashbots => ValidationApi::new(
|
||||
self.provider.clone(),
|
||||
eth_api.provider().clone(),
|
||||
Arc::new(self.consensus.clone()),
|
||||
self.block_executor.clone(),
|
||||
self.config.flashbots.clone(),
|
||||
|
||||
Reference in New Issue
Block a user