diff --git a/Cargo.lock b/Cargo.lock index 148c7cecb98..7a8207b31b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6525,7 +6525,6 @@ dependencies = [ "clap", "eyre", "futures-util", - "humantime", "reth-chainspec", "reth-cli-util", "reth-db", @@ -9974,6 +9973,7 @@ dependencies = [ "clap", "eyre", "futures", + "humantime", "op-alloy-consensus", "op-alloy-network", "op-alloy-rpc-types-engine", diff --git a/crates/optimism/bin/op-reth/Cargo.toml b/crates/optimism/bin/op-reth/Cargo.toml index 6ef9822e5c7..9549ebc9dbe 100644 --- a/crates/optimism/bin/op-reth/Cargo.toml +++ b/crates/optimism/bin/op-reth/Cargo.toml @@ -32,7 +32,6 @@ tracing.workspace = true eyre.workspace = true futures-util.workspace = true tokio.workspace = true -humantime.workspace = true [lints] workspace = true diff --git a/crates/optimism/bin/op-reth/src/main.rs b/crates/optimism/bin/op-reth/src/main.rs index ad574c96964..09aff01c731 100644 --- a/crates/optimism/bin/op-reth/src/main.rs +++ b/crates/optimism/bin/op-reth/src/main.rs @@ -1,6 +1,6 @@ #![allow(missing_docs, rustdoc::missing_crate_level_docs)] -use clap::{builder::ArgPredicate, Parser}; +use clap::Parser; use eyre::ErrReport; use futures_util::FutureExt; use reth_db::DatabaseEnv; @@ -16,7 +16,7 @@ use reth_optimism_rpc::{ }; use reth_optimism_trie::{db::MdbxProofsStorage, OpProofsStorage}; use reth_tasks::TaskExecutor; -use std::{path::PathBuf, sync::Arc, time::Duration}; +use std::{sync::Arc, time::Duration}; use tokio::time::sleep; use tracing::info; @@ -27,89 +27,21 @@ static ALLOC: reth_cli_util::allocator::Allocator = reth_cli_util::allocator::ne #[unsafe(export_name = "_rjem_malloc_conf")] static MALLOC_CONF: &[u8] = b"prof:true,prof_active:true,lg_prof_sample:19\0"; -#[derive(Debug, Clone, PartialEq, Eq, clap::Args)] -#[command(next_help_heading = "Proofs History")] -struct Args { - #[command(flatten)] - pub rollup_args: RollupArgs, - - /// If true, initialize external-proofs exex to save and serve trie nodes to provide proofs - /// faster. - #[arg( - long = "proofs-history", - value_name = "PROOFS_HISTORY", - default_value_ifs([ - ("proofs-history.storage-path", ArgPredicate::IsPresent, "true") - ]) - )] - pub proofs_history: bool, - - /// The path to the storage DB for proofs history. - #[arg(long = "proofs-history.storage-path", value_name = "PROOFS_HISTORY_STORAGE_PATH")] - pub proofs_history_storage_path: Option, - - /// The window to span blocks for proofs history. Value is the number of blocks. - /// Default is 1 month of blocks based on 2 seconds block time. - /// 30 * 24 * 60 * 60 / 2 = `1_296_000` - #[arg( - long = "proofs-history.window", - default_value_t = 1_296_000, - value_name = "PROOFS_HISTORY_WINDOW" - )] - pub proofs_history_window: u64, - - /// Interval between proof-storage prune runs. Accepts human-friendly durations - /// like "100s", "5m", "1h". Defaults to 15s. - /// - /// - Shorter intervals prune smaller batches more often, so each prune run tends to be faster - /// and the blocking pause for writes is shorter, at the cost of more frequent pauses. - /// - Longer intervals prune larger batches less often, which reduces how often pruning runs, - /// but each run can take longer and block writes for longer. - /// - /// A shorter interval is preferred so that prune - /// runs stay small and don’t stall writes for too long. - /// - /// CLI: `--proofs-history.prune-interval 10m` - #[arg( - long = "proofs-history.prune-interval", - value_name = "PROOFS_HISTORY_PRUNE_INTERVAL", - default_value = "15s", - value_parser = humantime::parse_duration - )] - pub proofs_history_prune_interval: Duration, - /// Verification interval: perform full block execution every N blocks for data integrity. - /// - 0: Disabled (Default) (always use fast path with pre-computed data from notifications) - /// - 1: Always verify (always execute blocks, slowest) - /// - N: Verify every Nth block (e.g., 100 = every 100 blocks) - /// - /// Periodic verification helps catch data corruption or consensus bugs while maintaining - /// good performance. - /// - /// CLI: `--proofs-history.verification-interval 100` - #[arg( - long = "proofs-history.verification-interval", - value_name = "PROOFS_HISTORY_VERIFICATION_INTERVAL", - default_value_t = 0 - )] - pub proofs_history_verification_interval: u64, -} - /// Single entry that handles: /// - no proofs history (plain node), /// - in-mem proofs storage, /// - MDBX proofs storage. async fn launch_node( builder: WithLaunchContext, OpChainSpec>>, - args: Args, + args: RollupArgs, ) -> eyre::Result<(), ErrReport> { let proofs_history_enabled = args.proofs_history; - let rollup_args = args.rollup_args.clone(); let proofs_history_window = args.proofs_history_window; let proofs_history_prune_interval = args.proofs_history_prune_interval; let proofs_history_verification_interval = args.proofs_history_verification_interval; // Start from a plain OpNode builder - let mut node_builder = builder.node(OpNode::new(rollup_args)); + let mut node_builder = builder.node(OpNode::new(args.clone())); if proofs_history_enabled { let path = args @@ -196,11 +128,13 @@ fn main() { } } - if let Err(err) = Cli::::parse().run(async move |builder, args| { - info!(target: "reth::cli", "Launching node"); - launch_node(builder, args.clone()).await?; - Ok(()) - }) { + if let Err(err) = + Cli::::parse().run(async move |builder, args| { + info!(target: "reth::cli", "Launching node"); + launch_node(builder, args.clone()).await?; + Ok(()) + }) + { eprintln!("Error: {err:?}"); std::process::exit(1); } diff --git a/crates/optimism/node/Cargo.toml b/crates/optimism/node/Cargo.toml index 062b9c8c810..2d09e2082a0 100644 --- a/crates/optimism/node/Cargo.toml +++ b/crates/optimism/node/Cargo.toml @@ -64,6 +64,7 @@ clap.workspace = true serde.workspace = true eyre.workspace = true url.workspace = true +humantime.workspace = true # test-utils dependencies reth-e2e-test-utils = { workspace = true, optional = true } diff --git a/crates/optimism/node/src/args.rs b/crates/optimism/node/src/args.rs index abddb76109c..4f6e1cc84b5 100644 --- a/crates/optimism/node/src/args.rs +++ b/crates/optimism/node/src/args.rs @@ -2,8 +2,10 @@ //! clap [Args](clap::Args) for optimism rollup configuration +use clap::builder::ArgPredicate; use op_alloy_consensus::interop::SafetyLevel; use reth_optimism_txpool::supervisor::DEFAULT_SUPERVISOR_URL; +use std::{path::PathBuf, time::Duration}; use url::Url; /// Parameters for rollup configuration @@ -82,6 +84,66 @@ pub struct RollupArgs { /// Requires `flashblocks_url` to be set. #[arg(long, default_value_t = false, requires = "flashblocks_url")] pub flashblock_consensus: bool, + + /// If true, initialize external-proofs exex to save and serve trie nodes to provide proofs + /// faster. + #[arg( + long = "proofs-history", + value_name = "PROOFS_HISTORY", + default_value_ifs([ + ("proofs-history.storage-path", ArgPredicate::IsPresent, "true") + ]) + )] + pub proofs_history: bool, + + /// The path to the storage DB for proofs history. + #[arg(long = "proofs-history.storage-path", value_name = "PROOFS_HISTORY_STORAGE_PATH")] + pub proofs_history_storage_path: Option, + + /// The window to span blocks for proofs history. Value is the number of blocks. + /// Default is 1 month of blocks based on 2 seconds block time. + /// 30 * 24 * 60 * 60 / 2 = `1_296_000` + #[arg( + long = "proofs-history.window", + default_value_t = 1_296_000, + value_name = "PROOFS_HISTORY_WINDOW" + )] + pub proofs_history_window: u64, + + /// Interval between proof-storage prune runs. Accepts human-friendly durations + /// like "100s", "5m", "1h". Defaults to 15s. + /// + /// - Shorter intervals prune smaller batches more often, so each prune run tends to be faster + /// and the blocking pause for writes is shorter, at the cost of more frequent pauses. + /// - Longer intervals prune larger batches less often, which reduces how often pruning runs, + /// but each run can take longer and block writes for longer. + /// + /// A shorter interval is preferred so that prune + /// runs stay small and don’t stall writes for too long. + /// + /// CLI: `--proofs-history.prune-interval 10m` + #[arg( + long = "proofs-history.prune-interval", + value_name = "PROOFS_HISTORY_PRUNE_INTERVAL", + default_value = "15s", + value_parser = humantime::parse_duration + )] + pub proofs_history_prune_interval: Duration, + /// Verification interval: perform full block execution every N blocks for data integrity. + /// - 0: Disabled (Default) (always use fast path with pre-computed data from notifications) + /// - 1: Always verify (always execute blocks, slowest) + /// - N: Verify every Nth block (e.g., 100 = every 100 blocks) + /// + /// Periodic verification helps catch data corruption or consensus bugs while maintaining + /// good performance. + /// + /// CLI: `--proofs-history.verification-interval 100` + #[arg( + long = "proofs-history.verification-interval", + value_name = "PROOFS_HISTORY_VERIFICATION_INTERVAL", + default_value_t = 0 + )] + pub proofs_history_verification_interval: u64, } impl Default for RollupArgs { @@ -99,6 +161,11 @@ impl Default for RollupArgs { min_suggested_priority_fee: 1_000_000, flashblocks_url: None, flashblock_consensus: false, + proofs_history: false, + proofs_history_storage_path: None, + proofs_history_window: 1_296_000, + proofs_history_prune_interval: Duration::from_secs(15), + proofs_history_verification_interval: 0, } } }