Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimism Cli struct #9416

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/optimism/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ 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
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
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/cli/src/commands/build_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB, C>(
pub(crate) async fn build_import_pipeline<DB, C>(
config: &Config,
provider_factory: ProviderFactory<DB>,
consensus: &Arc<C>,
Expand Down
52 changes: 51 additions & 1 deletion crates/optimism/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -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<Ext: clap::Args + fmt::Debug = NoArgs> {
/// Start the node
#[command(name = "node")]
Node(node::NodeCommand<Ext>),
/// 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),
}
71 changes: 71 additions & 0 deletions crates/optimism/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ext: clap::Args + fmt::Debug = NoArgs> {
/// The command to run
#[command(subcommand)]
command: Commands<Ext>,

/// 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<ChainSpec>,

/// 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<I, T>(itr: I) -> Result<Self, clap::error::Error>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
Self::try_parse_from(itr)
}
}
Loading