Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rpc): Remove provider and network trait methods from EthApiSpec #12050

Merged
merged 34 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
233d99b
Fix clone impl for OpEthApi
emhane Aug 29, 2024
f0c4120
Add helper trait reth_node_api::NodeCore for simplified type def
emhane Aug 29, 2024
a64bfa7
Add auto trait bounds to reth_node_api::NodeCore
emhane Aug 29, 2024
5c3f060
Relax trait bounds for reth_node_api::BuilderProvider
emhane Aug 29, 2024
0d228c9
Relax trait bounds for OpEthApi
emhane Aug 29, 2024
f40fc8d
Merge branch 'emhane/fix-clone-op-ethapi' into emhane/test-op-eth-api
emhane Aug 29, 2024
8a97ca6
Fix docs
emhane Aug 29, 2024
91079a4
Merge branch 'main' into emhane/def-op-ethapi
emhane Aug 29, 2024
9593550
Cargo update
emhane Sep 4, 2024
65f40ef
Merge branch 'main' into emhane/def-op-ethapi
emhane Sep 4, 2024
d1df7f9
Merge branch 'main' into emhane/def-op-ethapi
emhane Sep 4, 2024
ec16b13
Merge branch 'main' into emhane/def-op-ethapi
emhane Oct 4, 2024
cf1ef10
Fix merge conflicts
emhane Oct 4, 2024
17a4209
Merge branch 'main' into emhane/def-op-ethapi
emhane Oct 18, 2024
c28cce2
Merge branch 'main' into emhane/def-op-ethapi
emhane Oct 24, 2024
362f409
Fix merge conflicts
emhane Oct 24, 2024
45760ba
Add FullNodeComponents getters to NodeCore
emhane Oct 24, 2024
421b261
Rescope NodeCore and NodeTy to RpcNodeCore and RpcNodeTy
emhane Oct 24, 2024
1ff6f2d
Remove RpcNodeTy to remove unambiguous AT for provider
emhane Oct 24, 2024
888c7b0
Merge branch 'main' into emhane/def-op-ethapi
emhane Oct 24, 2024
209fd9a
Move reth_node_api::RpcNodeCore into reth-rpc-eth-api by removing cyc…
emhane Oct 24, 2024
2c2eb4d
Add RpcNodeCore as super trait of EthApiSpec
emhane Oct 24, 2024
aac5aee
Fix docs
emhane Oct 24, 2024
8cdc833
Fix docs
emhane Oct 24, 2024
aeb5f67
Merge branch 'emhane/def-op-ethapi' into emhane/rpc-node-core-eth-api…
emhane Oct 24, 2024
475d676
Merge branch 'main' into emhane/def-op-ethapi
emhane Oct 25, 2024
a79c495
Fix merge conflicts
emhane Oct 25, 2024
02309c2
Merge branch 'emhane/def-op-ethapi' into emhane/rpc-node-core-eth-api…
emhane Oct 25, 2024
11bb733
Fix deps
emhane Oct 26, 2024
d550a27
Fix deps
emhane Oct 26, 2024
4a76db2
Update docs
emhane Oct 26, 2024
9d6b247
Merge branch 'emhane/def-op-ethapi' into emhane/rpc-node-core-eth-api…
emhane Oct 26, 2024
cefe852
Merge branch 'main' into emhane/rpc-node-core-eth-api-spec
emhane Oct 26, 2024
897f293
Fix broken doc tests
emhane Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{
Comment on lines +17 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, I like this a lot, this allows us to extend the RpcNodeCore internals as we see fit, which will be important to tackle #12023

/// 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
Loading