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