Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make non-validators listen on /ws by default #8609

Merged
3 commits merged into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
&self,
chain_spec: &Box<dyn ChainSpec>,
is_dev: bool,
is_validator: bool,
net_config_dir: PathBuf,
client_id: &str,
node_name: &str,
Expand All @@ -169,6 +170,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
network_params.network_config(
chain_spec,
is_dev,
is_validator,
Some(net_config_dir),
client_id,
node_name,
Expand Down Expand Up @@ -501,6 +503,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
network: self.network_config(
&chain_spec,
is_dev,
is_validator,
net_config_dir,
client_id.as_str(),
self.node_name()?.as_str(),
Expand Down
36 changes: 27 additions & 9 deletions client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -53,6 +53,10 @@ pub struct NetworkParams {
pub public_addr: Vec<Multiaddr>,

/// Listen on this multiaddress.
///
/// 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")]
pub listen_addr: Vec<Multiaddr>,

Expand Down Expand Up @@ -122,6 +126,7 @@ impl NetworkParams {
&self,
chain_spec: &Box<dyn ChainSpec>,
is_dev: bool,
is_validator: bool,
net_config_path: Option<PathBuf>,
client_id: &str,
node_name: &str,
Expand All @@ -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()
};
Expand Down