reth/commands/debug_cmd/
mod.rs

1//! `reth debug` command. Collection of various debugging routines.
2
3use clap::{Parser, Subcommand};
4use reth_chainspec::ChainSpec;
5use reth_cli::chainspec::ChainSpecParser;
6use reth_cli_commands::common::CliNodeTypes;
7use reth_cli_runner::CliContext;
8use reth_ethereum_primitives::EthPrimitives;
9use reth_node_ethereum::EthEngineTypes;
10use std::sync::Arc;
11
12mod build_block;
13mod execution;
14mod in_memory_merkle;
15mod merkle;
16
17/// `reth debug` command
18#[derive(Debug, Parser)]
19pub struct Command<C: ChainSpecParser> {
20    #[command(subcommand)]
21    command: Subcommands<C>,
22}
23
24/// `reth debug` subcommands
25#[derive(Subcommand, Debug)]
26pub enum Subcommands<C: ChainSpecParser> {
27    /// Debug the roundtrip execution of blocks as well as the generated data.
28    Execution(execution::Command<C>),
29    /// Debug the clean & incremental state root calculations.
30    Merkle(merkle::Command<C>),
31    /// Debug in-memory state root calculation.
32    InMemoryMerkle(in_memory_merkle::Command<C>),
33    /// Debug block building.
34    BuildBlock(build_block::Command<C>),
35}
36
37impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
38    /// Execute `debug` command
39    pub async fn execute<
40        N: CliNodeTypes<
41            Payload = EthEngineTypes,
42            Primitives = EthPrimitives,
43            ChainSpec = C::ChainSpec,
44        >,
45    >(
46        self,
47        ctx: CliContext,
48    ) -> eyre::Result<()> {
49        match self.command {
50            Subcommands::Execution(command) => command.execute::<N>(ctx).await,
51            Subcommands::Merkle(command) => command.execute::<N>(ctx).await,
52            Subcommands::InMemoryMerkle(command) => command.execute::<N>(ctx).await,
53            Subcommands::BuildBlock(command) => command.execute::<N>(ctx).await,
54        }
55    }
56    /// Returns the underlying chain being used to run this command
57    pub const fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
58        match &self.command {
59            Subcommands::Execution(command) => command.chain_spec(),
60            Subcommands::Merkle(command) => command.chain_spec(),
61            Subcommands::InMemoryMerkle(command) => command.chain_spec(),
62            Subcommands::BuildBlock(command) => command.chain_spec(),
63        }
64    }
65}