From 45e21194e84d781aaee9a2f395efd845d4f50a53 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:44:49 +0000 Subject: [PATCH 01/15] add storage_proofs_only arg --- Cargo.lock | 4 + crates/optimism/bin/src/main.rs | 3 +- crates/optimism/node/src/args.rs | 7 ++ crates/optimism/node/src/node.rs | 11 +-- crates/optimism/node/tests/it/builder.rs | 2 +- crates/optimism/rpc/Cargo.toml | 4 + crates/optimism/rpc/src/eth/mod.rs | 99 ++++++++++++++++++++++-- 7 files changed, 116 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0ad6f5b230b..50970a94f4b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8446,6 +8446,7 @@ dependencies = [ "alloy-primitives", "alloy-rpc-types-debug", "alloy-rpc-types-eth", + "alloy-serde", "derive_more 1.0.0", "jsonrpsee-core", "jsonrpsee-types", @@ -8456,6 +8457,7 @@ dependencies = [ "parking_lot", "reqwest", "reth-chainspec", + "reth-errors", "reth-evm", "reth-network-api", "reth-node-api", @@ -8473,8 +8475,10 @@ dependencies = [ "reth-rpc-eth-api", "reth-rpc-eth-types", "reth-rpc-server-types", + "reth-rpc-types-compat", "reth-tasks", "reth-transaction-pool", + "reth-trie-common", "revm", "serde_json", "thiserror 2.0.3", diff --git a/crates/optimism/bin/src/main.rs b/crates/optimism/bin/src/main.rs index 6494298ba393..f12ca2872600 100644 --- a/crates/optimism/bin/src/main.rs +++ b/crates/optimism/bin/src/main.rs @@ -28,6 +28,7 @@ fn main() { } let use_legacy_engine = rollup_args.legacy; let sequencer_http_arg = rollup_args.sequencer_http.clone(); + let storage_proof_only = rollup_args.storage_proof_only.clone(); match use_legacy_engine { false => { let engine_tree_config = TreeConfig::default() @@ -36,7 +37,7 @@ fn main() { let handle = builder .with_types_and_provider::>() .with_components(OpNode::components(rollup_args)) - .with_add_ons(OpAddOns::new(sequencer_http_arg)) + .with_add_ons(OpAddOns::new(sequencer_http_arg, storage_proof_only)) .launch_with_fn(|builder| { let launcher = EngineNodeLauncher::new( builder.task_executor().clone(), diff --git a/crates/optimism/node/src/args.rs b/crates/optimism/node/src/args.rs index b84e98d28b19..7935ea1f7d28 100644 --- a/crates/optimism/node/src/args.rs +++ b/crates/optimism/node/src/args.rs @@ -2,6 +2,7 @@ //! clap [Args](clap::Args) for optimism rollup configuration +use alloy_primitives::Address; use reth_node_builder::engine_tree_config::{ DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD, }; @@ -56,6 +57,11 @@ pub struct RollupArgs { /// Configure the target number of blocks to keep in memory. #[arg(long = "engine.memory-block-buffer-target", conflicts_with = "legacy", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)] pub memory_block_buffer_target: u64, + + /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called + /// with `eth_getProof`. + #[arg(long = "rpc.storage_proof_addresses", value_delimiter = ',', num_args(1..))] + pub storage_proof_only: Vec
, } impl Default for RollupArgs { @@ -70,6 +76,7 @@ impl Default for RollupArgs { legacy: false, persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD, memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, + storage_proof_only: vec![] } } } diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index d6cd47cf2af1..0b6d96cf8d28 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -7,6 +7,7 @@ use crate::{ OpEngineTypes, }; use alloy_consensus::Header; +use alloy_primitives::Address; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks}; use reth_db::transaction::{DbTx, DbTxMut}; @@ -183,7 +184,7 @@ where } fn add_ons(&self) -> Self::AddOns { - OpAddOns::new(self.args.sequencer_http.clone()) + OpAddOns::new(self.args.sequencer_http.clone(), self.args.storage_proof_only.clone()) } } @@ -204,14 +205,14 @@ pub struct OpAddOns(pub RpcAddOns, OpEngin impl>> Default for OpAddOns { fn default() -> Self { - Self::new(None) + Self::new(None, vec![]) } } impl>> OpAddOns { - /// Create a new instance with the given `sequencer_http` URL. - pub fn new(sequencer_http: Option) -> Self { - Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http), Default::default())) + /// Create a new instance with the given `sequencer_http` URL and list of storage proof-only addresses. + pub fn new(sequencer_http: Option, storage_proof_addresses: Vec
) -> Self { + Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http, storage_proof_addresses), Default::default())) } } diff --git a/crates/optimism/node/tests/it/builder.rs b/crates/optimism/node/tests/it/builder.rs index 67cac17d3987..f47dc253aaa0 100644 --- a/crates/optimism/node/tests/it/builder.rs +++ b/crates/optimism/node/tests/it/builder.rs @@ -15,7 +15,7 @@ fn test_basic_setup() { .with_database(db) .with_types::() .with_components(OpNode::components(Default::default())) - .with_add_ons(OpAddOns::new(None)) + .with_add_ons(OpAddOns::new(None, vec![])) .on_component_initialized(move |ctx| { let _provider = ctx.provider(); Ok(()) diff --git a/crates/optimism/rpc/Cargo.toml b/crates/optimism/rpc/Cargo.toml index 50194f39aa3c..cc59327ef0ef 100644 --- a/crates/optimism/rpc/Cargo.toml +++ b/crates/optimism/rpc/Cargo.toml @@ -14,6 +14,7 @@ workspace = true [dependencies] # reth reth-evm.workspace = true +reth-errors.workspace = true reth-primitives.workspace = true reth-provider.workspace = true reth-rpc-eth-api.workspace = true @@ -23,10 +24,12 @@ reth-tasks = { workspace = true, features = ["rayon"] } reth-transaction-pool.workspace = true reth-rpc.workspace = true reth-rpc-api.workspace = true +reth-rpc-types-compat.workspace = true reth-node-api.workspace = true reth-network-api.workspace = true reth-node-builder.workspace = true reth-chainspec.workspace = true +reth-trie-common.workspace = true # op-reth reth-optimism-chainspec.workspace = true @@ -41,6 +44,7 @@ alloy-eips.workspace = true alloy-primitives.workspace = true alloy-rpc-types-eth.workspace = true alloy-rpc-types-debug.workspace = true +alloy-serde.workspace = true alloy-consensus.workspace = true op-alloy-network.workspace = true op-alloy-rpc-types.workspace = true diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 6b909f012c55..6111c1c06a8a 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -13,16 +13,20 @@ use reth_optimism_primitives::OpPrimitives; use std::{fmt, sync::Arc}; use alloy_consensus::Header; -use alloy_primitives::U256; +use alloy_eips::BlockId; +use alloy_primitives::{Address, B256, U256}; +use alloy_rpc_types_eth::EIP1186AccountProofResponse; +use alloy_serde::JsonStorageKey; use derive_more::Deref; use op_alloy_network::Optimism; use reth_chainspec::{EthChainSpec, EthereumHardforks}; +use reth_errors::RethError; use reth_evm::ConfigureEvm; use reth_network_api::NetworkInfo; use reth_node_builder::EthApiBuilderCtx; use reth_provider::{ - BlockNumReader, BlockReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, - EvmEnvProvider, StageCheckpointReader, StateProviderFactory, + BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, CanonStateSubscriptions, + ChainSpecProvider, EvmEnvProvider, StageCheckpointReader, StateProviderFactory, }; use reth_rpc::eth::{core::EthApiInner, DevSigner}; use reth_rpc_eth_api::{ @@ -30,14 +34,17 @@ use reth_rpc_eth_api::{ AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState, SpawnBlocking, Trace, }, - EthApiTypes, RpcNodeCore, RpcNodeCoreExt, + EthApiTypes, FromEthApiError, RpcNodeCore, RpcNodeCoreExt, }; -use reth_rpc_eth_types::{EthStateCache, FeeHistoryCache, GasPriceOracle}; +use reth_rpc_eth_types::{EthApiError, EthStateCache, FeeHistoryCache, GasPriceOracle}; +use reth_rpc_types_compat::proof::from_primitive_account_proof; use reth_tasks::{ pool::{BlockingTaskGuard, BlockingTaskPool}, TaskSpawner, }; use reth_transaction_pool::TransactionPool; +use reth_trie_common::AccountProof; +use std::future::Future; use crate::{OpEthApiError, SequencerClient}; @@ -67,6 +74,9 @@ pub struct OpEthApi { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. sequencer_client: Option, + /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called + /// with `eth_getProof`. + storage_proof_only: Vec
, } impl OpEthApi @@ -80,7 +90,7 @@ where >, { /// Creates a new instance for given context. - pub fn new(ctx: &EthApiBuilderCtx, sequencer_http: Option) -> Self { + pub fn new(ctx: &EthApiBuilderCtx, sequencer_http: Option, storage_proof_only: Vec
) -> Self { let blocking_task_pool = BlockingTaskPool::build().expect("failed to build blocking task pool"); @@ -100,7 +110,11 @@ where ctx.config.proof_permits, ); - Self { inner: Arc::new(inner), sequencer_client: sequencer_http.map(SequencerClient::new) } + Self { + inner: Arc::new(inner), + sequencer_client: sequencer_http.map(SequencerClient::new), + storage_proof_only, + } } } @@ -243,6 +257,77 @@ where fn max_proof_window(&self) -> u64 { self.inner.eth_proof_window() } + + fn get_proof( + &self, + address: Address, + keys: Vec, + block_id: Option, + ) -> Result< + impl Future> + Send, + Self::Error, + > + where + Self: EthApiSpec, + { + Ok(async move { + let _permit = self + .acquire_owned() + .await + .map_err(RethError::other) + .map_err(EthApiError::Internal)?; + + let chain_info = self.chain_info().map_err(Self::Error::from_eth_err)?; + let block_id = block_id.unwrap_or_default(); + + // Check whether the distance to the block exceeds the maximum configured window. + let block_number = self + .provider() + .block_number_for_id(block_id) + .map_err(Self::Error::from_eth_err)? + .ok_or(EthApiError::HeaderNotFound(block_id))?; + + if self.storage_proof_only.contains(&address) { + self.spawn_blocking_io(move |this| { + let b256_keys: Vec = keys.iter().map(|k| k.as_b256()).collect(); + let state = this.state_at_block_id(block_number.into())?; + + let proofs = state + .storage_multiproof(address, &b256_keys, Default::default()) + .map_err(EthApiError::from_eth_err)?; + + let account_proof = AccountProof { + address, + storage_root: proofs.root, + storage_proofs: b256_keys + .into_iter() + .map(|k| proofs.storage_proof(k)) + .collect::>() + .map_err(RethError::other) + .map_err(Self::Error::from_eth_err)?, + ..Default::default() + }; + Ok(from_primitive_account_proof(account_proof, keys)) + }) + .await + } else { + let max_window = self.max_proof_window(); + if chain_info.best_number.saturating_sub(block_number) > max_window { + return Err(EthApiError::ExceedsMaxProofWindow.into()) + } + + self.spawn_blocking_io(move |this| { + let state = this.state_at_block_id(block_id)?; + let storage_keys = keys.iter().map(|key| key.as_b256()).collect::>(); + let proof = state + .proof(Default::default(), address, &storage_keys) + .map_err(Self::Error::from_eth_err)?; + Ok(from_primitive_account_proof(proof, keys)) + }) + .await + } + }) + } } impl EthFees for OpEthApi From 4c174a57a441bddfe7330b0ce36b0efb4fb2b0db Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:57:38 +0000 Subject: [PATCH 02/15] fmt --- crates/optimism/node/src/args.rs | 4 ++-- crates/optimism/node/src/node.rs | 10 +++++++--- crates/optimism/rpc/src/eth/mod.rs | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/optimism/node/src/args.rs b/crates/optimism/node/src/args.rs index 7935ea1f7d28..bda6202627ce 100644 --- a/crates/optimism/node/src/args.rs +++ b/crates/optimism/node/src/args.rs @@ -60,7 +60,7 @@ pub struct RollupArgs { /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called /// with `eth_getProof`. - #[arg(long = "rpc.storage_proof_addresses", value_delimiter = ',', num_args(1..))] + #[arg(long = "rpc.storage-proof-addresses", value_delimiter = ',', num_args(1..))] pub storage_proof_only: Vec
, } @@ -76,7 +76,7 @@ impl Default for RollupArgs { legacy: false, persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD, memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, - storage_proof_only: vec![] + storage_proof_only: vec![], } } } diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 0b6d96cf8d28..e547e534b209 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -210,9 +210,13 @@ impl>> Default } impl>> OpAddOns { - /// Create a new instance with the given `sequencer_http` URL and list of storage proof-only addresses. - pub fn new(sequencer_http: Option, storage_proof_addresses: Vec
) -> Self { - Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http, storage_proof_addresses), Default::default())) + /// Create a new instance with the given `sequencer_http` URL and list of storage proof-only + /// addresses. + pub fn new(sequencer_http: Option, storage_proof_addresses: Vec
) -> Self { + Self(RpcAddOns::new( + move |ctx| OpEthApi::new(ctx, sequencer_http, storage_proof_addresses), + Default::default(), + )) } } diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 6111c1c06a8a..2a25960f9782 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -90,7 +90,11 @@ where >, { /// Creates a new instance for given context. - pub fn new(ctx: &EthApiBuilderCtx, sequencer_http: Option, storage_proof_only: Vec
) -> Self { + pub fn new( + ctx: &EthApiBuilderCtx, + sequencer_http: Option, + storage_proof_only: Vec
, + ) -> Self { let blocking_task_pool = BlockingTaskPool::build().expect("failed to build blocking task pool"); From 932e1bc529c2c2fb0df4e1f7dc010546df346ec1 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:23:26 +0000 Subject: [PATCH 03/15] add OpEthApiInner and OpEthApiBuilder --- crates/optimism/node/src/node.rs | 11 ++- crates/optimism/rpc/src/eth/mod.rs | 128 +++++++++++++++++++++-------- 2 files changed, 102 insertions(+), 37 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index e547e534b209..003ad9483061 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -214,7 +214,16 @@ impl>> OpAddOn /// addresses. pub fn new(sequencer_http: Option, storage_proof_addresses: Vec
) -> Self { Self(RpcAddOns::new( - move |ctx| OpEthApi::new(ctx, sequencer_http, storage_proof_addresses), + move |ctx| { + let mut builder = + OpEthApi::builder(ctx).with_storage_proof_only(storage_proof_addresses); + + if let Some(sequencer_http) = sequencer_http { + builder = builder.with_sequencer(sequencer_http) + } + + builder.build() + }, Default::default(), )) } diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 2a25960f9782..6992c687806a 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -70,13 +70,7 @@ pub type EthApiNodeBackend = EthApiInner< pub struct OpEthApi { /// Gateway to node's core components. #[deref] - inner: Arc>, - /// Sequencer client, configured to forward submitted transactions to sequencer of given OP - /// network. - sequencer_client: Option, - /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called - /// with `eth_getProof`. - storage_proof_only: Vec
, + inner: Arc>, } impl OpEthApi @@ -90,35 +84,8 @@ where >, { /// Creates a new instance for given context. - pub fn new( - ctx: &EthApiBuilderCtx, - sequencer_http: Option, - storage_proof_only: Vec
, - ) -> Self { - let blocking_task_pool = - BlockingTaskPool::build().expect("failed to build blocking task pool"); - - let inner = EthApiInner::new( - ctx.provider.clone(), - ctx.pool.clone(), - ctx.network.clone(), - ctx.cache.clone(), - ctx.new_gas_price_oracle(), - ctx.config.rpc_gas_cap, - ctx.config.rpc_max_simulate_blocks, - ctx.config.eth_proof_window, - blocking_task_pool, - ctx.new_fee_history_cache(), - ctx.evm_config.clone(), - ctx.executor.clone(), - ctx.config.proof_permits, - ); - - Self { - inner: Arc::new(inner), - sequencer_client: sequencer_http.map(SequencerClient::new), - storage_proof_only, - } + pub fn builder(ctx: &EthApiBuilderCtx) -> OpEthApiBuilder<'_, N> { + OpEthApiBuilder::new(ctx) } } @@ -362,3 +329,92 @@ impl fmt::Debug for OpEthApi { f.debug_struct("OpEthApi").finish_non_exhaustive() } } + +/// Container type `OpEthApi` +#[derive(Deref)] +#[allow(missing_debug_implementations)] +pub struct OpEthApiInner { + /// Gateway to node's core components. + #[deref] + eth_api: EthApiNodeBackend, + /// Sequencer client, configured to forward submitted transactions to sequencer of given OP + /// network. + sequencer_client: Option, + /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called + /// with `eth_getProof`. + storage_proof_only: Vec
, +} + +/// A type that knows how to build a [`OpEthApi`]. +#[allow(missing_debug_implementations)] +pub struct OpEthApiBuilder<'a, N: RpcNodeCore> { + /// Gateway to node's core components. + ctx: &'a EthApiBuilderCtx, + /// Sequencer client, configured to forward submitted transactions to sequencer of given OP + /// network. + sequencer_client: Option, + /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called + /// with `eth_getProof`. + storage_proof_only: Vec
, +} + +impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { + /// Creates a [`OpEthApiBuilder`] instance from [`EthApiBuilderCtx`]. + pub fn new(ctx: &'a EthApiBuilderCtx) -> Self { + Self { ctx, sequencer_client: None, storage_proof_only: vec![] } + } + + /// With a [SequencerClient]. + pub fn with_sequencer(mut self, sequencer_client: String) -> Self { + self.sequencer_client = Some(SequencerClient::new(sequencer_client)); + self + } + + /// With a list of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when + /// called with `eth_getProof`. + pub fn with_storage_proof_only(mut self, storage_proof_only: Vec
) -> Self { + self.storage_proof_only = storage_proof_only; + self + } +} + +impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> +where + N: RpcNodeCore< + Provider: BlockReaderIdExt + + ChainSpecProvider + + CanonStateSubscriptions + + Clone + + 'static, + >, +{ + /// Builds an instance of [`OpEthApi`] + pub fn build(self) -> OpEthApi { + let blocking_task_pool = + BlockingTaskPool::build().expect("failed to build blocking task pool"); + + let eth_api = EthApiInner::new( + self.ctx.provider.clone(), + self.ctx.pool.clone(), + self.ctx.network.clone(), + self.ctx.cache.clone(), + self.ctx.new_gas_price_oracle(), + self.ctx.config.rpc_gas_cap, + self.ctx.config.rpc_max_simulate_blocks, + self.ctx.config.eth_proof_window, + blocking_task_pool, + self.ctx.new_fee_history_cache(), + self.ctx.evm_config.clone(), + self.ctx.executor.clone(), + self.ctx.config.proof_permits, + ); + + OpEthApi { + inner: Arc::new(OpEthApiInner { + eth_api, + sequencer_client: self.sequencer_client, + storage_proof_only: self.storage_proof_only, + }), + } + } +} From 059334dc87bf84e6faa521369fe4d4546c0aeb54 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:56:20 +0000 Subject: [PATCH 04/15] add OpAddonsBuilder --- crates/optimism/bin/src/main.rs | 10 ++- crates/optimism/node/src/node.rs | 107 ++++++++++++++++++++++------- crates/optimism/rpc/src/eth/mod.rs | 4 +- 3 files changed, 87 insertions(+), 34 deletions(-) diff --git a/crates/optimism/bin/src/main.rs b/crates/optimism/bin/src/main.rs index f12ca2872600..a8ec80ed1671 100644 --- a/crates/optimism/bin/src/main.rs +++ b/crates/optimism/bin/src/main.rs @@ -3,9 +3,9 @@ #![cfg(feature = "optimism")] use clap::Parser; -use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher}; +use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher, Node}; use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli}; -use reth_optimism_node::{args::RollupArgs, node::OpAddOns, OpNode}; +use reth_optimism_node::{args::RollupArgs, OpNode}; use reth_provider::providers::BlockchainProvider2; use tracing as _; @@ -27,8 +27,6 @@ fn main() { tracing::warn!(target: "reth::cli", "Experimental engine is default now, and the --engine.experimental flag is deprecated. To enable the legacy functionality, use --engine.legacy."); } let use_legacy_engine = rollup_args.legacy; - let sequencer_http_arg = rollup_args.sequencer_http.clone(); - let storage_proof_only = rollup_args.storage_proof_only.clone(); match use_legacy_engine { false => { let engine_tree_config = TreeConfig::default() @@ -36,8 +34,8 @@ fn main() { .with_memory_block_buffer_target(rollup_args.memory_block_buffer_target); let handle = builder .with_types_and_provider::>() - .with_components(OpNode::components(rollup_args)) - .with_add_ons(OpAddOns::new(sequencer_http_arg, storage_proof_only)) + .with_components(OpNode::components(&rollup_args)) + .with_add_ons(OpNode::new(rollup_args).add_ons()) .launch_with_fn(|builder| { let launcher = EngineNodeLauncher::new( builder.task_executor().clone(), diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 003ad9483061..26a09d2c18ad 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -32,7 +32,7 @@ use reth_optimism_payload_builder::builder::OpPayloadTransactions; use reth_optimism_primitives::OpPrimitives; use reth_optimism_rpc::{ witness::{DebugExecutionWitnessApiServer, OpDebugWitnessApi}, - OpEthApi, + OpEthApi, SequencerClient, }; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; use reth_primitives::BlockBody; @@ -47,7 +47,7 @@ use reth_transaction_pool::{ TransactionValidationTaskExecutor, }; use reth_trie_db::MerklePatriciaTrie; -use std::sync::Arc; +use std::{marker::PhantomData, sync::Arc}; /// Storage implementation for Optimism. #[derive(Debug, Default, Clone)] @@ -123,7 +123,7 @@ impl OpNode { /// Returns the components for the given [`RollupArgs`]. pub fn components( - args: RollupArgs, + args: &RollupArgs, ) -> ComponentsBuilder< Node, OpPoolBuilder, @@ -145,9 +145,9 @@ impl OpNode { ComponentsBuilder::default() .node_types::() .pool(OpPoolBuilder::default()) - .payload(OpPayloadBuilder::new(compute_pending_block)) + .payload(OpPayloadBuilder::new(*compute_pending_block)) .network(OpNetworkBuilder { - disable_txpool_gossip, + disable_txpool_gossip: *disable_txpool_gossip, disable_discovery_v4: !discovery_v4, }) .executor(OpExecutorBuilder::default()) @@ -179,12 +179,20 @@ where OpAddOns>::Components>>; fn components_builder(&self) -> Self::ComponentsBuilder { - let Self { args } = self; - Self::components(args.clone()) + Self::components(&self.args) } fn add_ons(&self) -> Self::AddOns { - OpAddOns::new(self.args.sequencer_http.clone(), self.args.storage_proof_only.clone()) + let mut builder = OpAddOns::builder(); + if let Some(sequencer) = &self.args.sequencer_http { + builder = builder.with_sequencer(sequencer.clone()); + } + + if !self.args.storage_proof_only.is_empty() { + builder = builder.with_storage_proof_only(self.args.storage_proof_only.clone()); + } + + builder.build() } } @@ -205,27 +213,13 @@ pub struct OpAddOns(pub RpcAddOns, OpEngin impl>> Default for OpAddOns { fn default() -> Self { - Self::new(None, vec![]) + Self::builder().build() } } -impl>> OpAddOns { - /// Create a new instance with the given `sequencer_http` URL and list of storage proof-only - /// addresses. - pub fn new(sequencer_http: Option, storage_proof_addresses: Vec
) -> Self { - Self(RpcAddOns::new( - move |ctx| { - let mut builder = - OpEthApi::builder(ctx).with_storage_proof_only(storage_proof_addresses); - - if let Some(sequencer_http) = sequencer_http { - builder = builder.with_sequencer(sequencer_http) - } - - builder.build() - }, - Default::default(), - )) +impl OpAddOns { + fn builder() -> OpAddOnsBuilder { + OpAddOnsBuilder::default() } } @@ -284,6 +278,67 @@ where } } +/// A regular optimism evm and executor builder. +#[derive(Debug, Clone)] +#[non_exhaustive] +pub struct OpAddOnsBuilder { + /// Sequencer client, configured to forward submitted transactions to sequencer of given OP + /// network. + sequencer_client: Option, + /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called + /// with `eth_getProof`. + storage_proof_only: Vec
, + _marker: PhantomData, +} + +impl Default for OpAddOnsBuilder { + fn default() -> Self { + Self { sequencer_client: None, storage_proof_only: vec![], _marker: PhantomData } + } +} + +impl OpAddOnsBuilder { + /// With a [SequencerClient]. + pub fn with_sequencer(mut self, sequencer_client: String) -> Self { + self.sequencer_client = Some(SequencerClient::new(sequencer_client)); + self + } + + /// With a list of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when + /// called with `eth_getProof`. + pub fn with_storage_proof_only(mut self, storage_proof_only: Vec
) -> Self { + self.storage_proof_only = storage_proof_only; + self + } +} + +impl OpAddOnsBuilder +where + N: FullNodeComponents>, +{ + /// Builds an instance of [`OpAddOns`]. + pub fn build(self) -> OpAddOns { + let Self { sequencer_client, storage_proof_only, .. } = self; + + OpAddOns(RpcAddOns::new( + move |ctx| { + let mut builder = OpEthApi::builder(ctx); + + if let Some(sequencer_client) = sequencer_client { + builder = builder.with_sequencer(sequencer_client) + } + + if !storage_proof_only.is_empty() { + builder = builder.with_storage_proof_only(storage_proof_only); + } + + builder.build() + }, + Default::default(), + )) + } +} + /// A regular optimism evm and executor builder. #[derive(Debug, Default, Clone, Copy)] #[non_exhaustive] diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 6992c687806a..8798ec77b541 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -365,8 +365,8 @@ impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { } /// With a [SequencerClient]. - pub fn with_sequencer(mut self, sequencer_client: String) -> Self { - self.sequencer_client = Some(SequencerClient::new(sequencer_client)); + pub fn with_sequencer(mut self, sequencer_client: SequencerClient) -> Self { + self.sequencer_client = Some(sequencer_client); self } From dabc31da7b509dc4baf0a97beed0a8f08577bb53 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 29 Nov 2024 14:58:46 +0000 Subject: [PATCH 05/15] docs --- crates/optimism/node/src/node.rs | 3 ++- crates/optimism/rpc/src/eth/mod.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 26a09d2c18ad..7750d5dd14d8 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -218,7 +218,8 @@ impl>> Default } impl OpAddOns { - fn builder() -> OpAddOnsBuilder { + /// Build a [`OpAddOns`] using [`OpAddOnsBuilder`]. + pub fn builder() -> OpAddOnsBuilder { OpAddOnsBuilder::default() } } diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 8798ec77b541..c49b53f40b1c 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -83,7 +83,7 @@ where + 'static, >, { - /// Creates a new instance for given context. + /// Build a [`OpEthApi`] using [`OpEthApiBuilder`]. pub fn builder(ctx: &EthApiBuilderCtx) -> OpEthApiBuilder<'_, N> { OpEthApiBuilder::new(ctx) } From 45318e20631ea3b9b8ff6a544a445475f32db316 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:02:28 +0000 Subject: [PATCH 06/15] clippy --- crates/optimism/rpc/src/eth/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index c49b53f40b1c..4acff0271e16 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -378,7 +378,7 @@ impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { } } -impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> +impl OpEthApiBuilder<'_, N> where N: RpcNodeCore< Provider: BlockReaderIdExt From 3f2eb2674fd15aa6f634db3ded53e9979b82c304 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:07:29 +0000 Subject: [PATCH 07/15] clippy --- crates/optimism/node/src/node.rs | 2 +- crates/optimism/rpc/src/eth/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 7750d5dd14d8..85aa9bc757d0 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -299,7 +299,7 @@ impl Default for OpAddOnsBuilder { } impl OpAddOnsBuilder { - /// With a [SequencerClient]. + /// With a [`SequencerClient`]. pub fn with_sequencer(mut self, sequencer_client: String) -> Self { self.sequencer_client = Some(SequencerClient::new(sequencer_client)); self diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 4acff0271e16..f4a97b7e58bc 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -364,7 +364,7 @@ impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { Self { ctx, sequencer_client: None, storage_proof_only: vec![] } } - /// With a [SequencerClient]. + /// With a [`SequencerClient`]. pub fn with_sequencer(mut self, sequencer_client: SequencerClient) -> Self { self.sequencer_client = Some(sequencer_client); self From ccd271b9a4ecbd6046d42e65fd9d3bfd96ac5dcc Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:42:21 +0000 Subject: [PATCH 08/15] clippy --- crates/optimism/node/tests/it/builder.rs | 4 ++-- crates/optimism/rpc/src/eth/mod.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/optimism/node/tests/it/builder.rs b/crates/optimism/node/tests/it/builder.rs index f47dc253aaa0..d43e2b4019e4 100644 --- a/crates/optimism/node/tests/it/builder.rs +++ b/crates/optimism/node/tests/it/builder.rs @@ -14,8 +14,8 @@ fn test_basic_setup() { let _builder = NodeBuilder::new(config) .with_database(db) .with_types::() - .with_components(OpNode::components(Default::default())) - .with_add_ons(OpAddOns::new(None, vec![])) + .with_components(OpNode::components(&Default::default())) + .with_add_ons(OpAddOns::builder().build()) .on_component_initialized(move |ctx| { let _provider = ctx.provider(); Ok(()) diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index f4a97b7e58bc..4e3b019c69ea 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -84,7 +84,7 @@ where >, { /// Build a [`OpEthApi`] using [`OpEthApiBuilder`]. - pub fn builder(ctx: &EthApiBuilderCtx) -> OpEthApiBuilder<'_, N> { + pub const fn builder(ctx: &EthApiBuilderCtx) -> OpEthApiBuilder<'_, N> { OpEthApiBuilder::new(ctx) } } @@ -360,7 +360,7 @@ pub struct OpEthApiBuilder<'a, N: RpcNodeCore> { impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { /// Creates a [`OpEthApiBuilder`] instance from [`EthApiBuilderCtx`]. - pub fn new(ctx: &'a EthApiBuilderCtx) -> Self { + pub const fn new(ctx: &'a EthApiBuilderCtx) -> Self { Self { ctx, sequencer_client: None, storage_proof_only: vec![] } } @@ -378,7 +378,7 @@ impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { } } -impl OpEthApiBuilder<'_, N> +impl OpEthApiBuilder<'_, N> where N: RpcNodeCore< Provider: BlockReaderIdExt From ba6aee05a7556022a89a4f0d60033add4cc56531 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:17:03 +0000 Subject: [PATCH 09/15] make the args on builder optional instead --- crates/optimism/node/src/node.rs | 33 +++++++++--------------------- crates/optimism/rpc/src/eth/mod.rs | 4 ++-- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 85aa9bc757d0..fe36f79dbc05 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -183,16 +183,10 @@ where } fn add_ons(&self) -> Self::AddOns { - let mut builder = OpAddOns::builder(); - if let Some(sequencer) = &self.args.sequencer_http { - builder = builder.with_sequencer(sequencer.clone()); - } - - if !self.args.storage_proof_only.is_empty() { - builder = builder.with_storage_proof_only(self.args.storage_proof_only.clone()); - } - - builder.build() + OpAddOns::builder() + .with_sequencer(self.args.sequencer_http.clone()) + .with_storage_proof_only(self.args.storage_proof_only.clone()) + .build() } } @@ -300,8 +294,8 @@ impl Default for OpAddOnsBuilder { impl OpAddOnsBuilder { /// With a [`SequencerClient`]. - pub fn with_sequencer(mut self, sequencer_client: String) -> Self { - self.sequencer_client = Some(SequencerClient::new(sequencer_client)); + pub fn with_sequencer(mut self, sequencer_client: Option) -> Self { + self.sequencer_client = sequencer_client.map(SequencerClient::new); self } @@ -323,17 +317,10 @@ where OpAddOns(RpcAddOns::new( move |ctx| { - let mut builder = OpEthApi::builder(ctx); - - if let Some(sequencer_client) = sequencer_client { - builder = builder.with_sequencer(sequencer_client) - } - - if !storage_proof_only.is_empty() { - builder = builder.with_storage_proof_only(storage_proof_only); - } - - builder.build() + OpEthApi::builder(ctx) + .with_sequencer(sequencer_client) + .with_storage_proof_only(storage_proof_only) + .build() }, Default::default(), )) diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 4e3b019c69ea..558e40d8070a 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -365,8 +365,8 @@ impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { } /// With a [`SequencerClient`]. - pub fn with_sequencer(mut self, sequencer_client: SequencerClient) -> Self { - self.sequencer_client = Some(sequencer_client); + pub fn with_sequencer(mut self, sequencer_client: Option) -> Self { + self.sequencer_client = sequencer_client; self } From f305d882078e17816c1e1da8dc2a434ae3d94311 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:18:49 +0000 Subject: [PATCH 10/15] noref --- crates/optimism/bin/src/main.rs | 2 +- crates/optimism/node/src/node.rs | 2 +- crates/optimism/node/tests/it/builder.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/optimism/bin/src/main.rs b/crates/optimism/bin/src/main.rs index a8ec80ed1671..82fb3c241954 100644 --- a/crates/optimism/bin/src/main.rs +++ b/crates/optimism/bin/src/main.rs @@ -34,7 +34,7 @@ fn main() { .with_memory_block_buffer_target(rollup_args.memory_block_buffer_target); let handle = builder .with_types_and_provider::>() - .with_components(OpNode::components(&rollup_args)) + .with_components(OpNode::components(rollup_args.clone())) .with_add_ons(OpNode::new(rollup_args).add_ons()) .launch_with_fn(|builder| { let launcher = EngineNodeLauncher::new( diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index fe36f79dbc05..3432a794e604 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -123,7 +123,7 @@ impl OpNode { /// Returns the components for the given [`RollupArgs`]. pub fn components( - args: &RollupArgs, + args: RollupArgs, ) -> ComponentsBuilder< Node, OpPoolBuilder, diff --git a/crates/optimism/node/tests/it/builder.rs b/crates/optimism/node/tests/it/builder.rs index d43e2b4019e4..89f04bef422f 100644 --- a/crates/optimism/node/tests/it/builder.rs +++ b/crates/optimism/node/tests/it/builder.rs @@ -14,7 +14,7 @@ fn test_basic_setup() { let _builder = NodeBuilder::new(config) .with_database(db) .with_types::() - .with_components(OpNode::components(&Default::default())) + .with_components(OpNode::components(Default::default())) .with_add_ons(OpAddOns::builder().build()) .on_component_initialized(move |ctx| { let _provider = ctx.provider(); From c7efd2dcab9b2db5dd5a56bcca985d3df0f0b1e3 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:39:15 +0000 Subject: [PATCH 11/15] make ethopapi private --- Cargo.lock | 1 - crates/optimism/node/src/node.rs | 6 ++-- crates/optimism/rpc/Cargo.toml | 1 - crates/optimism/rpc/src/eth/block.rs | 2 +- crates/optimism/rpc/src/eth/call.rs | 4 +-- crates/optimism/rpc/src/eth/mod.rs | 38 +++++++++----------- crates/optimism/rpc/src/eth/pending_block.rs | 2 +- crates/optimism/rpc/src/eth/receipt.rs | 4 ++- crates/optimism/rpc/src/eth/transaction.rs | 5 +-- 9 files changed, 30 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50970a94f4b7..b43a3858111c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8447,7 +8447,6 @@ dependencies = [ "alloy-rpc-types-debug", "alloy-rpc-types-eth", "alloy-serde", - "derive_more 1.0.0", "jsonrpsee-core", "jsonrpsee-types", "op-alloy-consensus", diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 3432a794e604..c62208cfce7c 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -145,9 +145,9 @@ impl OpNode { ComponentsBuilder::default() .node_types::() .pool(OpPoolBuilder::default()) - .payload(OpPayloadBuilder::new(*compute_pending_block)) + .payload(OpPayloadBuilder::new(compute_pending_block)) .network(OpNetworkBuilder { - disable_txpool_gossip: *disable_txpool_gossip, + disable_txpool_gossip: disable_txpool_gossip, disable_discovery_v4: !discovery_v4, }) .executor(OpExecutorBuilder::default()) @@ -179,7 +179,7 @@ where OpAddOns>::Components>>; fn components_builder(&self) -> Self::ComponentsBuilder { - Self::components(&self.args) + Self::components(self.args.clone()) } fn add_ons(&self) -> Self::AddOns { diff --git a/crates/optimism/rpc/Cargo.toml b/crates/optimism/rpc/Cargo.toml index cc59327ef0ef..911d489c0a78 100644 --- a/crates/optimism/rpc/Cargo.toml +++ b/crates/optimism/rpc/Cargo.toml @@ -65,7 +65,6 @@ serde_json.workspace = true # misc thiserror.workspace = true tracing.workspace = true -derive_more = { workspace = true, features = ["constructor", "deref"] } [dev-dependencies] reth-optimism-chainspec.workspace = true diff --git a/crates/optimism/rpc/src/eth/block.rs b/crates/optimism/rpc/src/eth/block.rs index 64a55496993d..92b4353ec9e4 100644 --- a/crates/optimism/rpc/src/eth/block.rs +++ b/crates/optimism/rpc/src/eth/block.rs @@ -57,7 +57,7 @@ where }; Ok(OpReceiptBuilder::new( - &self.inner.provider().chain_spec(), + &self.inner.eth_api.provider().chain_spec(), tx, meta, receipt, diff --git a/crates/optimism/rpc/src/eth/call.rs b/crates/optimism/rpc/src/eth/call.rs index 9495a359e329..c5e96bb87d17 100644 --- a/crates/optimism/rpc/src/eth/call.rs +++ b/crates/optimism/rpc/src/eth/call.rs @@ -33,12 +33,12 @@ where { #[inline] fn call_gas_limit(&self) -> u64 { - self.inner.gas_cap() + self.inner.eth_api.gas_cap() } #[inline] fn max_simulate_blocks(&self) -> u64 { - self.inner.max_simulate_blocks() + self.inner.eth_api.max_simulate_blocks() } fn create_txn_env( diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 558e40d8070a..1e21f56a7917 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -17,7 +17,6 @@ use alloy_eips::BlockId; use alloy_primitives::{Address, B256, U256}; use alloy_rpc_types_eth::EIP1186AccountProofResponse; use alloy_serde::JsonStorageKey; -use derive_more::Deref; use op_alloy_network::Optimism; use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_errors::RethError; @@ -66,10 +65,9 @@ pub type EthApiNodeBackend = EthApiInner< /// /// This type implements the [`FullEthApi`](reth_rpc_eth_api::helpers::FullEthApi) by implemented /// all the `Eth` helper traits and prerequisite traits. -#[derive(Deref, Clone)] +#[derive(Clone)] pub struct OpEthApi { /// Gateway to node's core components. - #[deref] inner: Arc>, } @@ -115,17 +113,17 @@ where #[inline] fn pool(&self) -> &Self::Pool { - self.inner.pool() + self.inner.eth_api.pool() } #[inline] fn evm_config(&self) -> &Self::Evm { - self.inner.evm_config() + self.inner.eth_api.evm_config() } #[inline] fn network(&self) -> &Self::Network { - self.inner.network() + self.inner.eth_api.network() } #[inline] @@ -135,7 +133,7 @@ where #[inline] fn provider(&self) -> &Self::Provider { - self.inner.provider() + self.inner.eth_api.provider() } } @@ -145,7 +143,7 @@ where { #[inline] fn cache(&self) -> &EthStateCache { - self.inner.cache() + self.inner.eth_api.cache() } } @@ -160,12 +158,12 @@ where { #[inline] fn starting_block(&self) -> U256 { - self.inner.starting_block() + self.inner.eth_api.starting_block() } #[inline] fn signers(&self) -> &parking_lot::RwLock>> { - self.inner.signers() + self.inner.eth_api.signers() } } @@ -176,17 +174,17 @@ where { #[inline] fn io_task_spawner(&self) -> impl TaskSpawner { - self.inner.task_spawner() + self.inner.eth_api.task_spawner() } #[inline] fn tracing_task_pool(&self) -> &BlockingTaskPool { - self.inner.blocking_task_pool() + self.inner.eth_api.blocking_task_pool() } #[inline] fn tracing_task_guard(&self) -> &BlockingTaskGuard { - self.inner.blocking_task_guard() + self.inner.eth_api.blocking_task_guard() } } @@ -202,12 +200,12 @@ where { #[inline] fn gas_oracle(&self) -> &GasPriceOracle { - self.inner.gas_oracle() + self.inner.eth_api.gas_oracle() } #[inline] fn fee_history_cache(&self) -> &FeeHistoryCache { - self.inner.fee_history_cache() + self.inner.eth_api.fee_history_cache() } } @@ -226,7 +224,7 @@ where { #[inline] fn max_proof_window(&self) -> u64 { - self.inner.eth_proof_window() + self.inner.eth_api.eth_proof_window() } fn get_proof( @@ -258,7 +256,7 @@ where .map_err(Self::Error::from_eth_err)? .ok_or(EthApiError::HeaderNotFound(block_id))?; - if self.storage_proof_only.contains(&address) { + if self.inner.storage_proof_only.contains(&address) { self.spawn_blocking_io(move |this| { let b256_keys: Vec = keys.iter().map(|k| k.as_b256()).collect(); let state = this.state_at_block_id(block_number.into())?; @@ -320,7 +318,7 @@ where N: RpcNodeCore, { fn with_dev_accounts(&self) { - *self.inner.signers().write() = DevSigner::random_signers(20) + *self.inner.eth_api.signers().write() = DevSigner::random_signers(20) } } @@ -331,11 +329,9 @@ impl fmt::Debug for OpEthApi { } /// Container type `OpEthApi` -#[derive(Deref)] #[allow(missing_debug_implementations)] -pub struct OpEthApiInner { +struct OpEthApiInner { /// Gateway to node's core components. - #[deref] eth_api: EthApiNodeBackend, /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. diff --git a/crates/optimism/rpc/src/eth/pending_block.rs b/crates/optimism/rpc/src/eth/pending_block.rs index 98ea65778d8d..499d45da099c 100644 --- a/crates/optimism/rpc/src/eth/pending_block.rs +++ b/crates/optimism/rpc/src/eth/pending_block.rs @@ -36,7 +36,7 @@ where { #[inline] fn pending_block(&self) -> &tokio::sync::Mutex> { - self.inner.pending_block() + self.inner.eth_api.pending_block() } /// Returns the locally built pending block diff --git a/crates/optimism/rpc/src/eth/receipt.rs b/crates/optimism/rpc/src/eth/receipt.rs index e803ea210197..2a4df1ada49d 100644 --- a/crates/optimism/rpc/src/eth/receipt.rs +++ b/crates/optimism/rpc/src/eth/receipt.rs @@ -31,6 +31,8 @@ where receipt: Receipt, ) -> Result, Self::Error> { let (block, receipts) = self + .inner + .eth_api .cache() .get_block_and_receipts(meta.block_hash) .await @@ -43,7 +45,7 @@ where reth_optimism_evm::extract_l1_info(&block.body).map_err(OpEthApiError::from)?; Ok(OpReceiptBuilder::new( - &self.inner.provider().chain_spec(), + &self.inner.eth_api.provider().chain_spec(), &tx, meta, &receipt, diff --git a/crates/optimism/rpc/src/eth/transaction.rs b/crates/optimism/rpc/src/eth/transaction.rs index 3202dc46ad1b..2b92927f6495 100644 --- a/crates/optimism/rpc/src/eth/transaction.rs +++ b/crates/optimism/rpc/src/eth/transaction.rs @@ -23,7 +23,7 @@ where N: RpcNodeCore, { fn signers(&self) -> &parking_lot::RwLock>> { - self.inner.signers() + self.inner.eth_api.signers() } /// Decodes and recovers the transaction and submits it to the pool. @@ -68,7 +68,7 @@ where { /// Returns the [`SequencerClient`] if one is set. pub fn raw_tx_forwarder(&self) -> Option { - self.sequencer_client.clone() + self.inner.sequencer_client.clone() } } @@ -106,6 +106,7 @@ where } reth_primitives::Transaction::Deposit(tx) => { self.inner + .eth_api .provider() .receipt_by_hash(hash) .map_err(Self::Error::from_eth_err)? From e0d310be64d43e5374f44245c784108a94b7338e Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:43:09 +0000 Subject: [PATCH 12/15] rm storage proof --- Cargo.lock | 4 -- crates/optimism/node/src/args.rs | 7 -- crates/optimism/node/src/node.rs | 29 ++------ crates/optimism/rpc/Cargo.toml | 4 -- crates/optimism/rpc/src/eth/mod.rs | 104 ++--------------------------- 5 files changed, 11 insertions(+), 137 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b43a3858111c..10c10806a8a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8446,7 +8446,6 @@ dependencies = [ "alloy-primitives", "alloy-rpc-types-debug", "alloy-rpc-types-eth", - "alloy-serde", "jsonrpsee-core", "jsonrpsee-types", "op-alloy-consensus", @@ -8456,7 +8455,6 @@ dependencies = [ "parking_lot", "reqwest", "reth-chainspec", - "reth-errors", "reth-evm", "reth-network-api", "reth-node-api", @@ -8474,10 +8472,8 @@ dependencies = [ "reth-rpc-eth-api", "reth-rpc-eth-types", "reth-rpc-server-types", - "reth-rpc-types-compat", "reth-tasks", "reth-transaction-pool", - "reth-trie-common", "revm", "serde_json", "thiserror 2.0.3", diff --git a/crates/optimism/node/src/args.rs b/crates/optimism/node/src/args.rs index bda6202627ce..b84e98d28b19 100644 --- a/crates/optimism/node/src/args.rs +++ b/crates/optimism/node/src/args.rs @@ -2,7 +2,6 @@ //! clap [Args](clap::Args) for optimism rollup configuration -use alloy_primitives::Address; use reth_node_builder::engine_tree_config::{ DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD, }; @@ -57,11 +56,6 @@ pub struct RollupArgs { /// Configure the target number of blocks to keep in memory. #[arg(long = "engine.memory-block-buffer-target", conflicts_with = "legacy", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)] pub memory_block_buffer_target: u64, - - /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called - /// with `eth_getProof`. - #[arg(long = "rpc.storage-proof-addresses", value_delimiter = ',', num_args(1..))] - pub storage_proof_only: Vec
, } impl Default for RollupArgs { @@ -76,7 +70,6 @@ impl Default for RollupArgs { legacy: false, persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD, memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, - storage_proof_only: vec![], } } } diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index c62208cfce7c..2101f5bba424 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -7,7 +7,6 @@ use crate::{ OpEngineTypes, }; use alloy_consensus::Header; -use alloy_primitives::Address; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks}; use reth_db::transaction::{DbTx, DbTxMut}; @@ -147,7 +146,7 @@ impl OpNode { .pool(OpPoolBuilder::default()) .payload(OpPayloadBuilder::new(compute_pending_block)) .network(OpNetworkBuilder { - disable_txpool_gossip: disable_txpool_gossip, + disable_txpool_gossip, disable_discovery_v4: !discovery_v4, }) .executor(OpExecutorBuilder::default()) @@ -183,10 +182,7 @@ where } fn add_ons(&self) -> Self::AddOns { - OpAddOns::builder() - .with_sequencer(self.args.sequencer_http.clone()) - .with_storage_proof_only(self.args.storage_proof_only.clone()) - .build() + OpAddOns::builder().with_sequencer(self.args.sequencer_http.clone()).build() } } @@ -280,15 +276,12 @@ pub struct OpAddOnsBuilder { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. sequencer_client: Option, - /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called - /// with `eth_getProof`. - storage_proof_only: Vec
, _marker: PhantomData, } impl Default for OpAddOnsBuilder { fn default() -> Self { - Self { sequencer_client: None, storage_proof_only: vec![], _marker: PhantomData } + Self { sequencer_client: None, _marker: PhantomData } } } @@ -298,13 +291,6 @@ impl OpAddOnsBuilder { self.sequencer_client = sequencer_client.map(SequencerClient::new); self } - - /// With a list of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when - /// called with `eth_getProof`. - pub fn with_storage_proof_only(mut self, storage_proof_only: Vec
) -> Self { - self.storage_proof_only = storage_proof_only; - self - } } impl OpAddOnsBuilder @@ -313,15 +299,10 @@ where { /// Builds an instance of [`OpAddOns`]. pub fn build(self) -> OpAddOns { - let Self { sequencer_client, storage_proof_only, .. } = self; + let Self { sequencer_client, .. } = self; OpAddOns(RpcAddOns::new( - move |ctx| { - OpEthApi::builder(ctx) - .with_sequencer(sequencer_client) - .with_storage_proof_only(storage_proof_only) - .build() - }, + move |ctx| OpEthApi::builder(ctx).with_sequencer(sequencer_client).build(), Default::default(), )) } diff --git a/crates/optimism/rpc/Cargo.toml b/crates/optimism/rpc/Cargo.toml index 911d489c0a78..4b25066d6759 100644 --- a/crates/optimism/rpc/Cargo.toml +++ b/crates/optimism/rpc/Cargo.toml @@ -14,7 +14,6 @@ workspace = true [dependencies] # reth reth-evm.workspace = true -reth-errors.workspace = true reth-primitives.workspace = true reth-provider.workspace = true reth-rpc-eth-api.workspace = true @@ -24,12 +23,10 @@ reth-tasks = { workspace = true, features = ["rayon"] } reth-transaction-pool.workspace = true reth-rpc.workspace = true reth-rpc-api.workspace = true -reth-rpc-types-compat.workspace = true reth-node-api.workspace = true reth-network-api.workspace = true reth-node-builder.workspace = true reth-chainspec.workspace = true -reth-trie-common.workspace = true # op-reth reth-optimism-chainspec.workspace = true @@ -44,7 +41,6 @@ alloy-eips.workspace = true alloy-primitives.workspace = true alloy-rpc-types-eth.workspace = true alloy-rpc-types-debug.workspace = true -alloy-serde.workspace = true alloy-consensus.workspace = true op-alloy-network.workspace = true op-alloy-rpc-types.workspace = true diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 1e21f56a7917..deaea93dcfd3 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -13,19 +13,15 @@ use reth_optimism_primitives::OpPrimitives; use std::{fmt, sync::Arc}; use alloy_consensus::Header; -use alloy_eips::BlockId; -use alloy_primitives::{Address, B256, U256}; -use alloy_rpc_types_eth::EIP1186AccountProofResponse; -use alloy_serde::JsonStorageKey; +use alloy_primitives::{ U256}; use op_alloy_network::Optimism; use reth_chainspec::{EthChainSpec, EthereumHardforks}; -use reth_errors::RethError; use reth_evm::ConfigureEvm; use reth_network_api::NetworkInfo; use reth_node_builder::EthApiBuilderCtx; use reth_provider::{ - BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, CanonStateSubscriptions, - ChainSpecProvider, EvmEnvProvider, StageCheckpointReader, StateProviderFactory, + BlockNumReader, BlockReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, + EvmEnvProvider, StageCheckpointReader, StateProviderFactory, }; use reth_rpc::eth::{core::EthApiInner, DevSigner}; use reth_rpc_eth_api::{ @@ -33,17 +29,14 @@ use reth_rpc_eth_api::{ AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState, SpawnBlocking, Trace, }, - EthApiTypes, FromEthApiError, RpcNodeCore, RpcNodeCoreExt, + EthApiTypes, RpcNodeCore, RpcNodeCoreExt, }; -use reth_rpc_eth_types::{EthApiError, EthStateCache, FeeHistoryCache, GasPriceOracle}; -use reth_rpc_types_compat::proof::from_primitive_account_proof; +use reth_rpc_eth_types::{EthStateCache, FeeHistoryCache, GasPriceOracle}; use reth_tasks::{ pool::{BlockingTaskGuard, BlockingTaskPool}, TaskSpawner, }; use reth_transaction_pool::TransactionPool; -use reth_trie_common::AccountProof; -use std::future::Future; use crate::{OpEthApiError, SequencerClient}; @@ -226,77 +219,6 @@ where fn max_proof_window(&self) -> u64 { self.inner.eth_api.eth_proof_window() } - - fn get_proof( - &self, - address: Address, - keys: Vec, - block_id: Option, - ) -> Result< - impl Future> + Send, - Self::Error, - > - where - Self: EthApiSpec, - { - Ok(async move { - let _permit = self - .acquire_owned() - .await - .map_err(RethError::other) - .map_err(EthApiError::Internal)?; - - let chain_info = self.chain_info().map_err(Self::Error::from_eth_err)?; - let block_id = block_id.unwrap_or_default(); - - // Check whether the distance to the block exceeds the maximum configured window. - let block_number = self - .provider() - .block_number_for_id(block_id) - .map_err(Self::Error::from_eth_err)? - .ok_or(EthApiError::HeaderNotFound(block_id))?; - - if self.inner.storage_proof_only.contains(&address) { - self.spawn_blocking_io(move |this| { - let b256_keys: Vec = keys.iter().map(|k| k.as_b256()).collect(); - let state = this.state_at_block_id(block_number.into())?; - - let proofs = state - .storage_multiproof(address, &b256_keys, Default::default()) - .map_err(EthApiError::from_eth_err)?; - - let account_proof = AccountProof { - address, - storage_root: proofs.root, - storage_proofs: b256_keys - .into_iter() - .map(|k| proofs.storage_proof(k)) - .collect::>() - .map_err(RethError::other) - .map_err(Self::Error::from_eth_err)?, - ..Default::default() - }; - Ok(from_primitive_account_proof(account_proof, keys)) - }) - .await - } else { - let max_window = self.max_proof_window(); - if chain_info.best_number.saturating_sub(block_number) > max_window { - return Err(EthApiError::ExceedsMaxProofWindow.into()) - } - - self.spawn_blocking_io(move |this| { - let state = this.state_at_block_id(block_id)?; - let storage_keys = keys.iter().map(|key| key.as_b256()).collect::>(); - let proof = state - .proof(Default::default(), address, &storage_keys) - .map_err(Self::Error::from_eth_err)?; - Ok(from_primitive_account_proof(proof, keys)) - }) - .await - } - }) - } } impl EthFees for OpEthApi @@ -336,9 +258,6 @@ struct OpEthApiInner { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. sequencer_client: Option, - /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called - /// with `eth_getProof`. - storage_proof_only: Vec
, } /// A type that knows how to build a [`OpEthApi`]. @@ -349,15 +268,12 @@ pub struct OpEthApiBuilder<'a, N: RpcNodeCore> { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. sequencer_client: Option, - /// List of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when called - /// with `eth_getProof`. - storage_proof_only: Vec
, } impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { /// Creates a [`OpEthApiBuilder`] instance from [`EthApiBuilderCtx`]. pub const fn new(ctx: &'a EthApiBuilderCtx) -> Self { - Self { ctx, sequencer_client: None, storage_proof_only: vec![] } + Self { ctx, sequencer_client: None } } /// With a [`SequencerClient`]. @@ -365,13 +281,6 @@ impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { self.sequencer_client = sequencer_client; self } - - /// With a list of addresses that _ONLY_ return storage proofs _WITHOUT_ an account proof when - /// called with `eth_getProof`. - pub fn with_storage_proof_only(mut self, storage_proof_only: Vec
) -> Self { - self.storage_proof_only = storage_proof_only; - self - } } impl OpEthApiBuilder<'_, N> @@ -409,7 +318,6 @@ where inner: Arc::new(OpEthApiInner { eth_api, sequencer_client: self.sequencer_client, - storage_proof_only: self.storage_proof_only, }), } } From 6b5978f668f9f456cfacb9b89fe6fe479c0b8835 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:47:39 +0000 Subject: [PATCH 13/15] move ctx from builder to fn build --- crates/optimism/node/src/node.rs | 2 +- crates/optimism/rpc/src/eth/mod.rs | 67 ++++++++++++++---------------- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 2101f5bba424..578541982132 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -302,7 +302,7 @@ where let Self { sequencer_client, .. } = self; OpAddOns(RpcAddOns::new( - move |ctx| OpEthApi::builder(ctx).with_sequencer(sequencer_client).build(), + move |ctx| OpEthApi::::builder().with_sequencer(sequencer_client).build(ctx), Default::default(), )) } diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index deaea93dcfd3..3671ca6336ad 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -13,7 +13,7 @@ use reth_optimism_primitives::OpPrimitives; use std::{fmt, sync::Arc}; use alloy_consensus::Header; -use alloy_primitives::{ U256}; +use alloy_primitives::U256; use op_alloy_network::Optimism; use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_evm::ConfigureEvm; @@ -75,8 +75,8 @@ where >, { /// Build a [`OpEthApi`] using [`OpEthApiBuilder`]. - pub const fn builder(ctx: &EthApiBuilderCtx) -> OpEthApiBuilder<'_, N> { - OpEthApiBuilder::new(ctx) + pub const fn builder() -> OpEthApiBuilder { + OpEthApiBuilder::new() } } @@ -262,18 +262,16 @@ struct OpEthApiInner { /// A type that knows how to build a [`OpEthApi`]. #[allow(missing_debug_implementations)] -pub struct OpEthApiBuilder<'a, N: RpcNodeCore> { - /// Gateway to node's core components. - ctx: &'a EthApiBuilderCtx, +pub struct OpEthApiBuilder { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. sequencer_client: Option, } -impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { +impl OpEthApiBuilder { /// Creates a [`OpEthApiBuilder`] instance from [`EthApiBuilderCtx`]. - pub const fn new(ctx: &'a EthApiBuilderCtx) -> Self { - Self { ctx, sequencer_client: None } + pub const fn new() -> Self { + Self { sequencer_client: None } } /// With a [`SequencerClient`]. @@ -283,42 +281,39 @@ impl<'a, N: RpcNodeCore> OpEthApiBuilder<'a, N> { } } -impl OpEthApiBuilder<'_, N> -where - N: RpcNodeCore< - Provider: BlockReaderIdExt - + ChainSpecProvider - + CanonStateSubscriptions - + Clone - + 'static, - >, -{ +impl OpEthApiBuilder { /// Builds an instance of [`OpEthApi`] - pub fn build(self) -> OpEthApi { + pub fn build(self, ctx: &EthApiBuilderCtx) -> OpEthApi + where + N: RpcNodeCore< + Provider: BlockReaderIdExt + + ChainSpecProvider + + CanonStateSubscriptions + + Clone + + 'static, + >, + { let blocking_task_pool = BlockingTaskPool::build().expect("failed to build blocking task pool"); let eth_api = EthApiInner::new( - self.ctx.provider.clone(), - self.ctx.pool.clone(), - self.ctx.network.clone(), - self.ctx.cache.clone(), - self.ctx.new_gas_price_oracle(), - self.ctx.config.rpc_gas_cap, - self.ctx.config.rpc_max_simulate_blocks, - self.ctx.config.eth_proof_window, + ctx.provider.clone(), + ctx.pool.clone(), + ctx.network.clone(), + ctx.cache.clone(), + ctx.new_gas_price_oracle(), + ctx.config.rpc_gas_cap, + ctx.config.rpc_max_simulate_blocks, + ctx.config.eth_proof_window, blocking_task_pool, - self.ctx.new_fee_history_cache(), - self.ctx.evm_config.clone(), - self.ctx.executor.clone(), - self.ctx.config.proof_permits, + ctx.new_fee_history_cache(), + ctx.evm_config.clone(), + ctx.executor.clone(), + ctx.config.proof_permits, ); OpEthApi { - inner: Arc::new(OpEthApiInner { - eth_api, - sequencer_client: self.sequencer_client, - }), + inner: Arc::new(OpEthApiInner { eth_api, sequencer_client: self.sequencer_client }), } } } From 365f98f001f1d92b5cbe9656a9331f808a170ce0 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:03:33 +0000 Subject: [PATCH 14/15] move ctx from builder to fn build on AddOns --- crates/optimism/node/src/node.rs | 31 +++++++++--------------- crates/optimism/node/tests/it/builder.rs | 9 ++++--- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 578541982132..d4429026745b 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -46,7 +46,7 @@ use reth_transaction_pool::{ TransactionValidationTaskExecutor, }; use reth_trie_db::MerklePatriciaTrie; -use std::{marker::PhantomData, sync::Arc}; +use std::sync::Arc; /// Storage implementation for Optimism. #[derive(Debug, Default, Clone)] @@ -182,7 +182,7 @@ where } fn add_ons(&self) -> Self::AddOns { - OpAddOns::builder().with_sequencer(self.args.sequencer_http.clone()).build() + Self::AddOns::builder().with_sequencer(self.args.sequencer_http.clone()).build() } } @@ -207,9 +207,9 @@ impl>> Default } } -impl OpAddOns { +impl>> OpAddOns { /// Build a [`OpAddOns`] using [`OpAddOnsBuilder`]. - pub fn builder() -> OpAddOnsBuilder { + pub fn builder() -> OpAddOnsBuilder { OpAddOnsBuilder::default() } } @@ -270,22 +270,15 @@ where } /// A regular optimism evm and executor builder. -#[derive(Debug, Clone)] +#[derive(Debug, Default, Clone)] #[non_exhaustive] -pub struct OpAddOnsBuilder { +pub struct OpAddOnsBuilder { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network. sequencer_client: Option, - _marker: PhantomData, -} - -impl Default for OpAddOnsBuilder { - fn default() -> Self { - Self { sequencer_client: None, _marker: PhantomData } - } } -impl OpAddOnsBuilder { +impl OpAddOnsBuilder { /// With a [`SequencerClient`]. pub fn with_sequencer(mut self, sequencer_client: Option) -> Self { self.sequencer_client = sequencer_client.map(SequencerClient::new); @@ -293,12 +286,12 @@ impl OpAddOnsBuilder { } } -impl OpAddOnsBuilder -where - N: FullNodeComponents>, -{ +impl OpAddOnsBuilder { /// Builds an instance of [`OpAddOns`]. - pub fn build(self) -> OpAddOns { + pub fn build(self) -> OpAddOns + where + N: FullNodeComponents>, + { let Self { sequencer_client, .. } = self; OpAddOns(RpcAddOns::new( diff --git a/crates/optimism/node/tests/it/builder.rs b/crates/optimism/node/tests/it/builder.rs index 89f04bef422f..875b282e0ad0 100644 --- a/crates/optimism/node/tests/it/builder.rs +++ b/crates/optimism/node/tests/it/builder.rs @@ -2,20 +2,21 @@ use reth_db::test_utils::create_test_rw_db; use reth_node_api::FullNodeComponents; -use reth_node_builder::{NodeBuilder, NodeConfig}; +use reth_node_builder::{Node, NodeBuilder, NodeConfig}; use reth_optimism_chainspec::BASE_MAINNET; -use reth_optimism_node::{node::OpAddOns, OpNode}; +use reth_optimism_node::{args::RollupArgs, OpNode}; #[test] fn test_basic_setup() { // parse CLI -> config let config = NodeConfig::new(BASE_MAINNET.clone()); let db = create_test_rw_db(); + let args = RollupArgs::default(); let _builder = NodeBuilder::new(config) .with_database(db) .with_types::() - .with_components(OpNode::components(Default::default())) - .with_add_ons(OpAddOns::builder().build()) + .with_components(OpNode::components(args.clone())) + .with_add_ons(OpNode::new(args).add_ons()) .on_component_initialized(move |ctx| { let _provider = ctx.provider(); Ok(()) From 7ed3313e85dde0efe147c1bda1215908347ca46e Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:22:45 +0000 Subject: [PATCH 15/15] clippy --- crates/optimism/rpc/src/eth/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index 3671ca6336ad..27672804839b 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -261,7 +261,7 @@ struct OpEthApiInner { } /// A type that knows how to build a [`OpEthApi`]. -#[allow(missing_debug_implementations)] +#[derive(Debug, Default)] pub struct OpEthApiBuilder { /// Sequencer client, configured to forward submitted transactions to sequencer of given OP /// network.