Skip to content

Commit

Permalink
refactor: remove Events generic from RPC types (#14033)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Jan 28, 2025
1 parent 42dc1ed commit 0f2e2fa
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 306 deletions.
1 change: 0 additions & 1 deletion crates/node/builder/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub type EthApiBuilderCtx<N> = reth_rpc_eth_types::EthApiBuilderCtx<
<N as RpcNodeCore>::Evm,
<N as RpcNodeCore>::Network,
TaskExecutor,
<N as RpcNodeCore>::Provider,
>;

/// A general purpose trait that launches a new node of any kind.
Expand Down
3 changes: 0 additions & 3 deletions crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ pub struct RpcRegistry<Node: FullNodeComponents, EthApi: EthApiTypes> {
Node::Pool,
Node::Network,
TaskExecutor,
Node::Provider,
EthApi,
Node::Executor,
Node::Consensus,
Expand All @@ -214,7 +213,6 @@ where
Node::Pool,
Node::Network,
TaskExecutor,
Node::Provider,
EthApi,
Node::Executor,
Node::Consensus,
Expand Down Expand Up @@ -453,7 +451,6 @@ where
.with_provider(node.provider().clone())
.with_pool(node.pool().clone())
.with_network(node.network().clone())
.with_events(node.provider().clone())
.with_executor(node.task_executor().clone())
.with_evm_config(node.evm_config().clone())
.with_block_executor(node.block_executor().clone())
Expand Down
49 changes: 13 additions & 36 deletions crates/rpc/rpc-builder/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,31 @@ use reth_rpc_eth_types::{
use reth_tasks::TaskSpawner;

/// Alias for `eth` namespace API builder.
pub type DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, Events, EthApi> =
Box<dyn FnOnce(&EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events>) -> EthApi>;
pub type DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, EthApi> =
Box<dyn FnOnce(&EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks>) -> EthApi>;

/// Handlers for core, filter and pubsub `eth` namespace APIs.
#[derive(Debug, Clone)]
pub struct EthHandlers<Provider: BlockReader, Events, EthApi: EthApiTypes> {
pub struct EthHandlers<Provider: BlockReader, 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<EthApi>,
/// Handler for subscriptions only available for transports that support it (ws, ipc)
pub pubsub: EthPubSub<EthApi, Events>,
pub pubsub: EthPubSub<EthApi>,
}

impl<Provider, Events, EthApi> EthHandlers<Provider, Events, EthApi>
impl<N, Provider, EthApi> EthHandlers<Provider, EthApi>
where
N: NodePrimitives,
Provider: StateProviderFactory
+ BlockReader<
Block = <Events::Primitives as NodePrimitives>::Block,
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
> + Clone
+ BlockReader<Block = N::Block, Receipt = N::Receipt>
+ Clone
+ CanonStateSubscriptions<Primitives = N>
+ Unpin
+ 'static,
Events: CanonStateSubscriptions + Clone + 'static,
EthApi: EthApiTypes + 'static,
{
/// Returns a new instance with handlers for `eth` namespace.
Expand All @@ -48,24 +47,15 @@ where
evm_config: EvmConfig,
config: EthConfig,
executor: Tasks,
events: Events,
eth_api_builder: DynEthApiBuilder<
Provider,
Pool,
EvmConfig,
Network,
Tasks,
Events,
EthApi,
>,
eth_api_builder: DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, EthApi>,
) -> Self
where
EvmConfig: ConfigureEvm<Header = Provider::Header>,
Tasks: TaskSpawner + Clone + 'static,
{
let cache = EthStateCache::spawn_with(provider.clone(), config.cache, executor.clone());

let new_canonical_blocks = events.canonical_state_stream();
let new_canonical_blocks = provider.canonical_state_stream();
let c = cache.clone();
executor.spawn_critical(
"cache canonical blocks task",
Expand All @@ -74,27 +64,14 @@ where
}),
);

let ctx = EthApiBuilderCtx {
provider,
pool,
network,
evm_config,
config,
executor,
events,
cache,
};
let ctx = EthApiBuilderCtx { provider, pool, network, evm_config, config, executor, cache };

let api = eth_api_builder(&ctx);

let filter =
EthFilter::new(api.clone(), ctx.config.filter_config(), Box::new(ctx.executor.clone()));

let pubsub = EthPubSub::with_spawner(
api.clone(),
ctx.events.clone(),
Box::new(ctx.executor.clone()),
);
let pubsub = EthPubSub::with_spawner(api.clone(), Box::new(ctx.executor.clone()));

Self { api, cache: ctx.cache, filter, pubsub }
}
Expand Down
Loading

0 comments on commit 0f2e2fa

Please sign in to comment.