diff --git a/crates/optimism/cli/Cargo.toml b/crates/optimism/cli/Cargo.toml index ffe109379989..d17de95b6b9a 100644 --- a/crates/optimism/cli/Cargo.toml +++ b/crates/optimism/cli/Cargo.toml @@ -25,6 +25,8 @@ reth-static-file.workspace = true reth-execution-types.workspace = true reth-node-core.workspace = true reth-primitives.workspace = true + +reth-chainspec.workspace = true reth-stages-types.workspace = true reth-node-events.workspace = true reth-network-p2p.workspace = true @@ -32,7 +34,6 @@ reth-errors.workspace = true reth-config.workspace = true reth-evm-optimism.workspace = true reth-cli.workspace = true -reth-chainspec.workspace = true # eth alloy-genesis.workspace = true diff --git a/crates/optimism/cli/src/commands/build_pipeline.rs b/crates/optimism/cli/src/commands/build_pipeline.rs index 29761d0f7e49..e770a1e8b992 100644 --- a/crates/optimism/cli/src/commands/build_pipeline.rs +++ b/crates/optimism/cli/src/commands/build_pipeline.rs @@ -26,7 +26,7 @@ use tokio::sync::watch; /// /// If configured to execute, all stages will run. Otherwise, only stages that don't require state /// will run. -pub async fn build_import_pipeline( +pub(crate) async fn build_import_pipeline( config: &Config, provider_factory: ProviderFactory, consensus: &Arc, diff --git a/crates/optimism/cli/src/commands/mod.rs b/crates/optimism/cli/src/commands/mod.rs index 373e7802cd4a..4c63bb6237c6 100644 --- a/crates/optimism/cli/src/commands/mod.rs +++ b/crates/optimism/cli/src/commands/mod.rs @@ -1,4 +1,54 @@ +use clap::Subcommand; +use import::ImportOpCommand; +use import_receipts::ImportReceiptsOpCommand; +use reth_cli_commands::{ + config_cmd, db, dump_genesis, init_cmd, init_state, + node::{self, NoArgs}, + p2p, prune, recover, stage, +}; +use std::fmt; + /// Helper function to build an import pipeline. -pub mod build_pipeline; +mod build_pipeline; pub mod import; pub mod import_receipts; + +/// Commands to be executed +#[derive(Debug, Subcommand)] +pub enum Commands { + /// Start the node + #[command(name = "node")] + Node(node::NodeCommand), + /// Initialize the database from a genesis file. + #[command(name = "init")] + Init(init_cmd::InitCommand), + /// Initialize the database from a state dump file. + #[command(name = "init-state")] + InitState(init_state::InitStateCommand), + /// This syncs RLP encoded OP blocks below Bedrock from a file, without executing. + #[command(name = "import-op")] + ImportOp(ImportOpCommand), + /// This imports RLP encoded receipts from a file. + #[command(name = "import-receipts-op")] + ImportReceiptsOp(ImportReceiptsOpCommand), + /// Dumps genesis block JSON configuration to stdout. + DumpGenesis(dump_genesis::DumpGenesisCommand), + /// Database debugging utilities + #[command(name = "db")] + Db(db::Command), + /// Manipulate individual stages. + #[command(name = "stage")] + Stage(stage::Command), + /// P2P Debugging utilities + #[command(name = "p2p")] + P2P(p2p::Command), + /// Write config to stdout + #[command(name = "config")] + Config(config_cmd::Command), + /// Scripts for node recovery + #[command(name = "recover")] + Recover(recover::Command), + /// Prune according to the configuration without any limits + #[command(name = "prune")] + Prune(prune::PruneCommand), +} diff --git a/crates/optimism/cli/src/lib.rs b/crates/optimism/cli/src/lib.rs index 6becc745570c..e8559ebaee75 100644 --- a/crates/optimism/cli/src/lib.rs +++ b/crates/optimism/cli/src/lib.rs @@ -10,8 +10,79 @@ // The `optimism` feature must be enabled to use this crate. #![cfg(feature = "optimism")] +use chainspec::OpChainSpecParser; +use clap::{command, value_parser, Parser}; +use commands::Commands; +use reth_chainspec::ChainSpec; +use reth_cli::chainspec::ChainSpecParser; +use reth_cli_commands::node::NoArgs; +use reth_node_core::{ + args::{utils::chain_help, LogArgs}, + version::{LONG_VERSION, SHORT_VERSION}, +}; +use std::{ffi::OsString, fmt, sync::Arc}; + /// Optimism chain specification parser. pub mod chainspec; /// Optimism CLI commands. pub mod commands; pub use commands::{import::ImportOpCommand, import_receipts::ImportReceiptsOpCommand}; + +/// The main reth cli interface. +/// +/// This is the entrypoint to the executable. +#[derive(Debug, Parser)] +#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)] +pub struct Cli { + /// The command to run + #[command(subcommand)] + command: Commands, + + /// The chain this node is running. + /// + /// Possible values are either a built-in chain or the path to a chain specification file. + #[arg( + long, + value_name = "CHAIN_OR_PATH", + long_help = chain_help(), + default_value = OpChainSpecParser::SUPPORTED_CHAINS[0], + value_parser = OpChainSpecParser::default(), + global = true, + )] + chain: Arc, + + /// Add a new instance of a node. + /// + /// Configures the ports of the node to avoid conflicts with the defaults. + /// This is useful for running multiple nodes on the same machine. + /// + /// Max number of instances is 200. It is chosen in a way so that it's not possible to have + /// port numbers that conflict with each other. + /// + /// Changes to the following port numbers: + /// - `DISCOVERY_PORT`: default + `instance` - 1 + /// - `AUTH_PORT`: default + `instance` * 100 - 100 + /// - `HTTP_RPC_PORT`: default - `instance` + 1 + /// - `WS_RPC_PORT`: default + `instance` * 2 - 2 + #[arg(long, value_name = "INSTANCE", global = true, default_value_t = 1, value_parser = value_parser!(u16).range(..=200))] + instance: u16, + + #[command(flatten)] + logs: LogArgs, +} + +impl Cli { + /// Parsers only the default CLI arguments + pub fn parse_args() -> Self { + Self::parse() + } + + /// Parsers only the default CLI arguments from the given iterator + pub fn try_parse_args_from(itr: I) -> Result + where + I: IntoIterator, + T: Into + Clone, + { + Self::try_parse_from(itr) + } +}