diff --git a/substrate/client/cli/src/arg_enums.rs b/substrate/client/cli/src/arg_enums.rs index 249e3c639e..a5403e3497 100644 --- a/substrate/client/cli/src/arg_enums.rs +++ b/substrate/client/cli/src/arg_enums.rs @@ -15,8 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -// NOTE: we allow missing docs here because arg_enum! creates the function variants without doc -#![allow(missing_docs)] + +//! Definitions of [`ArgEnum`] types. use clap::ArgEnum; @@ -90,6 +90,7 @@ impl Into for WasmExecutionMethod { #[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)] #[clap(rename_all = "PascalCase")] pub enum TracingReceiver { + /// Output the tracing records using the log. Log, } @@ -101,25 +102,33 @@ impl Into for TracingReceiver { } } -#[allow(missing_docs)] +/// The type of the node key. #[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)] #[clap(rename_all = "PascalCase")] pub enum NodeKeyType { + /// Use ed25519. Ed25519, } +/// The crypto scheme to use. #[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)] #[clap(rename_all = "PascalCase")] pub enum CryptoScheme { + /// Use ed25519. Ed25519, + /// Use sr25519. Sr25519, + /// Use Ecdsa, } +/// The type of the output format. #[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)] #[clap(rename_all = "PascalCase")] pub enum OutputType { + /// Output as json. Json, + /// Output as text. Text, } @@ -127,13 +136,13 @@ pub enum OutputType { #[derive(Debug, Copy, Clone, PartialEq, Eq, ArgEnum)] #[clap(rename_all = "PascalCase")] pub enum ExecutionStrategy { - // Execute with native build (if available, WebAssembly otherwise). + /// Execute with native build (if available, WebAssembly otherwise). Native, - // Only execute with the WebAssembly build. + /// Only execute with the WebAssembly build. Wasm, - // Execute with both native (where available) and WebAssembly builds. + /// Execute with both native (where available) and WebAssembly builds. Both, - // Execute with the native build if possible; if it fails, then execute with WebAssembly. + /// Execute with the native build if possible; if it fails, then execute with WebAssembly. NativeElseWasm, } @@ -165,12 +174,12 @@ impl ExecutionStrategy { #[derive(Debug, Copy, Clone, PartialEq, ArgEnum)] #[clap(rename_all = "PascalCase")] pub enum RpcMethods { - // Expose every RPC method only when RPC is listening on `localhost`, - // otherwise serve only safe RPC methods. + /// Expose every RPC method only when RPC is listening on `localhost`, + /// otherwise serve only safe RPC methods. Auto, - // Allow only a safe subset of RPC methods. + /// Allow only a safe subset of RPC methods. Safe, - // Expose every RPC method (even potentially unsafe ones). + /// Expose every RPC method (even potentially unsafe ones). Unsafe, } @@ -224,22 +233,25 @@ impl Database { #[derive(Debug, Clone, ArgEnum)] #[clap(rename_all = "PascalCase")] pub enum OffchainWorkerEnabled { + /// Always have offchain worker enabled. Always, + /// Never enable the offchain worker. Never, + /// Only enable the offchain worker when running as validator. WhenValidating, } /// Syncing mode. -#[derive(Debug, Clone, Copy, ArgEnum)] +#[derive(Debug, Clone, Copy, ArgEnum, PartialEq)] #[clap(rename_all = "PascalCase")] pub enum SyncMode { - // Full sync. Donwnload end verify all blocks. + /// Full sync. Download end verify all blocks. Full, - // Download blocks without executing them. Download latest state with proofs. + /// Download blocks without executing them. Download latest state with proofs. Fast, - // Download blocks without executing them. Download latest state without proofs. + /// Download blocks without executing them. Download latest state without proofs. FastUnsafe, - // Prove finality and download the latest state. + /// Prove finality and download the latest state. Warp, } diff --git a/substrate/client/cli/src/params/network_params.rs b/substrate/client/cli/src/params/network_params.rs index 1de2896cba..7a265c5e27 100644 --- a/substrate/client/cli/src/params/network_params.rs +++ b/substrate/client/cli/src/params/network_params.rs @@ -34,11 +34,11 @@ use std::{borrow::Cow, path::PathBuf}; #[derive(Debug, Clone, Args)] pub struct NetworkParams { /// Specify a list of bootnodes. - #[clap(long, value_name = "ADDR")] + #[clap(long, value_name = "ADDR", multiple_values(true))] pub bootnodes: Vec, /// Specify a list of reserved node addresses. - #[clap(long, value_name = "ADDR")] + #[clap(long, value_name = "ADDR", multiple_values(true))] pub reserved_nodes: Vec, /// Whether to only synchronize the chain with reserved nodes. @@ -54,7 +54,7 @@ pub struct NetworkParams { /// The public address that other nodes will use to connect to it. /// This can be used if there's a proxy in front of this node. - #[clap(long, value_name = "PUBLIC_ADDR")] + #[clap(long, value_name = "PUBLIC_ADDR", multiple_values(true))] pub public_addr: Vec, /// Listen on this multiaddress. @@ -62,7 +62,7 @@ pub struct NetworkParams { /// By default: /// If `--validator` is passed: `/ip4/0.0.0.0/tcp/` and `/ip6/[::]/tcp/`. /// Otherwise: `/ip4/0.0.0.0/tcp//ws` and `/ip6/[::]/tcp//ws`. - #[clap(long, value_name = "LISTEN_ADDR")] + #[clap(long, value_name = "LISTEN_ADDR", multiple_values(true))] pub listen_addr: Vec, /// Specify p2p protocol TCP port. @@ -137,7 +137,7 @@ pub struct NetworkParams { /// - `Fast`: Download blocks and the latest state only. /// /// - `FastUnsafe`: Same as `Fast`, but skip downloading state proofs. - #[clap(long, arg_enum, value_name = "SYNC_MODE", default_value = "Full")] + #[clap(long, arg_enum, value_name = "SYNC_MODE", default_value = "Full", ignore_case(true))] pub sync: SyncMode, } @@ -237,3 +237,55 @@ impl NetworkParams { } } } + +#[cfg(test)] +mod tests { + use super::*; + use clap::Parser; + + #[derive(Parser)] + struct Cli { + #[clap(flatten)] + network_params: NetworkParams, + } + + #[test] + fn reserved_nodes_multiple_values_and_occurrences() { + let params = Cli::try_parse_from([ + "", + "--reserved-nodes", + "/ip4/0.0.0.0/tcp/501/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS", + "/ip4/0.0.0.0/tcp/502/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS", + "--reserved-nodes", + "/ip4/0.0.0.0/tcp/503/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS", + ]) + .expect("Parses network params"); + + let expected = vec![ + MultiaddrWithPeerId::try_from( + "/ip4/0.0.0.0/tcp/501/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS" + .to_string(), + ) + .unwrap(), + MultiaddrWithPeerId::try_from( + "/ip4/0.0.0.0/tcp/502/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS" + .to_string(), + ) + .unwrap(), + MultiaddrWithPeerId::try_from( + "/ip4/0.0.0.0/tcp/503/p2p/12D3KooWEBo1HUPQJwiBmM5kSeg4XgiVxEArArQdDarYEsGxMfbS" + .to_string(), + ) + .unwrap(), + ]; + + assert_eq!(expected, params.network_params.reserved_nodes); + } + + #[test] + fn sync_ingores_case() { + let params = Cli::try_parse_from(["", "--sync", "wArP"]).expect("Parses network params"); + + assert_eq!(SyncMode::Warp, params.network_params.sync); + } +} diff --git a/substrate/client/cli/src/params/shared_params.rs b/substrate/client/cli/src/params/shared_params.rs index a4f2271e12..4066a75a93 100644 --- a/substrate/client/cli/src/params/shared_params.rs +++ b/substrate/client/cli/src/params/shared_params.rs @@ -46,7 +46,7 @@ pub struct SharedParams { /// /// Log levels (least to most verbose) are error, warn, info, debug, and trace. /// By default, all targets log `info`. The global log level can be set with -l. - #[clap(short = 'l', long, value_name = "LOG_PATTERN")] + #[clap(short = 'l', long, value_name = "LOG_PATTERN", multiple_values(true))] pub log: Vec, /// Enable detailed log output. diff --git a/substrate/client/network/src/config.rs b/substrate/client/network/src/config.rs index 3b9c864c37..a7e4e5cc87 100644 --- a/substrate/client/network/src/config.rs +++ b/substrate/client/network/src/config.rs @@ -295,7 +295,7 @@ pub fn parse_addr(mut addr: Multiaddr) -> Result<(PeerId, Multiaddr), ParseErr> /// assert_eq!(addr.peer_id.to_base58(), "QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV"); /// assert_eq!(addr.multiaddr.to_string(), "/ip4/198.51.100.19/tcp/30333"); /// ``` -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)] #[serde(try_from = "String", into = "String")] pub struct MultiaddrWithPeerId { /// Address of the node.