Skip to content

Commit

Permalink
feat: Add required trait impls for OpEthApi (#9341)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiowp authored Jul 8, 2024
1 parent 5b85567 commit 9e45c82
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 8 deletions.
8 changes: 6 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions crates/optimism/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ workspace = true

[dependencies]
# reth
reth-rpc.workspace = true
reth-errors.workspace = true
reth-evm.workspace = true
reth-rpc-eth-api.workspace = true
reth-rpc-eth-types.workspace = true
reth-rpc-server-types.workspace = true
reth-rpc-types.workspace = true
reth-errors.workspace = true
reth-chainspec.workspace = true
reth-provider.workspace = true
reth-tasks = { workspace = true, features = ["rayon"] }
reth-transaction-pool.workspace = true

# ethereum
alloy-primitives.workspace = true
alloy-primitives.workspace = true

# async
parking_lot.workspace = true
tokio.workspace = true
157 changes: 156 additions & 1 deletion crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@
use alloy_primitives::{Address, U64};
use reth_chainspec::ChainInfo;
use reth_errors::RethResult;
use reth_rpc_eth_api::helpers::EthApiSpec;
use reth_evm::ConfigureEvm;
use reth_provider::{
BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, HeaderProvider, StateProviderFactory,
};
use reth_rpc_eth_api::{
helpers::{
Call, EthApiSpec, EthBlocks, EthCall, EthFees, EthSigner, EthState, EthTransactions,
LoadBlock, LoadFee, LoadPendingBlock, LoadReceipt, LoadState, LoadTransaction,
SpawnBlocking, Trace,
},
RawTransactionForwarder,
};
use reth_rpc_eth_types::{EthStateCache, PendingBlock};
use reth_rpc_types::SyncStatus;
use reth_tasks::{pool::BlockingTaskPool, TaskSpawner};
use reth_transaction_pool::TransactionPool;
use std::future::Future;
use tokio::sync::Mutex;

/// OP-Reth `Eth` API implementation.
///
Expand Down Expand Up @@ -54,3 +69,143 @@ impl<Eth: EthApiSpec> EthApiSpec for OpEthApi<Eth> {
self.inner.sync_status()
}
}

impl<Eth: LoadBlock> LoadBlock for OpEthApi<Eth> {
fn provider(&self) -> impl BlockReaderIdExt {
LoadBlock::provider(&self.inner)
}

fn cache(&self) -> &reth_rpc_eth_types::EthStateCache {
self.inner.cache()
}
}

impl<Eth: LoadPendingBlock> LoadPendingBlock for OpEthApi<Eth> {
fn provider(
&self,
) -> impl BlockReaderIdExt + EvmEnvProvider + ChainSpecProvider + StateProviderFactory {
self.inner.provider()
}

fn pool(&self) -> impl TransactionPool {
self.inner.pool()
}

fn pending_block(&self) -> &Mutex<Option<PendingBlock>> {
self.inner.pending_block()
}

fn evm_config(&self) -> &impl ConfigureEvm {
self.inner.evm_config()
}
}

impl<Eth: SpawnBlocking> SpawnBlocking for OpEthApi<Eth> {
fn io_task_spawner(&self) -> impl TaskSpawner {
self.inner.io_task_spawner()
}

fn tracing_task_pool(&self) -> &BlockingTaskPool {
self.inner.tracing_task_pool()
}
}

impl<Eth: LoadReceipt> LoadReceipt for OpEthApi<Eth> {
fn cache(&self) -> &EthStateCache {
self.inner.cache()
}
}

impl<Eth: LoadFee> LoadFee for OpEthApi<Eth> {
fn provider(&self) -> impl reth_provider::BlockIdReader + HeaderProvider + ChainSpecProvider {
LoadFee::provider(&self.inner)
}

fn cache(&self) -> &EthStateCache {
LoadFee::cache(&self.inner)
}

fn gas_oracle(&self) -> &reth_rpc_eth_types::GasPriceOracle<impl BlockReaderIdExt> {
self.inner.gas_oracle()
}

fn fee_history_cache(&self) -> &reth_rpc_eth_types::FeeHistoryCache {
self.inner.fee_history_cache()
}
}

impl<Eth: Call> Call for OpEthApi<Eth> {
fn call_gas_limit(&self) -> u64 {
self.inner.call_gas_limit()
}

fn evm_config(&self) -> &impl ConfigureEvm {
self.inner.evm_config()
}
}

impl<Eth: LoadState> LoadState for OpEthApi<Eth> {
fn provider(&self) -> impl StateProviderFactory {
LoadState::provider(&self.inner)
}

fn cache(&self) -> &EthStateCache {
LoadState::cache(&self.inner)
}

fn pool(&self) -> impl TransactionPool {
LoadState::pool(&self.inner)
}
}

impl<Eth: LoadTransaction> LoadTransaction for OpEthApi<Eth> {
type Pool = Eth::Pool;

fn provider(&self) -> impl reth_provider::TransactionsProvider {
LoadTransaction::provider(&self.inner)
}

fn cache(&self) -> &EthStateCache {
LoadTransaction::cache(&self.inner)
}

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

impl<Eth: EthTransactions> EthTransactions for OpEthApi<Eth> {
fn provider(&self) -> impl BlockReaderIdExt {
EthTransactions::provider(&self.inner)
}

fn raw_tx_forwarder(&self) -> Option<std::sync::Arc<dyn RawTransactionForwarder>> {
self.inner.raw_tx_forwarder()
}

fn signers(&self) -> &parking_lot::RwLock<Vec<Box<dyn EthSigner>>> {
self.inner.signers()
}
}

impl<Eth: EthBlocks> EthBlocks for OpEthApi<Eth> {
fn provider(&self) -> impl HeaderProvider {
EthBlocks::provider(&self.inner)
}
}

impl<Eth: EthState> EthState for OpEthApi<Eth> {
fn max_proof_window(&self) -> u64 {
self.inner.max_proof_window()
}
}

impl<Eth: EthCall> EthCall for OpEthApi<Eth> {}

impl<Eth: EthFees> EthFees for OpEthApi<Eth> {}

impl<Eth: Trace> Trace for OpEthApi<Eth> {
fn evm_config(&self) -> &impl ConfigureEvm {
self.inner.evm_config()
}
}
2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
// #![cfg_attr(not(test), warn(unused_crate_dependencies))] TODO: enable
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

pub mod eth;

0 comments on commit 9e45c82

Please sign in to comment.