reth_optimism_cli/commands/
mod.rs

1use crate::chainspec::OpChainSpecParser;
2use clap::Subcommand;
3use import::ImportOpCommand;
4use import_receipts::ImportReceiptsOpCommand;
5use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
6use reth_cli::chainspec::ChainSpecParser;
7use reth_cli_commands::{
8    config_cmd, db, dump_genesis, init_cmd,
9    node::{self, NoArgs},
10    p2p, prune, re_execute, recover, stage,
11};
12use std::{fmt, sync::Arc};
13
14pub mod import;
15pub mod import_receipts;
16pub mod init_state;
17
18#[cfg(feature = "dev")]
19pub mod test_vectors;
20
21/// Commands to be executed
22#[derive(Debug, Subcommand)]
23pub enum Commands<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs>
24{
25    /// Start the node
26    #[command(name = "node")]
27    Node(Box<node::NodeCommand<Spec, Ext>>),
28    /// Initialize the database from a genesis file.
29    #[command(name = "init")]
30    Init(init_cmd::InitCommand<Spec>),
31    /// Initialize the database from a state dump file.
32    #[command(name = "init-state")]
33    InitState(init_state::InitStateCommandOp<Spec>),
34    /// This syncs RLP encoded OP blocks below Bedrock from a file, without executing.
35    #[command(name = "import-op")]
36    ImportOp(ImportOpCommand<Spec>),
37    /// This imports RLP encoded receipts from a file.
38    #[command(name = "import-receipts-op")]
39    ImportReceiptsOp(ImportReceiptsOpCommand<Spec>),
40    /// Dumps genesis block JSON configuration to stdout.
41    DumpGenesis(dump_genesis::DumpGenesisCommand<Spec>),
42    /// Database debugging utilities
43    #[command(name = "db")]
44    Db(db::Command<Spec>),
45    /// Manipulate individual stages.
46    #[command(name = "stage")]
47    Stage(Box<stage::Command<Spec>>),
48    /// P2P Debugging utilities
49    #[command(name = "p2p")]
50    P2P(Box<p2p::Command<Spec>>),
51    /// Write config to stdout
52    #[command(name = "config")]
53    Config(config_cmd::Command),
54    /// Scripts for node recovery
55    #[command(name = "recover")]
56    Recover(recover::Command<Spec>),
57    /// Prune according to the configuration without any limits
58    #[command(name = "prune")]
59    Prune(prune::PruneCommand<Spec>),
60    /// Generate Test Vectors
61    #[cfg(feature = "dev")]
62    #[command(name = "test-vectors")]
63    TestVectors(test_vectors::Command),
64    /// Re-execute blocks in parallel to verify historical sync correctness.
65    #[command(name = "re-execute")]
66    ReExecute(re_execute::Command<Spec>),
67}
68
69impl<
70        C: ChainSpecParser<ChainSpec: EthChainSpec + Hardforks + EthereumHardforks>,
71        Ext: clap::Args + fmt::Debug,
72    > Commands<C, Ext>
73{
74    /// Returns the underlying chain being used for commands
75    pub fn chain_spec(&self) -> Option<&Arc<C::ChainSpec>> {
76        match self {
77            Self::Node(cmd) => cmd.chain_spec(),
78            Self::Init(cmd) => cmd.chain_spec(),
79            Self::InitState(cmd) => cmd.chain_spec(),
80            Self::DumpGenesis(cmd) => cmd.chain_spec(),
81            Self::Db(cmd) => cmd.chain_spec(),
82            Self::Stage(cmd) => cmd.chain_spec(),
83            Self::P2P(cmd) => cmd.chain_spec(),
84            Self::Config(_) => None,
85            Self::Recover(cmd) => cmd.chain_spec(),
86            Self::Prune(cmd) => cmd.chain_spec(),
87            Self::ImportOp(cmd) => cmd.chain_spec(),
88            Self::ImportReceiptsOp(cmd) => cmd.chain_spec(),
89            #[cfg(feature = "dev")]
90            Self::TestVectors(_) => None,
91            Self::ReExecute(cmd) => cmd.chain_spec(),
92        }
93    }
94}