diff --git a/Cargo.lock b/Cargo.lock index 5c48a9d74..b71d76871 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6090,6 +6090,7 @@ dependencies = [ "reth-basic-payload-builder", "reth-beacon-consensus", "reth-blockchain-tree", + "reth-cli-runner", "reth-config", "reth-consensus-common", "reth-db", @@ -6244,6 +6245,16 @@ dependencies = [ "tracing", ] +[[package]] +name = "reth-cli-runner" +version = "0.2.0-beta.5" +dependencies = [ + "futures", + "reth-tasks", + "tokio", + "tracing", +] + [[package]] name = "reth-codecs" version = "0.2.0-beta.5" diff --git a/Cargo.toml b/Cargo.toml index 6aace0ad1..2ce5d813d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "bin/reth/", "crates/blockchain-tree/", + "crates/cli/runner/", "crates/config/", "crates/consensus/auto-seal/", "crates/consensus/beacon/", @@ -202,6 +203,7 @@ reth-basic-payload-builder = { path = "crates/payload/basic" } reth-beacon-consensus = { path = "crates/consensus/beacon" } reth-beacon-consensus-core = { path = "crates/consensus/beacon-core" } reth-blockchain-tree = { path = "crates/blockchain-tree" } +reth-cli-runner = { path = "crates/cli/runner" } reth-codecs = { path = "crates/storage/codecs" } reth-config = { path = "crates/config" } reth-consensus-common = { path = "crates/consensus/common" } diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index b57ea46ec..bf8922ccf 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -24,6 +24,7 @@ reth-interfaces = { workspace = true, features = ["clap"] } reth-transaction-pool.workspace = true reth-beacon-consensus.workspace = true reth-auto-seal-consensus.workspace = true +reth-cli-runner.workspace = true reth-consensus-common.workspace = true reth-blockchain-tree.workspace = true reth-rpc-engine-api.workspace = true diff --git a/bin/reth/src/cli/mod.rs b/bin/reth/src/cli/mod.rs index ff206eefc..1adc4975f 100644 --- a/bin/reth/src/cli/mod.rs +++ b/bin/reth/src/cli/mod.rs @@ -9,10 +9,10 @@ use crate::{ config_cmd, db, debug_cmd, dump_genesis, import, init_cmd, node, node::NoArgs, p2p, recover, stage, test_vectors, }, - core::cli::runner::CliRunner, version::{LONG_VERSION, SHORT_VERSION}, }; use clap::{value_parser, Parser, Subcommand}; +use reth_cli_runner::CliRunner; use reth_db::DatabaseEnv; use reth_node_builder::{InitState, WithLaunchContext}; use reth_primitives::ChainSpec; diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 063af9fc3..566198ec8 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -5,7 +5,6 @@ use crate::{ utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS}, DatabaseArgs, }, - core::cli::runner::CliContext, dirs::{DataDirPath, MaybePlatformPath}, }; use alloy_rlp::Decodable; @@ -18,6 +17,7 @@ use reth_beacon_consensus::BeaconConsensus; use reth_blockchain_tree::{ BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, }; +use reth_cli_runner::CliContext; use reth_db::{init_db, DatabaseEnv}; use reth_interfaces::{consensus::Consensus, RethResult}; use reth_node_api::PayloadBuilderAttributes; diff --git a/bin/reth/src/commands/debug_cmd/execution.rs b/bin/reth/src/commands/debug_cmd/execution.rs index 99edd2ef2..839e037ef 100644 --- a/bin/reth/src/commands/debug_cmd/execution.rs +++ b/bin/reth/src/commands/debug_cmd/execution.rs @@ -6,13 +6,13 @@ use crate::{ utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS}, DatabaseArgs, NetworkArgs, }, - core::cli::runner::CliContext, dirs::{DataDirPath, MaybePlatformPath}, utils::get_single_header, }; use clap::Parser; use futures::{stream::select as stream_select, StreamExt}; use reth_beacon_consensus::BeaconConsensus; +use reth_cli_runner::CliContext; use reth_config::{config::EtlConfig, Config}; use reth_db::{database::Database, init_db, DatabaseEnv}; use reth_downloaders::{ diff --git a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs index e579e446a..3632f4cff 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -6,12 +6,12 @@ use crate::{ utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS}, DatabaseArgs, NetworkArgs, }, - core::cli::runner::CliContext, dirs::{DataDirPath, MaybePlatformPath}, utils::{get_single_body, get_single_header}, }; use backon::{ConstantBuilder, Retryable}; use clap::Parser; +use reth_cli_runner::CliContext; use reth_config::Config; use reth_db::{init_db, DatabaseEnv}; use reth_interfaces::executor::BlockValidationError; diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index 5db0503e5..742e51c70 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -6,13 +6,13 @@ use crate::{ utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS}, DatabaseArgs, NetworkArgs, }, - core::cli::runner::CliContext, dirs::{DataDirPath, MaybePlatformPath}, utils::get_single_header, }; use backon::{ConstantBuilder, Retryable}; use clap::Parser; use reth_beacon_consensus::BeaconConsensus; +use reth_cli_runner::CliContext; use reth_config::Config; use reth_db::{cursor::DbCursorRO, init_db, tables, transaction::DbTx, DatabaseEnv}; use reth_interfaces::{consensus::Consensus, p2p::full_block::FullBlockClient}; diff --git a/bin/reth/src/commands/debug_cmd/mod.rs b/bin/reth/src/commands/debug_cmd/mod.rs index 512df32e8..c3704aff4 100644 --- a/bin/reth/src/commands/debug_cmd/mod.rs +++ b/bin/reth/src/commands/debug_cmd/mod.rs @@ -1,7 +1,8 @@ //! `reth debug` command. Collection of various debugging routines. -use crate::core::cli::runner::CliContext; use clap::{Parser, Subcommand}; +use reth_cli_runner::CliContext; + mod build_block; mod execution; mod in_memory_merkle; diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs index d1b99f074..0ef866396 100644 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ b/bin/reth/src/commands/debug_cmd/replay_engine.rs @@ -4,7 +4,6 @@ use crate::{ utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS}, DatabaseArgs, NetworkArgs, }, - core::cli::runner::CliContext, dirs::{DataDirPath, MaybePlatformPath}, }; use clap::Parser; @@ -14,6 +13,7 @@ use reth_beacon_consensus::{hooks::EngineHooks, BeaconConsensus, BeaconConsensus use reth_blockchain_tree::{ BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, }; +use reth_cli_runner::CliContext; use reth_config::Config; use reth_db::{init_db, DatabaseEnv}; use reth_interfaces::consensus::Consensus; diff --git a/bin/reth/src/commands/node/mod.rs b/bin/reth/src/commands/node/mod.rs index 786d6d1a1..349130486 100644 --- a/bin/reth/src/commands/node/mod.rs +++ b/bin/reth/src/commands/node/mod.rs @@ -6,10 +6,10 @@ use crate::{ DatabaseArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs, RpcServerArgs, TxPoolArgs, }, - core::cli::runner::CliContext, dirs::{DataDirPath, MaybePlatformPath}, }; use clap::{value_parser, Args, Parser}; +use reth_cli_runner::CliContext; use reth_db::{init_db, DatabaseEnv}; use reth_node_builder::{InitState, NodeBuilder, WithLaunchContext}; use reth_node_core::{node_config::NodeConfig, version}; diff --git a/bin/reth/src/commands/recover/mod.rs b/bin/reth/src/commands/recover/mod.rs index b1f778fea..d082f4e07 100644 --- a/bin/reth/src/commands/recover/mod.rs +++ b/bin/reth/src/commands/recover/mod.rs @@ -1,7 +1,7 @@ //! `reth recover` command. -use crate::core::cli::runner::CliContext; use clap::{Parser, Subcommand}; +use reth_cli_runner::CliContext; mod storage_tries; diff --git a/bin/reth/src/commands/recover/storage_tries.rs b/bin/reth/src/commands/recover/storage_tries.rs index 6b619b945..7a1c2ccc2 100644 --- a/bin/reth/src/commands/recover/storage_tries.rs +++ b/bin/reth/src/commands/recover/storage_tries.rs @@ -1,9 +1,9 @@ use crate::{ args::utils::{chain_help, genesis_value_parser, SUPPORTED_CHAINS}, - core::cli::runner::CliContext, dirs::{DataDirPath, MaybePlatformPath}, }; use clap::Parser; +use reth_cli_runner::CliContext; use reth_db::{ cursor::{DbCursorRO, DbDupCursorRW}, init_db, tables, diff --git a/bin/reth/src/lib.rs b/bin/reth/src/lib.rs index 00e2c586a..42f26115c 100644 --- a/bin/reth/src/lib.rs +++ b/bin/reth/src/lib.rs @@ -158,6 +158,10 @@ pub mod rpc { } } +// re-export for convenience +#[doc(inline)] +pub use reth_cli_runner::{tokio_runtime, CliContext, CliRunner}; + #[cfg(all(unix, any(target_env = "gnu", target_os = "macos")))] pub mod sigsegv_handler; diff --git a/crates/cli/runner/Cargo.toml b/crates/cli/runner/Cargo.toml new file mode 100644 index 000000000..697621cee --- /dev/null +++ b/crates/cli/runner/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "reth-cli-runner" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[lints] +workspace = true + +[dependencies] +# reth +reth-tasks.workspace = true + +# async +futures.workspace = true +tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] } + +# misc +tracing.workspace = true diff --git a/crates/node-core/src/cli/runner.rs b/crates/cli/runner/src/lib.rs similarity index 93% rename from crates/node-core/src/cli/runner.rs rename to crates/cli/runner/src/lib.rs index 9c2b717cd..31a1356c6 100644 --- a/crates/node-core/src/cli/runner.rs +++ b/crates/cli/runner/src/lib.rs @@ -1,3 +1,13 @@ +//! A tokio based CLI runner. + +#![doc( + html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", + html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", + issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + //! Entrypoint for running commands. use futures::pin_mut; @@ -6,6 +16,8 @@ use std::future::Future; use tracing::{debug, error, trace}; /// Executes CLI commands. +/// +/// Provides utilities for running a cli command to completion. #[derive(Clone, Debug, Default)] #[non_exhaustive] pub struct CliRunner; diff --git a/crates/node-core/src/cli/mod.rs b/crates/node-core/src/cli/mod.rs index fa14c5ee8..0ae8d33c0 100644 --- a/crates/node-core/src/cli/mod.rs +++ b/crates/node-core/src/cli/mod.rs @@ -1,4 +1,3 @@ //! Additional CLI configuration support. pub mod config; -pub mod runner;