Skip to content

Commit

Permalink
chore(rpc): Remove provider and network trait methods from `EthApiSpe…
Browse files Browse the repository at this point in the history
…c` (#12050)
  • Loading branch information
emhane authored Oct 26, 2024
1 parent 44e4c47 commit a06c3af
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 36 deletions.
41 changes: 30 additions & 11 deletions crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,43 @@ where
}
}

impl<N> EthApiSpec for OpEthApi<N>
impl<N> RpcNodeCore for OpEthApi<N>
where
Self: Send + Sync,
N: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
Self: Clone,
N: RpcNodeCore,
{
#[inline]
fn provider(
&self,
) -> impl ChainSpecProvider<ChainSpec: EthereumHardforks> + BlockNumReader + StageCheckpointReader
{
self.inner.provider()
type Provider = N::Provider;
type Pool = N::Pool;
type Network = <N as RpcNodeCore>::Network;
type Evm = <N as RpcNodeCore>::Evm;

fn pool(&self) -> &Self::Pool {
self.inner.pool()
}

#[inline]
fn network(&self) -> impl NetworkInfo {
fn evm_config(&self) -> &Self::Evm {
self.inner.evm_config()
}

fn network(&self) -> &Self::Network {
self.inner.network()
}

fn provider(&self) -> &Self::Provider {
self.inner.provider()
}
}

impl<N> EthApiSpec for OpEthApi<N>
where
Self: Send + Sync,
N: RpcNodeCore<
Provider: ChainSpecProvider<ChainSpec: EthereumHardforks>
+ BlockNumReader
+ StageCheckpointReader,
Network: NetworkInfo,
>,
{
#[inline]
fn starting_block(&self) -> U256 {
self.inner.starting_block()
Expand Down
5 changes: 3 additions & 2 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! block_executor: BlockExecutor,
//! ) where
//! Provider: FullRpcProvider + AccountReader + ChangeSetReader,
//! Pool: TransactionPool + 'static,
//! Pool: TransactionPool + Unpin + 'static,
//! Network: NetworkInfo + Peers + Clone + 'static,
//! Events: CanonStateSubscriptions + Clone + 'static,
//! EvmConfig: ConfigureEvm<Header = Header>,
Expand Down Expand Up @@ -85,6 +85,7 @@
//! use reth_tasks::TokioTaskExecutor;
//! use reth_transaction_pool::TransactionPool;
//! use tokio::try_join;
//!
//! pub async fn launch<
//! Provider,
//! Pool,
Expand All @@ -104,7 +105,7 @@
//! block_executor: BlockExecutor,
//! ) where
//! Provider: FullRpcProvider + AccountReader + ChangeSetReader,
//! Pool: TransactionPool + 'static,
//! Pool: TransactionPool + Unpin + 'static,
//! Network: NetworkInfo + Peers + Clone + 'static,
//! Events: CanonStateSubscriptions + Clone + 'static,
//! EngineApi: EngineApiServer<EngineT>,
Expand Down
20 changes: 10 additions & 10 deletions crates/rpc/rpc-eth-api/src/helpers/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ use reth_errors::{RethError, RethResult};
use reth_network_api::NetworkInfo;
use reth_provider::{BlockNumReader, ChainSpecProvider, StageCheckpointReader};

use super::EthSigner;
use crate::{helpers::EthSigner, RpcNodeCore};

/// `Eth` API trait.
///
/// Defines core functionality of the `eth` API implementation.
#[auto_impl::auto_impl(&, Arc)]
pub trait EthApiSpec: Send + Sync {
/// Returns a handle for reading data from disk.
fn provider(
&self,
) -> impl ChainSpecProvider<ChainSpec: EthereumHardforks> + BlockNumReader + StageCheckpointReader;

/// Returns a handle for reading network data summary.
fn network(&self) -> impl NetworkInfo;

pub trait EthApiSpec:
RpcNodeCore<
Provider: ChainSpecProvider<ChainSpec: EthereumHardforks>
+ BlockNumReader
+ StageCheckpointReader,
Network: NetworkInfo,
> + Send
+ Sync
{
/// Returns the block node is started on.
fn starting_block(&self) -> U256;

Expand Down
31 changes: 30 additions & 1 deletion crates/rpc/rpc/src/eth/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_primitives::BlockNumberOrTag;
use reth_provider::{BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider};
use reth_rpc_eth_api::{
helpers::{EthSigner, SpawnBlocking},
EthApiTypes,
EthApiTypes, RpcNodeCore,
};
use reth_rpc_eth_types::{
EthApiBuilderCtx, EthApiError, EthStateCache, FeeHistoryCache, GasCap, GasPriceOracle,
Expand Down Expand Up @@ -140,6 +140,35 @@ where
}
}

impl<Provider, Pool, Network, EvmConfig> RpcNodeCore for EthApi<Provider, Pool, Network, EvmConfig>
where
Provider: Send + Sync + Clone + Unpin,
Pool: Send + Sync + Clone + Unpin,
Network: Send + Sync + Clone,
EvmConfig: Send + Sync + Clone + Unpin,
{
type Provider = Provider;
type Pool = Pool;
type Network = Network;
type Evm = EvmConfig;

fn pool(&self) -> &Self::Pool {
self.inner.pool()
}

fn evm_config(&self) -> &Self::Evm {
self.inner.evm_config()
}

fn network(&self) -> &Self::Network {
self.inner.network()
}

fn provider(&self) -> &Self::Provider {
self.inner.provider()
}
}

impl<Provider, Pool, Network, EvmConfig> std::fmt::Debug
for EthApi<Provider, Pool, Network, EvmConfig>
{
Expand Down
14 changes: 2 additions & 12 deletions crates/rpc/rpc/src/eth/helpers/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use alloy_primitives::U256;
use reth_chainspec::EthereumHardforks;
use reth_network_api::NetworkInfo;
use reth_provider::{BlockNumReader, ChainSpecProvider, StageCheckpointReader};
use reth_rpc_eth_api::helpers::EthApiSpec;
use reth_rpc_eth_api::{helpers::EthApiSpec, RpcNodeCore};
use reth_transaction_pool::TransactionPool;

use crate::EthApi;

impl<Provider, Pool, Network, EvmConfig> EthApiSpec for EthApi<Provider, Pool, Network, EvmConfig>
where
Self: RpcNodeCore<Provider = Provider, Network = Network>,
Pool: TransactionPool + 'static,
Provider: ChainSpecProvider<ChainSpec: EthereumHardforks>
+ BlockNumReader
Expand All @@ -17,17 +18,6 @@ where
Network: NetworkInfo + 'static,
EvmConfig: Send + Sync,
{
fn provider(
&self,
) -> impl ChainSpecProvider<ChainSpec: EthereumHardforks> + BlockNumReader + StageCheckpointReader
{
self.inner.provider()
}

fn network(&self) -> impl NetworkInfo {
self.inner.network()
}

fn starting_block(&self) -> U256 {
self.inner.starting_block()
}
Expand Down

0 comments on commit a06c3af

Please sign in to comment.