chore: rename command to NodeCommand and make fields pub (#4080)

This commit is contained in:
Matthias Seitz
2023-08-05 16:57:12 +02:00
committed by GitHub
parent cac4049a08
commit c0abfcedff
3 changed files with 39 additions and 31 deletions

View File

@ -96,7 +96,7 @@ pub trait RethNodeCommandExt: fmt::Debug + clap::Args {
// TODO move network related functions here
}
/// The default configuration for the reth node command [Command](crate::node::Command).
/// The default configuration for the reth node command [Command](crate::node::NodeCommand).
#[derive(Debug, Clone, Copy, Default, Args)]
pub struct DefaultRethNodeCommandConfig;

View File

@ -107,7 +107,7 @@ pub fn run() -> eyre::Result<()> {
pub enum Commands<Ext: RethCliExt = ()> {
/// Start the node
#[command(name = "node")]
Node(node::Command<Ext>),
Node(node::NodeCommand<Ext>),
/// Initialize the database from a genesis file.
#[command(name = "init")]
Init(chain::InitCommand),

View File

@ -22,7 +22,6 @@ use eyre::Context;
use fdlimit::raise_fd_limit;
use futures::{future::Either, pin_mut, stream, stream_select, StreamExt};
use reth_auto_seal_consensus::{AutoSealBuilder, AutoSealConsensus, MiningMode};
use reth_beacon_consensus::{BeaconConsensus, BeaconConsensusEngine, MIN_BLOCKS_FOR_PIPELINE_RUN};
use reth_blockchain_tree::{
config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, ShareableBlockchainTree,
@ -44,7 +43,6 @@ use reth_interfaces::{
};
use reth_network::{error::NetworkError, NetworkConfig, NetworkHandle, NetworkManager};
use reth_network_api::NetworkInfo;
use reth_primitives::{
stage::StageId, BlockHashOrNumber, BlockNumber, ChainSpec, DisplayHardforks, Head,
SealedHeader, H256,
@ -82,7 +80,7 @@ pub mod events;
/// Start the node
#[derive(Debug, Parser)]
pub struct Command<Ext: RethCliExt = ()> {
pub struct NodeCommand<Ext: RethCliExt = ()> {
/// The path to the data dir for all reth files and subdirectories.
///
/// Defaults to the OS-specific data directory:
@ -91,11 +89,11 @@ pub struct Command<Ext: RethCliExt = ()> {
/// - Windows: `{FOLDERID_RoamingAppData}/reth/`
/// - macOS: `$HOME/Library/Application Support/reth/`
#[arg(long, value_name = "DATA_DIR", verbatim_doc_comment, default_value_t)]
datadir: MaybePlatformPath<DataDirPath>,
pub datadir: MaybePlatformPath<DataDirPath>,
/// The path to the configuration file to use.
#[arg(long, value_name = "FILE", verbatim_doc_comment)]
config: Option<PathBuf>,
pub config: Option<PathBuf>,
/// The chain this node is running.
///
@ -115,44 +113,52 @@ pub struct Command<Ext: RethCliExt = ()> {
value_parser = genesis_value_parser,
required = false,
)]
chain: Arc<ChainSpec>,
pub chain: Arc<ChainSpec>,
/// Enable Prometheus metrics.
///
/// The metrics will be served at the given interface and port.
#[arg(long, value_name = "SOCKET", value_parser = parse_socket_address, help_heading = "Metrics")]
metrics: Option<SocketAddr>,
pub metrics: Option<SocketAddr>,
/// All networking related arguments
#[clap(flatten)]
network: NetworkArgs,
pub network: NetworkArgs,
/// All rpc related arguments
#[clap(flatten)]
rpc: RpcServerArgs,
pub rpc: RpcServerArgs,
/// All txpool related arguments with --txpool prefix
#[clap(flatten)]
txpool: TxPoolArgs,
pub txpool: TxPoolArgs,
/// All payload builder related arguments
#[clap(flatten)]
builder: PayloadBuilderArgs,
pub builder: PayloadBuilderArgs,
/// All debug related arguments with --debug prefix
#[clap(flatten)]
debug: DebugArgs,
pub debug: DebugArgs,
/// All database related arguments
#[clap(flatten)]
db: DatabaseArgs,
pub db: DatabaseArgs,
/// All dev related arguments with --dev prefix
#[clap(flatten)]
dev: DevArgs,
pub dev: DevArgs,
/// All pruning related arguments
#[clap(flatten)]
pruning: PruningArgs,
pub pruning: PruningArgs,
/// Additional cli arguments
#[clap(flatten)]
pub ext: Ext::Node,
}
impl<Ext: RethCliExt> Command<Ext> {
impl<Ext: RethCliExt> NodeCommand<Ext> {
/// Execute `node` command
pub async fn execute(self, ctx: CliContext) -> eyre::Result<()> {
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
@ -825,28 +831,28 @@ mod tests {
#[test]
fn parse_help_node_command() {
let err = Command::<()>::try_parse_from(["reth", "--help"]).unwrap_err();
let err = NodeCommand::<()>::try_parse_from(["reth", "--help"]).unwrap_err();
assert_eq!(err.kind(), clap::error::ErrorKind::DisplayHelp);
}
#[test]
fn parse_common_node_command_chain_args() {
for chain in ["mainnet", "sepolia", "goerli"] {
let args: Command = Command::<()>::parse_from(["reth", "--chain", chain]);
let args: NodeCommand = NodeCommand::<()>::parse_from(["reth", "--chain", chain]);
assert_eq!(args.chain.chain, chain.parse().unwrap());
}
}
#[test]
fn parse_discovery_port() {
let cmd = Command::<()>::try_parse_from(["reth", "--discovery.port", "300"]).unwrap();
let cmd = NodeCommand::<()>::try_parse_from(["reth", "--discovery.port", "300"]).unwrap();
assert_eq!(cmd.network.discovery.port, Some(300));
}
#[test]
fn parse_port() {
let cmd =
Command::<()>::try_parse_from(["reth", "--discovery.port", "300", "--port", "99"])
NodeCommand::<()>::try_parse_from(["reth", "--discovery.port", "300", "--port", "99"])
.unwrap();
assert_eq!(cmd.network.discovery.port, Some(300));
assert_eq!(cmd.network.port, Some(99));
@ -854,26 +860,27 @@ mod tests {
#[test]
fn parse_metrics_port() {
let cmd = Command::<()>::try_parse_from(["reth", "--metrics", "9001"]).unwrap();
let cmd = NodeCommand::<()>::try_parse_from(["reth", "--metrics", "9001"]).unwrap();
assert_eq!(cmd.metrics, Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9001)));
let cmd = Command::<()>::try_parse_from(["reth", "--metrics", ":9001"]).unwrap();
let cmd = NodeCommand::<()>::try_parse_from(["reth", "--metrics", ":9001"]).unwrap();
assert_eq!(cmd.metrics, Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9001)));
let cmd = Command::<()>::try_parse_from(["reth", "--metrics", "localhost:9001"]).unwrap();
let cmd =
NodeCommand::<()>::try_parse_from(["reth", "--metrics", "localhost:9001"]).unwrap();
assert_eq!(cmd.metrics, Some(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 9001)));
}
#[test]
fn parse_config_path() {
let cmd =
Command::<()>::try_parse_from(["reth", "--config", "my/path/to/reth.toml"]).unwrap();
let cmd = NodeCommand::<()>::try_parse_from(["reth", "--config", "my/path/to/reth.toml"])
.unwrap();
// always store reth.toml in the data dir, not the chain specific data dir
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let config_path = cmd.config.unwrap_or(data_dir.config_path());
assert_eq!(config_path, Path::new("my/path/to/reth.toml"));
let cmd = Command::<()>::try_parse_from(["reth"]).unwrap();
let cmd = NodeCommand::<()>::try_parse_from(["reth"]).unwrap();
// always store reth.toml in the data dir, not the chain specific data dir
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
@ -883,12 +890,13 @@ mod tests {
#[test]
fn parse_db_path() {
let cmd = Command::<()>::try_parse_from(["reth"]).unwrap();
let cmd = NodeCommand::<()>::try_parse_from(["reth"]).unwrap();
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let db_path = data_dir.db_path();
assert!(db_path.ends_with("reth/mainnet/db"), "{:?}", cmd.config);
let cmd = Command::<()>::try_parse_from(["reth", "--datadir", "my/custom/path"]).unwrap();
let cmd =
NodeCommand::<()>::try_parse_from(["reth", "--datadir", "my/custom/path"]).unwrap();
let data_dir = cmd.datadir.unwrap_or_chain_default(cmd.chain.chain);
let db_path = data_dir.db_path();
assert_eq!(db_path, Path::new("my/custom/path/db"));
@ -896,7 +904,7 @@ mod tests {
#[test]
fn parse_dev() {
let cmd = Command::<()>::parse_from(["reth", "--dev"]);
let cmd = NodeCommand::<()>::parse_from(["reth", "--dev"]);
let chain = DEV.clone();
assert_eq!(cmd.chain.chain, chain.chain);
assert_eq!(cmd.chain.genesis_hash, chain.genesis_hash);