Skip to content

Commit

Permalink
chore: rm redundant builder types (paradigmxyz#11129)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Sep 23, 2024
1 parent cf294ce commit f81c7d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 95 deletions.
112 changes: 20 additions & 92 deletions crates/rpc/rpc-builder/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ pub struct EthHandlers<Provider, Pool, Network, Events, EthApi: EthApiTypes> {

impl<Provider, Pool, Network, Events, EthApi> EthHandlers<Provider, Pool, Network, Events, EthApi>
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<EvmConfig, Tasks>(
pub fn bootstrap<EvmConfig, Tasks>(
provider: Provider,
pool: Pool,
network: Network,
Expand All @@ -51,49 +57,11 @@ where
Events,
EthApi,
>,
) -> EthHandlersBuilder<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi> {
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, Pool, Network, Tasks, Events, EvmConfig, EthApi> {
provider: Provider,
pool: Pool,
network: Network,
evm_config: EvmConfig,
config: EthConfig,
executor: Tasks,
events: Events,
eth_api_builder: DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, Events, EthApi>,
}

impl<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi>
EthHandlersBuilder<Provider, Pool, Network, Tasks, Events, EvmConfig, EthApi>
where
Provider: StateProviderFactory + BlockReader + EvmEnvProvider + Clone + Unpin + 'static,
Pool: Send + Sync + Clone + 'static,
EvmConfig: ConfigureEvm<Header = Header>,
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<Provider, Pool, Network, Events, EthApi> {
let Self { provider, pool, network, evm_config, config, executor, events, eth_api_builder } =
self;

) -> Self
where
EvmConfig: ConfigureEvm<Header = Header>,
Tasks: TaskSpawner + Clone + 'static,
{
let cache = EthStateCache::spawn_with(
provider.clone(),
config.cache,
Expand Down Expand Up @@ -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<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>(
ctx: &EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>,
) -> EthFilter<Provider, Pool, Eth>
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<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>(
ctx: &EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>,
) -> EthPubSub<Provider, Pool, Events, Network, Eth>
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 }
}
}
5 changes: 2 additions & 3 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -670,8 +670,7 @@ where
executor.clone(),
events.clone(),
eth_api_builder,
)
.build();
);

Self {
provider,
Expand Down

0 comments on commit f81c7d0

Please sign in to comment.