Enable local addresses in DHT when chain type == Local | Development (#7538)

* Enable local addresses in DHT when chain type == `Local` | `Development`

This pr changes when to add local addresses to DHT. Instead of only
checking if `--discover-local` and `--dev` are present, we now also
check if the chain type is `Local` or `Development`.

* Update the docs!
This commit is contained in:
Bastian Köcher
2020-11-13 22:38:55 +01:00
committed by GitHub
parent f6466de3e7
commit 80830d2e1d
@@ -21,7 +21,7 @@ use sc_network::{
config::{NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, TransportConfig}, config::{NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, TransportConfig},
multiaddr::Protocol, multiaddr::Protocol,
}; };
use sc_service::{ChainSpec, config::{Multiaddr, MultiaddrWithPeerId}}; use sc_service::{ChainSpec, ChainType, config::{Multiaddr, MultiaddrWithPeerId}};
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt; use structopt::StructOpt;
@@ -94,7 +94,8 @@ pub struct NetworkParams {
/// Enable peer discovery on local networks. /// Enable peer discovery on local networks.
/// ///
/// By default this option is true for `--dev` and false otherwise. /// By default this option is `true` for `--dev` or when the chain type is `Local`/`Development`
/// and false otherwise.
#[structopt(long)] #[structopt(long)]
pub discover_local: bool, pub discover_local: bool,
@@ -139,6 +140,13 @@ impl NetworkParams {
let mut boot_nodes = chain_spec.boot_nodes().to_vec(); let mut boot_nodes = chain_spec.boot_nodes().to_vec();
boot_nodes.extend(self.bootnodes.clone()); boot_nodes.extend(self.bootnodes.clone());
let chain_type = chain_spec.chain_type();
// Activate if the user explicitly requested local discovery, `--dev` is given or the
// chain type is `Local`/`Development`
let allow_non_globals_in_dht = self.discover_local
|| is_dev
|| matches!(chain_type, ChainType::Local | ChainType::Development);
NetworkConfiguration { NetworkConfiguration {
boot_nodes, boot_nodes,
net_config_path, net_config_path,
@@ -163,7 +171,7 @@ impl NetworkParams {
wasm_external_transport: None, wasm_external_transport: None,
}, },
max_parallel_downloads: self.max_parallel_downloads, max_parallel_downloads: self.max_parallel_downloads,
allow_non_globals_in_dht: self.discover_local || is_dev, allow_non_globals_in_dht,
kademlia_disjoint_query_paths: self.kademlia_disjoint_query_paths, kademlia_disjoint_query_paths: self.kademlia_disjoint_query_paths,
} }
} }