From e06e8b90a017dd69fc7300fad610e8a4ecc5730b Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 16 Apr 2020 13:12:54 +0200 Subject: [PATCH 1/5] Make network_config_path an Option --- client/network/src/config.rs | 10 +++++----- client/network/src/service.rs | 4 +++- utils/browser/src/lib.rs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/client/network/src/config.rs b/client/network/src/config.rs index 01acbe68755be..89a0b6a06fe64 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -315,7 +315,7 @@ impl From for ParseErr { #[derive(Clone, Debug)] pub struct NetworkConfiguration { /// Directory path to store network-specific configuration. None means nothing will be saved. - pub net_config_path: PathBuf, + pub net_config_path: Option, /// Multiaddresses to listen for incoming connections. pub listen_addresses: Vec, /// Multiaddresses to advertise. Detected automatically if empty. @@ -351,10 +351,10 @@ impl NetworkConfiguration { node_name: SN, client_version: SV, node_key: NodeKeyConfig, - net_config_path: &PathBuf, + net_config_path: Option, ) -> Self { NetworkConfiguration { - net_config_path: net_config_path.clone(), + net_config_path, listen_addresses: Vec::new(), public_addresses: Vec::new(), boot_nodes: Vec::new(), @@ -384,7 +384,7 @@ impl NetworkConfiguration { "test-node", "test-client", Default::default(), - &std::env::current_dir().expect("current directory must exist"), + Some(std::env::current_dir().expect("current directory must exist")), ); config.listen_addresses = vec![ @@ -402,7 +402,7 @@ impl NetworkConfiguration { "test-node", "test-client", Default::default(), - &std::env::current_dir().expect("current directory must exist"), + Some(std::env::current_dir().expect("current directory must exist")), ); config.listen_addresses = vec![ diff --git a/client/network/src/service.rs b/client/network/src/service.rs index 642f67d14aa89..2d967dcd361b0 100644 --- a/client/network/src/service.rs +++ b/client/network/src/service.rs @@ -184,7 +184,9 @@ impl NetworkWorker { pub fn new(params: Params) -> Result, Error> { let (to_worker, from_worker) = tracing_unbounded("mpsc_network_worker"); - fs::create_dir_all(¶ms.network_config.net_config_path)?; + if let Some(path) = params.network_config.net_config_path { + fs::create_dir_all(&path)?; + } // List of multiaddresses that we know in the network. let mut known_addresses = Vec::new(); diff --git a/utils/browser/src/lib.rs b/utils/browser/src/lib.rs index 35b1bc99c4501..0c5f0f320f1f3 100644 --- a/utils/browser/src/lib.rs +++ b/utils/browser/src/lib.rs @@ -49,7 +49,7 @@ where format!("{} (Browser)", name), "unknown", Default::default(), - &std::path::PathBuf::new(), + None, ); network.boot_nodes = chain_spec.boot_nodes().to_vec(); network.transport = TransportConfig::Normal { From e5a69fd38f2eff9cb9495c3881c2c9bfbcea4455 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 16 Apr 2020 13:58:03 +0200 Subject: [PATCH 2/5] Fix network tests --- client/network/test/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index ae129871db95e..123ae7857baef 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -607,7 +607,7 @@ pub trait TestNetFactory: Sized { "test-node", "test-client", Default::default(), - &std::env::current_dir().expect("current directory must exist"), + Some(std::env::current_dir().expect("current directory must exist")), ); network_config.transport = TransportConfig::MemoryOnly; network_config.listen_addresses = vec![listen_addr.clone()]; @@ -683,7 +683,7 @@ pub trait TestNetFactory: Sized { "test-node", "test-client", Default::default(), - &std::env::current_dir().expect("current directory must exist"), + Some(std::env::current_dir().expect("current directory must exist")), ); network_config.transport = TransportConfig::MemoryOnly; network_config.listen_addresses = vec![listen_addr.clone()]; From a749ba80f5541909021c1490bc6c74e498aa31b0 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 16 Apr 2020 15:25:46 +0200 Subject: [PATCH 3/5] Use None as the network config path --- client/network/src/config.rs | 4 ++-- client/network/test/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/network/src/config.rs b/client/network/src/config.rs index 89a0b6a06fe64..4914ad680a45f 100644 --- a/client/network/src/config.rs +++ b/client/network/src/config.rs @@ -384,7 +384,7 @@ impl NetworkConfiguration { "test-node", "test-client", Default::default(), - Some(std::env::current_dir().expect("current directory must exist")), + None, ); config.listen_addresses = vec![ @@ -402,7 +402,7 @@ impl NetworkConfiguration { "test-node", "test-client", Default::default(), - Some(std::env::current_dir().expect("current directory must exist")), + None, ); config.listen_addresses = vec![ diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index 123ae7857baef..7b070f8041220 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -607,7 +607,7 @@ pub trait TestNetFactory: Sized { "test-node", "test-client", Default::default(), - Some(std::env::current_dir().expect("current directory must exist")), + None, ); network_config.transport = TransportConfig::MemoryOnly; network_config.listen_addresses = vec![listen_addr.clone()]; @@ -683,7 +683,7 @@ pub trait TestNetFactory: Sized { "test-node", "test-client", Default::default(), - Some(std::env::current_dir().expect("current directory must exist")), + None, ); network_config.transport = TransportConfig::MemoryOnly; network_config.listen_addresses = vec![listen_addr.clone()]; From f5b740e49afde7a29c6fb45c87d1e5e3501016c1 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Thu, 16 Apr 2020 18:30:42 +0200 Subject: [PATCH 4/5] Fix cli --- client/cli/src/commands/mod.rs | 2 +- client/cli/src/config.rs | 4 ++-- client/cli/src/params/network_params.rs | 4 ++-- client/service/test/src/lib.rs | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 68c22c4868565..1c57b75b2ac84 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -173,7 +173,7 @@ macro_rules! substrate_cli_subcommands { &self, chain_spec: &::std::boxed::Box, is_dev: bool, - net_config_dir: &::std::path::PathBuf, + net_config_dir: Option<::std::path::PathBuf>, client_id: &str, node_name: &str, node_key: ::sc_service::config::NodeKeyConfig, diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index 8c8490ff1a2b2..943f952586bb9 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -110,7 +110,7 @@ pub trait CliConfiguration: Sized { &self, chain_spec: &Box, is_dev: bool, - net_config_dir: &PathBuf, + net_config_dir: Option, client_id: &str, node_name: &str, node_key: NodeKeyConfig, @@ -405,7 +405,7 @@ pub trait CliConfiguration: Sized { network: self.network_config( &chain_spec, is_dev, - &net_config_dir, + Some(net_config_dir), client_id.as_str(), self.node_name()?.as_str(), node_key, diff --git a/client/cli/src/params/network_params.rs b/client/cli/src/params/network_params.rs index 21e44f9782286..bd7b6a4af3d93 100644 --- a/client/cli/src/params/network_params.rs +++ b/client/cli/src/params/network_params.rs @@ -100,7 +100,7 @@ impl NetworkParams { &self, chain_spec: &Box, is_dev: bool, - net_config_path: &PathBuf, + net_config_path: Option, client_id: &str, node_name: &str, node_key: NodeKeyConfig, @@ -117,7 +117,7 @@ impl NetworkParams { NetworkConfiguration { boot_nodes, - net_config_path: net_config_path.clone(), + net_config_path, reserved_nodes: self.reserved_nodes.clone(), non_reserved_mode: if self.reserved_only { NonReservedPeerMode::Deny diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index a53201465880c..1e824cb2734db 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -143,12 +143,11 @@ fn node_config Date: Fri, 17 Apr 2020 13:51:29 +0200 Subject: [PATCH 5/5] Don't make PathBuf an Option in a cli context --- client/cli/src/commands/mod.rs | 2 +- client/cli/src/config.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 1c57b75b2ac84..ae2fe55467598 100644 --- a/client/cli/src/commands/mod.rs +++ b/client/cli/src/commands/mod.rs @@ -173,7 +173,7 @@ macro_rules! substrate_cli_subcommands { &self, chain_spec: &::std::boxed::Box, is_dev: bool, - net_config_dir: Option<::std::path::PathBuf>, + net_config_dir: ::std::path::PathBuf, client_id: &str, node_name: &str, node_key: ::sc_service::config::NodeKeyConfig, diff --git a/client/cli/src/config.rs b/client/cli/src/config.rs index 943f952586bb9..04a664740284e 100644 --- a/client/cli/src/config.rs +++ b/client/cli/src/config.rs @@ -110,7 +110,7 @@ pub trait CliConfiguration: Sized { &self, chain_spec: &Box, is_dev: bool, - net_config_dir: Option, + net_config_dir: PathBuf, client_id: &str, node_name: &str, node_key: NodeKeyConfig, @@ -119,7 +119,7 @@ pub trait CliConfiguration: Sized { network_params.network_config( chain_spec, is_dev, - net_config_dir, + Some(net_config_dir), client_id, node_name, node_key, @@ -129,7 +129,7 @@ pub trait CliConfiguration: Sized { node_name, client_id, node_key, - net_config_dir, + Some(net_config_dir), ) }) } @@ -405,7 +405,7 @@ pub trait CliConfiguration: Sized { network: self.network_config( &chain_spec, is_dev, - Some(net_config_dir), + net_config_dir, client_id.as_str(), self.node_name()?.as_str(), node_key,