From f81c7d075c5d6347bedbec7fcd8babc8b3eabdc0 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 23 Sep 2024 17:37:45 +0200 Subject: [PATCH] chore: rm redundant builder types (#11129) --- crates/rpc/rpc-builder/src/eth.rs | 112 ++++++------------------------ crates/rpc/rpc-builder/src/lib.rs | 5 +- 2 files changed, 22 insertions(+), 95 deletions(-) diff --git a/crates/rpc/rpc-builder/src/eth.rs b/crates/rpc/rpc-builder/src/eth.rs index 6cb655d70861..920268a98549 100644 --- a/crates/rpc/rpc-builder/src/eth.rs +++ b/crates/rpc/rpc-builder/src/eth.rs @@ -30,11 +30,17 @@ pub struct EthHandlers { impl EthHandlers where - EthApi: EthApiTypes, + Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static, + Pool: Send + Sync + Clone + 'static, + Network: Clone + 'static, + Events: CanonStateSubscriptions + Clone + 'static, + EthApi: EthApiTypes + 'static, { - /// Returns a new [`EthHandlers`] builder. + /// 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 builder( + pub fn bootstrap( provider: Provider, pool: Pool, network: Network, @@ -51,49 +57,11 @@ where Events, EthApi, >, - ) -> EthHandlersBuilder { - EthHandlersBuilder { - provider, - pool, - network, - evm_config, - config, - executor, - events, - eth_api_builder, - } - } -} - -/// Builds [`EthHandlers`] for core, filter, and pubsub `eth_` apis. -#[allow(missing_debug_implementations)] -pub struct EthHandlersBuilder { - provider: Provider, - pool: Pool, - network: Network, - evm_config: EvmConfig, - config: EthConfig, - executor: Tasks, - events: Events, - eth_api_builder: DynEthApiBuilder, -} - -impl - EthHandlersBuilder -where - Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static, - Pool: Send + Sync + Clone + 'static, - EvmConfig: ConfigureEvm
, - Network: Clone + 'static, - Tasks: TaskSpawner + Clone + 'static, - Events: CanonStateSubscriptions + Clone + 'static, - EthApi: EthApiTypes + 'static, -{ - /// Returns a new instance with handlers for `eth` namespace. - pub fn build(self) -> EthHandlers { - let Self { provider, pool, network, evm_config, config, executor, events, eth_api_builder } = - self; - + ) -> Self + where + EvmConfig: ConfigureEvm
, + Tasks: TaskSpawner + Clone + 'static, + { let cache = EthStateCache::spawn_with( provider.clone(), config.cache, @@ -124,62 +92,22 @@ where let api = eth_api_builder(&ctx); - let filter = EthFilterApiBuilder::build(&ctx); - - let pubsub = EthPubSubApiBuilder::build(&ctx); - - EthHandlers { api, cache: ctx.cache, filter, pubsub } - } -} - -/// Builds the `eth_` namespace API [`EthFilterApiServer`](reth_rpc_eth_api::EthFilterApiServer). -#[derive(Debug)] -pub struct EthFilterApiBuilder; - -impl EthFilterApiBuilder { - /// Builds the [`EthFilterApiServer`](reth_rpc_eth_api::EthFilterApiServer), for given context. - pub fn build( - ctx: &EthApiBuilderCtx, - ) -> EthFilter - where - Provider: Send + Sync + Clone + 'static, - Pool: Send + Sync + Clone + 'static, - Tasks: TaskSpawner + Clone + 'static, - Eth: EthApiTypes + 'static, - { - EthFilter::new( + let filter = EthFilter::new( ctx.provider.clone(), ctx.pool.clone(), ctx.cache.clone(), ctx.config.filter_config(), Box::new(ctx.executor.clone()), - ) - } -} - -/// Builds the `eth_` namespace API [`EthPubSubApiServer`](reth_rpc_eth_api::EthFilterApiServer). -#[derive(Debug)] -pub struct EthPubSubApiBuilder; + ); -impl EthPubSubApiBuilder { - /// Builds the [`EthPubSubApiServer`](reth_rpc_eth_api::EthPubSubApiServer), for given context. - pub fn build( - ctx: &EthApiBuilderCtx, - ) -> EthPubSub - where - Provider: Clone, - Pool: Clone, - Events: Clone, - Network: Clone, - Tasks: TaskSpawner + Clone + 'static, - Eth: EthApiTypes + 'static, - { - EthPubSub::with_spawner( + let pubsub = EthPubSub::with_spawner( ctx.provider.clone(), ctx.pool.clone(), ctx.events.clone(), ctx.network.clone(), Box::new(ctx.executor.clone()), - ) + ); + + Self { api, cache: ctx.cache, filter, pubsub } } } diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index bd1ca447fc81..d7081fff57a5 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -661,7 +661,7 @@ where { let blocking_pool_guard = BlockingTaskGuard::new(config.eth.max_tracing_requests); - let eth = EthHandlers::builder( + let eth = EthHandlers::bootstrap( provider.clone(), pool.clone(), network.clone(), @@ -670,8 +670,7 @@ where executor.clone(), events.clone(), eth_api_builder, - ) - .build(); + ); Self { provider,