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

feat: Add required trait impls for OpEthApi #9341

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
14 changes: 14 additions & 0 deletions Cargo.lock

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

20 changes: 18 additions & 2 deletions crates/optimism/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ workspace = true

[dependencies]
# reth
revm.workspace = true
revm-inspectors = { workspace = true, features = ["js-tracer"] }
revm-primitives = { workspace = true, features = ["dev"] }
reth-errors.workspace = true
reth-evm.workspace = true
reth-rpc.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-revm.workspace = true
reth-rpc-types-compat.workspace = true
reth-tasks = { workspace = true, features = ["rayon"] }
reth-transaction-pool.workspace = true
reth-execution-types.workspace = true

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

# async
async-trait.workspace = true
futures.workspace = true
parking_lot.workspace = true
tokio.workspace = true
132 changes: 131 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,15 @@
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, EthSigner, EthTransactions, LoadBlock, LoadFee, LoadPendingBlock, LoadReceipt, LoadState, LoadTransaction, SpawnBlocking}, 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 +60,127 @@ 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)
}
}