diff --git a/Cargo.lock b/Cargo.lock index 9a98619a4cf8..1782ad8cda48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7959,13 +7959,17 @@ name = "reth-optimism-rpc" version = "1.0.0" dependencies = [ "alloy-primitives", + "parking_lot 0.12.3", "reth-chainspec", "reth-errors", - "reth-rpc", + "reth-evm", + "reth-provider", "reth-rpc-eth-api", "reth-rpc-eth-types", - "reth-rpc-server-types", "reth-rpc-types", + "reth-tasks", + "reth-transaction-pool", + "tokio", ] [[package]] diff --git a/crates/optimism/rpc/Cargo.toml b/crates/optimism/rpc/Cargo.toml index 9853e8f914b5..f7599b4a07a3 100644 --- a/crates/optimism/rpc/Cargo.toml +++ b/crates/optimism/rpc/Cargo.toml @@ -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 \ No newline at end of file +alloy-primitives.workspace = true + +# async +parking_lot.workspace = true +tokio.workspace = true \ No newline at end of file diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index b9836360ad64..b73311cb7768 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -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. /// @@ -54,3 +69,143 @@ impl EthApiSpec for OpEthApi { self.inner.sync_status() } } + +impl LoadBlock for OpEthApi { + fn provider(&self) -> impl BlockReaderIdExt { + LoadBlock::provider(&self.inner) + } + + fn cache(&self) -> &reth_rpc_eth_types::EthStateCache { + self.inner.cache() + } +} + +impl LoadPendingBlock for OpEthApi { + fn provider( + &self, + ) -> impl BlockReaderIdExt + EvmEnvProvider + ChainSpecProvider + StateProviderFactory { + self.inner.provider() + } + + fn pool(&self) -> impl TransactionPool { + self.inner.pool() + } + + fn pending_block(&self) -> &Mutex> { + self.inner.pending_block() + } + + fn evm_config(&self) -> &impl ConfigureEvm { + self.inner.evm_config() + } +} + +impl SpawnBlocking for OpEthApi { + fn io_task_spawner(&self) -> impl TaskSpawner { + self.inner.io_task_spawner() + } + + fn tracing_task_pool(&self) -> &BlockingTaskPool { + self.inner.tracing_task_pool() + } +} + +impl LoadReceipt for OpEthApi { + fn cache(&self) -> &EthStateCache { + self.inner.cache() + } +} + +impl LoadFee for OpEthApi { + 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 { + self.inner.gas_oracle() + } + + fn fee_history_cache(&self) -> &reth_rpc_eth_types::FeeHistoryCache { + self.inner.fee_history_cache() + } +} + +impl Call for OpEthApi { + fn call_gas_limit(&self) -> u64 { + self.inner.call_gas_limit() + } + + fn evm_config(&self) -> &impl ConfigureEvm { + self.inner.evm_config() + } +} + +impl LoadState for OpEthApi { + 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 LoadTransaction for OpEthApi { + 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 EthTransactions for OpEthApi { + fn provider(&self) -> impl BlockReaderIdExt { + EthTransactions::provider(&self.inner) + } + + fn raw_tx_forwarder(&self) -> Option> { + self.inner.raw_tx_forwarder() + } + + fn signers(&self) -> &parking_lot::RwLock>> { + self.inner.signers() + } +} + +impl EthBlocks for OpEthApi { + fn provider(&self) -> impl HeaderProvider { + EthBlocks::provider(&self.inner) + } +} + +impl EthState for OpEthApi { + fn max_proof_window(&self) -> u64 { + self.inner.max_proof_window() + } +} + +impl EthCall for OpEthApi {} + +impl EthFees for OpEthApi {} + +impl Trace for OpEthApi { + fn evm_config(&self) -> &impl ConfigureEvm { + self.inner.evm_config() + } +} diff --git a/crates/optimism/rpc/src/lib.rs b/crates/optimism/rpc/src/lib.rs index f2059fac16bd..cad90bc42bf8 100644 --- a/crates/optimism/rpc/src/lib.rs +++ b/crates/optimism/rpc/src/lib.rs @@ -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;