diff --git a/bin/reth/src/args/mod.rs b/bin/reth/src/args/mod.rs new file mode 100644 index 000000000..c8f539f0c --- /dev/null +++ b/bin/reth/src/args/mod.rs @@ -0,0 +1,9 @@ +//! Parameters for configuring the rpc more granularity via CLI + +/// NetworkArg struct +mod network_args; +pub use network_args::NetworkArgs; + +/// RpcServerArg struct +mod rpc_server_args; +pub use rpc_server_args::RpcServerArgs; diff --git a/bin/reth/src/args/network_args.rs b/bin/reth/src/args/network_args.rs new file mode 100644 index 000000000..793ac9906 --- /dev/null +++ b/bin/reth/src/args/network_args.rs @@ -0,0 +1,39 @@ +//! clap [Args](clap::Args) for network related arguments. + +use crate::dirs::{KnownPeersPath, PlatformPath}; +use clap::Args; +use reth_primitives::NodeRecord; + +/// Parameters for configuring the network more granularity via CLI +#[derive(Debug, Args)] +#[command(next_help_heading = "Networking")] +pub struct NetworkArgs { + /// Disable the discovery service. + #[arg(short, long)] + pub disable_discovery: bool, + + /// Target trusted peer enodes + /// --trusted-peers enode://abcd@192.168.0.1:30303 + #[arg(long)] + pub trusted_peers: Vec, + + /// Connect only to trusted peers + #[arg(long)] + pub trusted_only: bool, + + /// Nodes to bootstrap network discovery. + /// + /// Will fall back to a network-specific default if not specified. + #[arg(long, value_delimiter = ',')] + pub bootnodes: Option>, + + /// The path to the known peers file. Connected peers are + /// dumped to this file on node shutdown, and read on startup. + /// Cannot be used with --no-persist-peers + #[arg(long, value_name = "FILE", verbatim_doc_comment, default_value_t)] + pub peers_file: PlatformPath, + + /// Do not persist peers. Cannot be used with --peers-file + #[arg(long, verbatim_doc_comment, conflicts_with = "peers_file")] + pub no_persist_peers: bool, +} diff --git a/bin/reth/src/args/rpc_server_args.rs b/bin/reth/src/args/rpc_server_args.rs new file mode 100644 index 000000000..737e6dd84 --- /dev/null +++ b/bin/reth/src/args/rpc_server_args.rs @@ -0,0 +1,75 @@ +//! clap [Args](clap::Args) for RPC related arguments. + +use clap::Args; +use reth_rpc_builder::RpcModuleConfig; +use std::net::IpAddr; + +/// Parameters for configuring the rpc more granularity via CLI +#[derive(Debug, Args, PartialEq, Default)] +#[command(next_help_heading = "Rpc")] +pub struct RpcServerArgs { + /// Enable the HTTP-RPC server + #[arg(long)] + pub http: bool, + + /// Http server address to listen on + #[arg(long = "http.addr")] + pub http_addr: Option, + + /// Http server port to listen on + #[arg(long = "http.port")] + pub http_port: Option, + + /// Rpc Modules to be configured for http server + #[arg(long = "http.api")] + pub http_api: Option, + + /// Enable the WS-RPC server + #[arg(long)] + pub ws: bool, + + /// Ws server address to listen on + #[arg(long = "ws.addr")] + pub ws_addr: Option, + + /// Http server port to listen on + #[arg(long = "ws.port")] + pub ws_port: Option, + + /// Rpc Modules to be configured for Ws server + #[arg(long = "ws.api")] + pub ws_api: Option, + + /// Disable the IPC-RPC server + #[arg(long)] + pub ipcdisable: bool, + + /// Filename for IPC socket/pipe within the datadir + #[arg(long)] + pub ipcpath: Option, +} + +#[cfg(test)] +mod tests { + use super::*; + use clap::Parser; + + /// A helper type to parse Args more easily + #[derive(Parser)] + struct CommandParser { + #[clap(flatten)] + args: T, + } + + #[test] + fn test_rpc_server_args_parser() { + let args = + CommandParser::::parse_from(["reth", "--http.api", "eth,admin,debug"]) + .args; + + let apis = args.http_api.unwrap(); + let expected = RpcModuleConfig::try_from_selection(["eth", "admin", "debug"]).unwrap(); + + assert_eq!(apis, expected); + } +} diff --git a/bin/reth/src/chain/import.rs b/bin/reth/src/chain/import.rs index 4dfb267b5..9cc4d9200 100644 --- a/bin/reth/src/chain/import.rs +++ b/bin/reth/src/chain/import.rs @@ -1,7 +1,6 @@ use crate::{ dirs::{ConfigPath, DbPath, PlatformPath}, node::{handle_events, NodeEvent}, - utils::{chainspec::genesis_value_parser, init::init_db}, }; use clap::{crate_version, Parser}; use eyre::Context; @@ -17,7 +16,13 @@ use reth_interfaces::{ sync::SyncStateUpdater, }; use reth_primitives::ChainSpec; -use reth_staged_sync::{utils::init::init_genesis, Config}; +use reth_staged_sync::{ + utils::{ + chainspec::genesis_value_parser, + init::{init_db, init_genesis}, + }, + Config, +}; use reth_stages::{ prelude::*, stages::{ExecutionStage, SenderRecoveryStage, TotalDifficultyStage}, diff --git a/bin/reth/src/chain/init.rs b/bin/reth/src/chain/init.rs index c596f2651..e8eb32afe 100644 --- a/bin/reth/src/chain/init.rs +++ b/bin/reth/src/chain/init.rs @@ -1,10 +1,10 @@ -use crate::{ - dirs::{DbPath, PlatformPath}, - utils::chainspec::genesis_value_parser, -}; +use crate::dirs::{DbPath, PlatformPath}; use clap::Parser; use reth_primitives::ChainSpec; -use reth_staged_sync::utils::init::{init_db, init_genesis}; +use reth_staged_sync::utils::{ + chainspec::genesis_value_parser, + init::{init_db, init_genesis}, +}; use std::sync::Arc; use tracing::info; diff --git a/bin/reth/src/lib.rs b/bin/reth/src/lib.rs index ad9335a1c..d9a30ef98 100644 --- a/bin/reth/src/lib.rs +++ b/bin/reth/src/lib.rs @@ -6,6 +6,7 @@ ))] //! Rust Ethereum (reth) binary executable. +pub mod args; pub mod chain; pub mod cli; pub mod db; @@ -16,115 +17,3 @@ pub mod prometheus_exporter; pub mod stage; pub mod test_eth_chain; pub mod test_vectors; -use dirs::{KnownPeersPath, PlatformPath}; -use std::net::IpAddr; - -use reth_rpc_builder::RpcModuleConfig; -pub use reth_staged_sync::utils; - -use clap::Args; -use reth_primitives::NodeRecord; - -/// Parameters for configuring the network more granularity via CLI -#[derive(Debug, Args)] -#[command(next_help_heading = "Networking")] -struct NetworkOpts { - /// Disable the discovery service. - #[arg(short, long)] - disable_discovery: bool, - - /// Target trusted peer enodes - /// --trusted-peers enode://abcd@192.168.0.1:30303 - #[arg(long)] - trusted_peers: Vec, - - /// Connect only to trusted peers - #[arg(long)] - trusted_only: bool, - - /// Bootnodes to connect to initially. - /// - /// Will fall back to a network-specific default if not specified. - #[arg(long, value_delimiter = ',')] - bootnodes: Option>, - - /// The path to the known peers file. Connected peers are - /// dumped to this file on node shutdown, and read on startup. - /// Cannot be used with --no-persist-peers - #[arg(long, value_name = "FILE", verbatim_doc_comment, default_value_t)] - peers_file: PlatformPath, - - /// Do not persist peers. Cannot be used with --peers-file - #[arg(long, verbatim_doc_comment, conflicts_with = "peers_file")] - no_persist_peers: bool, -} - -/// Parameters for configuring the rpc more granularity via CLI -#[derive(Debug, Args, PartialEq, Default)] -#[command(next_help_heading = "Rpc")] -struct RpcServerOpts { - /// Enable the HTTP-RPC server - #[arg(long)] - http: bool, - - /// Http server address to listen on - #[arg(long = "http.addr")] - http_addr: Option, - - /// Http server port to listen on - #[arg(long = "http.port")] - http_port: Option, - - /// Rpc Modules to be configured for http server - #[arg(long = "http.api")] - http_api: Option, - - /// Enable the WS-RPC server - #[arg(long)] - ws: bool, - - /// Ws server address to listen on - #[arg(long = "ws.addr")] - ws_addr: Option, - - /// Http server port to listen on - #[arg(long = "ws.port")] - ws_port: Option, - - /// Rpc Modules to be configured for Ws server - #[arg(long = "ws.api")] - ws_api: Option, - - /// Disable the IPC-RPC server - #[arg(long)] - ipcdisable: bool, - - /// Filename for IPC socket/pipe within the datadir - #[arg(long)] - ipcpath: Option, -} - -#[cfg(test)] -mod tests { - use super::*; - use clap::Parser; - - /// A helper type to parse Args more easily - #[derive(Parser)] - struct CommandParser { - #[clap(flatten)] - args: T, - } - - #[test] - fn test_rpc_server_opts_parser() { - let opts = - CommandParser::::parse_from(["reth", "--http.api", "eth,admin,debug"]) - .args; - - let apis = opts.http_api.unwrap(); - let expected = RpcModuleConfig::try_from_selection(["eth", "admin", "debug"]).unwrap(); - - assert_eq!(apis, expected); - } -} diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index 6edd7bb82..3dae8e83d 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -2,10 +2,9 @@ //! //! Starts the client use crate::{ + args::{NetworkArgs, RpcServerArgs}, dirs::{ConfigPath, DbPath, PlatformPath}, prometheus_exporter, - utils::{chainspec::genesis_value_parser, init::init_db, parse_socket_address}, - NetworkOpts, RpcServerOpts, }; use clap::{crate_version, Parser}; use eyre::Context; @@ -28,7 +27,14 @@ use reth_network_api::NetworkInfo; use reth_primitives::{BlockNumber, ChainSpec, H256}; use reth_provider::ShareableDatabase; use reth_rpc_builder::{RethRpcModule, RpcServerConfig, TransportRpcModuleConfig}; -use reth_staged_sync::{utils::init::init_genesis, Config}; +use reth_staged_sync::{ + utils::{ + chainspec::genesis_value_parser, + init::{init_db, init_genesis}, + parse_socket_address, + }, + Config, +}; use reth_stages::{ prelude::*, stages::{ExecutionStage, SenderRecoveryStage, TotalDifficultyStage}, @@ -77,7 +83,7 @@ pub struct Command { metrics: Option, #[clap(flatten)] - network: NetworkOpts, + network: NetworkArgs, #[arg(long, default_value = "any")] nat: NatResolver, @@ -93,7 +99,7 @@ pub struct Command { max_block: Option, #[clap(flatten)] - rpc: RpcServerOpts, + rpc: RpcServerArgs, } impl Command { diff --git a/bin/reth/src/p2p/mod.rs b/bin/reth/src/p2p/mod.rs index 1dedc3c13..5aec2f9a8 100644 --- a/bin/reth/src/p2p/mod.rs +++ b/bin/reth/src/p2p/mod.rs @@ -1,8 +1,5 @@ //! P2P Debugging tool -use crate::{ - dirs::{ConfigPath, PlatformPath}, - utils::{chainspec::chain_spec_value_parser, hash_or_num_value_parser}, -}; +use crate::dirs::{ConfigPath, PlatformPath}; use backon::{ConstantBackoff, Retryable}; use clap::{Parser, Subcommand}; use reth_db::mdbx::{Env, EnvKind, WriteMap}; @@ -13,7 +10,10 @@ use reth_interfaces::p2p::{ }; use reth_network::FetchClient; use reth_primitives::{BlockHashOrNumber, ChainSpec, NodeRecord, SealedHeader}; -use reth_staged_sync::Config; +use reth_staged_sync::{ + utils::{chainspec::chain_spec_value_parser, hash_or_num_value_parser}, + Config, +}; use std::sync::Arc; /// `reth p2p` command diff --git a/bin/reth/src/stage/mod.rs b/bin/reth/src/stage/mod.rs index 864602106..aeca6717a 100644 --- a/bin/reth/src/stage/mod.rs +++ b/bin/reth/src/stage/mod.rs @@ -2,17 +2,18 @@ //! //! Stage debugging tool use crate::{ + args::NetworkArgs, dirs::{ConfigPath, DbPath, PlatformPath}, prometheus_exporter, - utils::{chainspec::chain_spec_value_parser, init::init_db}, - NetworkOpts, }; use reth_consensus::beacon::BeaconConsensus; use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder; - use reth_net_nat::NatResolver; use reth_primitives::ChainSpec; -use reth_staged_sync::Config; +use reth_staged_sync::{ + utils::{chainspec::chain_spec_value_parser, init::init_db}, + Config, +}; use reth_stages::{ stages::{BodyStage, ExecutionStage, SenderRecoveryStage}, ExecInput, Stage, StageId, Transaction, UnwindInput, @@ -83,7 +84,7 @@ pub struct Command { skip_unwind: bool, #[clap(flatten)] - network: NetworkOpts, + network: NetworkArgs, #[arg(long, default_value = "any")] nat: NatResolver,