diff --git a/substrate/client/cli/src/config.rs b/substrate/client/cli/src/config.rs index 289d6dc7cc..a21a79afe9 100644 --- a/substrate/client/cli/src/config.rs +++ b/substrate/client/cli/src/config.rs @@ -159,6 +159,7 @@ pub trait CliConfiguration: Sized { &self, chain_spec: &Box, is_dev: bool, + is_validator: bool, net_config_dir: PathBuf, client_id: &str, node_name: &str, @@ -169,6 +170,7 @@ pub trait CliConfiguration: Sized { network_params.network_config( chain_spec, is_dev, + is_validator, Some(net_config_dir), client_id, node_name, @@ -501,6 +503,7 @@ pub trait CliConfiguration: Sized { network: self.network_config( &chain_spec, is_dev, + is_validator, net_config_dir, client_id.as_str(), self.node_name()?.as_str(), diff --git a/substrate/client/cli/src/params/network_params.rs b/substrate/client/cli/src/params/network_params.rs index f4a6e8d398..24245cd57a 100644 --- a/substrate/client/cli/src/params/network_params.rs +++ b/substrate/client/cli/src/params/network_params.rs @@ -22,7 +22,7 @@ use sc_network::{ multiaddr::Protocol, }; use sc_service::{ChainSpec, ChainType, config::{Multiaddr, MultiaddrWithPeerId}}; -use std::path::PathBuf; +use std::{borrow::Cow, path::PathBuf}; use structopt::StructOpt; /// Parameters used to create the network configuration. @@ -53,6 +53,10 @@ pub struct NetworkParams { pub public_addr: Vec, /// Listen on this multiaddress. + /// + /// 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`. #[structopt(long = "listen-addr", value_name = "LISTEN_ADDR")] pub listen_addr: Vec, @@ -122,6 +126,7 @@ impl NetworkParams { &self, chain_spec: &Box, is_dev: bool, + is_validator: bool, net_config_path: Option, client_id: &str, node_name: &str, @@ -131,14 +136,27 @@ impl NetworkParams { let port = self.port.unwrap_or(default_listen_port); let listen_addresses = if self.listen_addr.is_empty() { - vec![ - Multiaddr::empty() - .with(Protocol::Ip6([0, 0, 0, 0, 0, 0, 0, 0].into())) - .with(Protocol::Tcp(port)), - Multiaddr::empty() - .with(Protocol::Ip4([0, 0, 0, 0].into())) - .with(Protocol::Tcp(port)), - ] + if is_validator { + vec![ + Multiaddr::empty() + .with(Protocol::Ip6([0, 0, 0, 0, 0, 0, 0, 0].into())) + .with(Protocol::Tcp(port)), + Multiaddr::empty() + .with(Protocol::Ip4([0, 0, 0, 0].into())) + .with(Protocol::Tcp(port)), + ] + } else { + vec![ + Multiaddr::empty() + .with(Protocol::Ip6([0, 0, 0, 0, 0, 0, 0, 0].into())) + .with(Protocol::Tcp(port)) + .with(Protocol::Ws(Cow::Borrowed("/"))), + Multiaddr::empty() + .with(Protocol::Ip4([0, 0, 0, 0].into())) + .with(Protocol::Tcp(port)) + .with(Protocol::Ws(Cow::Borrowed("/"))), + ] + } } else { self.listen_addr.clone() };