From 885e0322d4868b6c8079dd9fa4a7fd38ce42aa60 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 5 Jul 2024 09:19:57 +0200 Subject: [PATCH 1/2] feat: op eth api impl --- Cargo.lock | 6 ++++++ crates/optimism/rpc/Cargo.toml | 9 +++++++++ crates/optimism/rpc/src/eth/mod.rs | 6 ++++++ crates/optimism/rpc/src/lib.rs | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 crates/optimism/rpc/src/eth/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 76b82e90f821..c4191f127361 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7962,6 +7962,12 @@ version = "1.0.0" [[package]] name = "reth-optimism-rpc" version = "1.0.0" +dependencies = [ + "reth-rpc-eth-api", + "reth-rpc-eth-types", + "reth-rpc-server-types", + "reth-rpc-types", +] [[package]] name = "reth-payload-builder" diff --git a/crates/optimism/rpc/Cargo.toml b/crates/optimism/rpc/Cargo.toml index f6645519e65a..77528fa0558d 100644 --- a/crates/optimism/rpc/Cargo.toml +++ b/crates/optimism/rpc/Cargo.toml @@ -8,3 +8,12 @@ homepage.workspace = true repository.workspace = true [lints] +workspace = true + +[dependencies] +# reth +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 diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs new file mode 100644 index 000000000000..18645f6ece5f --- /dev/null +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -0,0 +1,6 @@ +//! OP-Reth `eth_` endpoint implementation. + +pub struct OpEthApi { + + +} \ No newline at end of file diff --git a/crates/optimism/rpc/src/lib.rs b/crates/optimism/rpc/src/lib.rs index f263793af102..d7b6c53d8256 100644 --- a/crates/optimism/rpc/src/lib.rs +++ b/crates/optimism/rpc/src/lib.rs @@ -7,3 +7,5 @@ )] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + +pub mod eth; \ No newline at end of file From 5b80f668d4c2236ea37537d86bab121035efde65 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 5 Jul 2024 11:40:59 +0200 Subject: [PATCH 2/2] feat: op rpc scaffolding --- Cargo.lock | 4 ++ crates/optimism/rpc/Cargo.toml | 5 +++ crates/optimism/rpc/src/eth/mod.rs | 54 ++++++++++++++++++++++- crates/optimism/rpc/src/lib.rs | 4 +- crates/rpc/rpc-eth-api/src/helpers/mod.rs | 2 + 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c4191f127361..e17cbbe1062d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7963,6 +7963,10 @@ version = "1.0.0" name = "reth-optimism-rpc" version = "1.0.0" dependencies = [ + "alloy-primitives", + "reth-chainspec", + "reth-errors", + "reth-rpc", "reth-rpc-eth-api", "reth-rpc-eth-types", "reth-rpc-server-types", diff --git a/crates/optimism/rpc/Cargo.toml b/crates/optimism/rpc/Cargo.toml index 77528fa0558d..9853e8f914b5 100644 --- a/crates/optimism/rpc/Cargo.toml +++ b/crates/optimism/rpc/Cargo.toml @@ -17,3 +17,8 @@ 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 + +# ethereum +alloy-primitives.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 18645f6ece5f..b9836360ad64 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -1,6 +1,56 @@ //! OP-Reth `eth_` endpoint implementation. -pub struct OpEthApi { +use alloy_primitives::{Address, U64}; +use reth_chainspec::ChainInfo; +use reth_errors::RethResult; +use reth_rpc_eth_api::helpers::EthApiSpec; +use reth_rpc_types::SyncStatus; +use std::future::Future; +/// OP-Reth `Eth` API implementation. +/// +/// This type provides the functionality for handling `eth_` related requests. +/// +/// This wraps a default `Eth` implementation, and provides additional functionality where the +/// optimism spec deviates from the default (ethereum) spec, e.g. transaction forwarding to the +/// sequencer, receipts, additional RPC fields for transaction receipts. +/// +/// This type implements the [`FullEthApi`](reth_rpc_eth_api::helpers::FullEthApi) by implemented +/// all the `Eth` helper traits and prerequisite traits. +#[derive(Debug, Clone)] +pub struct OpEthApi { + inner: Eth, +} -} \ No newline at end of file +impl OpEthApi { + /// Creates a new `OpEthApi` from the provided `Eth` implementation. + pub const fn new(inner: Eth) -> Self { + Self { inner } + } +} + +impl EthApiSpec for OpEthApi { + fn protocol_version(&self) -> impl Future> + Send { + self.inner.protocol_version() + } + + fn chain_id(&self) -> U64 { + self.inner.chain_id() + } + + fn chain_info(&self) -> RethResult { + self.inner.chain_info() + } + + fn accounts(&self) -> Vec
{ + self.inner.accounts() + } + + fn is_syncing(&self) -> bool { + self.inner.is_syncing() + } + + fn sync_status(&self) -> RethResult { + self.inner.sync_status() + } +} diff --git a/crates/optimism/rpc/src/lib.rs b/crates/optimism/rpc/src/lib.rs index d7b6c53d8256..f2059fac16bd 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))] +// #![cfg_attr(not(test), warn(unused_crate_dependencies))] TODO: enable #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -pub mod eth; \ No newline at end of file +pub mod eth; diff --git a/crates/rpc/rpc-eth-api/src/helpers/mod.rs b/crates/rpc/rpc-eth-api/src/helpers/mod.rs index d7d31320ce0b..72e49077efb8 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/mod.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/mod.rs @@ -47,6 +47,8 @@ pub trait TraceExt: impl TraceExt for T where T: LoadTransaction + LoadBlock + LoadPendingBlock + Trace + Call {} /// Helper trait to unify all `eth` rpc server building block traits, for simplicity. +/// +/// This trait is automatically implemented for any type that implements all the `Eth` traits. pub trait FullEthApi: EthApiSpec + EthTransactions + EthBlocks + EthState + EthCall + EthFees + Trace + LoadReceipt {