diff --git a/bin/reth/src/cli.rs b/bin/reth/src/cli.rs index bc55ce1bc4..9b5ae13a13 100644 --- a/bin/reth/src/cli.rs +++ b/bin/reth/src/cli.rs @@ -1,8 +1,8 @@ //! CLI definition and entrypoint to executable use crate::{ - chain, config, db, + chain, config, db, debug_cmd, dirs::{LogsDir, PlatformPath}, - execution_debug, merkle_debug, node, p2p, + node, p2p, runner::CliRunner, stage, test_vectors, version::{LONG_VERSION, SHORT_VERSION}, @@ -36,10 +36,7 @@ pub fn run() -> eyre::Result<()> { Commands::P2P(command) => runner.run_until_ctrl_c(command.execute()), Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()), Commands::Config(command) => runner.run_until_ctrl_c(command.execute()), - Commands::MerkleDebug(command) => runner.run_until_ctrl_c(command.execute()), - Commands::ExecutionDebug(command) => { - runner.run_command_until_exit(|ctx| command.execute(ctx)) - } + Commands::Debug(command) => runner.run_command_until_exit(|ctx| command.execute(ctx)), } } @@ -70,12 +67,9 @@ pub enum Commands { /// Write config to stdout #[command(name = "config")] Config(config::Command), - /// Debug state root calculation - #[command(name = "merkle-debug")] - MerkleDebug(merkle_debug::Command), - /// Debug execution. - #[command(name = "execution-debug")] - ExecutionDebug(execution_debug::Command), + /// Various debug routines + #[command(name = "debug")] + Debug(debug_cmd::Command), } #[derive(Debug, Parser)] diff --git a/bin/reth/src/execution_debug.rs b/bin/reth/src/debug_cmd/execution.rs similarity index 97% rename from bin/reth/src/execution_debug.rs rename to bin/reth/src/debug_cmd/execution.rs index 9807adb7f5..e2a7de034f 100644 --- a/bin/reth/src/execution_debug.rs +++ b/bin/reth/src/debug_cmd/execution.rs @@ -95,15 +95,11 @@ pub struct Command { /// The block interval for sync and unwind. /// Defaults to `1000`. - #[arg(long)] - pub interval: Option, + #[arg(long, default_value = "1000")] + pub interval: u64, } impl Command { - fn interval(&self) -> u64 { - self.interval.unwrap_or(1000) - } - fn build_pipeline( &self, config: &Config, @@ -262,11 +258,10 @@ impl Command { return Ok(()) } - let interval = self.interval(); let mut current_max_block = latest_block_number; while current_max_block < self.to { let next_block = current_max_block + 1; - let target_block = self.to.min(current_max_block + interval); + let target_block = self.to.min(current_max_block + self.interval); let target_block_hash = self.fetch_block_hash(fetch_client.clone(), target_block).await?; diff --git a/bin/reth/src/merkle_debug.rs b/bin/reth/src/debug_cmd/merkle.rs similarity index 100% rename from bin/reth/src/merkle_debug.rs rename to bin/reth/src/debug_cmd/merkle.rs diff --git a/bin/reth/src/debug_cmd/mod.rs b/bin/reth/src/debug_cmd/mod.rs new file mode 100644 index 0000000000..463c423508 --- /dev/null +++ b/bin/reth/src/debug_cmd/mod.rs @@ -0,0 +1,33 @@ +//! `reth debug` command. Collection of various debugging routines. +use clap::{Parser, Subcommand}; + +use crate::runner::CliContext; + +mod execution; +mod merkle; + +/// `reth debug` command +#[derive(Debug, Parser)] +pub struct Command { + #[clap(subcommand)] + command: Subcommands, +} + +/// `reth debug` subcommands +#[derive(Subcommand, Debug)] +pub enum Subcommands { + /// Debug the roundtrip execution of blocks as well as the generated data. + Execution(execution::Command), + /// Debug the clean & incremental state root calculations. + Merkle(merkle::Command), +} + +impl Command { + /// Execute `debug` command + pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> { + match self.command { + Subcommands::Execution(command) => command.execute(ctx).await, + Subcommands::Merkle(command) => command.execute().await, + } + } +} diff --git a/bin/reth/src/lib.rs b/bin/reth/src/lib.rs index 5509a09567..eaffb131c3 100644 --- a/bin/reth/src/lib.rs +++ b/bin/reth/src/lib.rs @@ -12,9 +12,8 @@ pub mod chain; pub mod cli; pub mod config; pub mod db; +pub mod debug_cmd; pub mod dirs; -pub mod execution_debug; -pub mod merkle_debug; pub mod node; pub mod p2p; pub mod prometheus_exporter; diff --git a/bin/reth/src/stage/mod.rs b/bin/reth/src/stage/mod.rs index bb94c404e8..ece1b11010 100644 --- a/bin/reth/src/stage/mod.rs +++ b/bin/reth/src/stage/mod.rs @@ -29,7 +29,7 @@ pub enum Subcommands { } impl Command { - /// Execute `db` command + /// Execute `stage` command pub async fn execute(self) -> eyre::Result<()> { match self.command { Subcommands::Run(command) => command.execute().await,