use clap3 instead of structopt (#10632)

* use clap3 instead of structopt

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* format

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* update ss58-registry and revert some nits

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix clippy and doc

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* update clap to 3.0.7

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Apply review suggestions

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* remove useless option long name

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* cargo fmt

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
Qinxuan Chen
2022-01-25 00:28:46 +08:00
committed by GitHub
parent d1ff02d31e
commit e327b734bc
66 changed files with 660 additions and 768 deletions
@@ -17,6 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::{arg_enums::SyncMode, params::node_key_params::NodeKeyParams};
use clap::Args;
use sc_network::{
config::{
NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, SetConfig, TransportConfig,
@@ -28,17 +29,16 @@ use sc_service::{
ChainSpec, ChainType,
};
use std::{borrow::Cow, path::PathBuf};
use structopt::StructOpt;
/// Parameters used to create the network configuration.
#[derive(Debug, StructOpt, Clone)]
#[derive(Debug, Clone, Args)]
pub struct NetworkParams {
/// Specify a list of bootnodes.
#[structopt(long = "bootnodes", value_name = "ADDR")]
#[clap(long, value_name = "ADDR")]
pub bootnodes: Vec<MultiaddrWithPeerId>,
/// Specify a list of reserved node addresses.
#[structopt(long = "reserved-nodes", value_name = "ADDR")]
#[clap(long, value_name = "ADDR")]
pub reserved_nodes: Vec<MultiaddrWithPeerId>,
/// Whether to only synchronize the chain with reserved nodes.
@@ -49,12 +49,12 @@ pub struct NetworkParams {
/// In particular, if you are a validator your node might still connect to other
/// validator nodes and collator nodes regardless of whether they are defined as
/// reserved nodes.
#[structopt(long = "reserved-only")]
#[clap(long)]
pub reserved_only: bool,
/// 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.
#[structopt(long, value_name = "PUBLIC_ADDR")]
#[clap(long, value_name = "PUBLIC_ADDR")]
pub public_addr: Vec<Multiaddr>,
/// Listen on this multiaddress.
@@ -62,60 +62,60 @@ pub struct NetworkParams {
/// By default:
/// If `--validator` is passed: `/ip4/0.0.0.0/tcp/<port>` and `/ip6/[::]/tcp/<port>`.
/// Otherwise: `/ip4/0.0.0.0/tcp/<port>/ws` and `/ip6/[::]/tcp/<port>/ws`.
#[structopt(long = "listen-addr", value_name = "LISTEN_ADDR")]
#[clap(long, value_name = "LISTEN_ADDR")]
pub listen_addr: Vec<Multiaddr>,
/// Specify p2p protocol TCP port.
#[structopt(long = "port", value_name = "PORT", conflicts_with_all = &[ "listen-addr" ])]
#[clap(long, value_name = "PORT", conflicts_with_all = &[ "listen-addr" ])]
pub port: Option<u16>,
/// Always forbid connecting to private IPv4 addresses (as specified in
/// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with
/// `--reserved-nodes` or `--bootnodes`. Enabled by default for chains marked as "live" in
/// their chain specifications.
#[structopt(long = "no-private-ipv4", conflicts_with_all = &["allow-private-ipv4"])]
#[clap(long, conflicts_with_all = &["allow-private-ipv4"])]
pub no_private_ipv4: bool,
/// Always accept connecting to private IPv4 addresses (as specified in
/// [RFC1918](https://tools.ietf.org/html/rfc1918)). Enabled by default for chains marked as
/// "local" in their chain specifications, or when `--dev` is passed.
#[structopt(long = "allow-private-ipv4", conflicts_with_all = &["no-private-ipv4"])]
#[clap(long, conflicts_with_all = &["no-private-ipv4"])]
pub allow_private_ipv4: bool,
/// Specify the number of outgoing connections we're trying to maintain.
#[structopt(long = "out-peers", value_name = "COUNT", default_value = "25")]
#[clap(long, value_name = "COUNT", default_value = "25")]
pub out_peers: u32,
/// Maximum number of inbound full nodes peers.
#[structopt(long = "in-peers", value_name = "COUNT", default_value = "25")]
#[clap(long, value_name = "COUNT", default_value = "25")]
pub in_peers: u32,
/// Maximum number of inbound light nodes peers.
#[structopt(long = "in-peers-light", value_name = "COUNT", default_value = "100")]
#[clap(long, value_name = "COUNT", default_value = "100")]
pub in_peers_light: u32,
/// Disable mDNS discovery.
///
/// By default, the network will use mDNS to discover other nodes on the
/// local network. This disables it. Automatically implied when using --dev.
#[structopt(long = "no-mdns")]
#[clap(long)]
pub no_mdns: bool,
/// Maximum number of peers from which to ask for the same blocks in parallel.
///
/// This allows downloading announced blocks from multiple peers. Decrease to save
/// traffic and risk increased latency.
#[structopt(long = "max-parallel-downloads", value_name = "COUNT", default_value = "5")]
#[clap(long, value_name = "COUNT", default_value = "5")]
pub max_parallel_downloads: u32,
#[allow(missing_docs)]
#[structopt(flatten)]
#[clap(flatten)]
pub node_key_params: NodeKeyParams,
/// Enable peer discovery on local networks.
///
/// By default this option is `true` for `--dev` or when the chain type is
/// `Local`/`Development` and false otherwise.
#[structopt(long)]
#[clap(long)]
pub discover_local: bool,
/// Require iterative Kademlia DHT queries to use disjoint paths for increased resiliency in
@@ -123,11 +123,11 @@ pub struct NetworkParams {
///
/// See the S/Kademlia paper for more information on the high level design as well as its
/// security improvements.
#[structopt(long)]
#[clap(long)]
pub kademlia_disjoint_query_paths: bool,
/// Join the IPFS network and serve transactions over bitswap protocol.
#[structopt(long)]
#[clap(long)]
pub ipfs_server: bool,
/// Blockchain syncing mode.
@@ -137,7 +137,7 @@ pub struct NetworkParams {
/// - `Fast`: Download blocks and the latest state only.
///
/// - `FastUnsafe`: Same as `Fast`, but skip downloading state proofs.
#[structopt(long, value_name = "SYNC_MODE", default_value = "Full")]
#[clap(long, arg_enum, value_name = "SYNC_MODE", default_value = "Full")]
pub sync: SyncMode,
}