From 95dc400bb88040aca74fea893cf461dbb67ddece Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 17 Apr 2020 14:48:45 +0200 Subject: [PATCH] Make network_config_path an Option (#5661) * Make network_config_path an Option * Fix network tests * Use None as the network config path * Fix cli * Don't make PathBuf an Option in a cli context --- substrate/client/cli/src/commands/mod.rs | 2 +- substrate/client/cli/src/config.rs | 8 ++++---- substrate/client/cli/src/params/network_params.rs | 4 ++-- substrate/client/network/src/config.rs | 10 +++++----- substrate/client/network/src/service.rs | 4 +++- substrate/client/network/test/src/lib.rs | 4 ++-- substrate/client/service/test/src/lib.rs | 5 ++--- substrate/utils/browser/src/lib.rs | 2 +- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/substrate/client/cli/src/commands/mod.rs b/substrate/client/cli/src/commands/mod.rs index 68c22c4868..ae2fe55467 100644 --- a/substrate/client/cli/src/commands/mod.rs +++ b/substrate/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: ::std::path::PathBuf, client_id: &str, node_name: &str, node_key: ::sc_service::config::NodeKeyConfig, diff --git a/substrate/client/cli/src/config.rs b/substrate/client/cli/src/config.rs index 8c8490ff1a..04a6647402 100644 --- a/substrate/client/cli/src/config.rs +++ b/substrate/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: 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, - &net_config_dir, + net_config_dir, client_id.as_str(), self.node_name()?.as_str(), node_key, diff --git a/substrate/client/cli/src/params/network_params.rs b/substrate/client/cli/src/params/network_params.rs index 6d9ffd6a6e..45500a5e06 100644 --- a/substrate/client/cli/src/params/network_params.rs +++ b/substrate/client/cli/src/params/network_params.rs @@ -96,7 +96,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, @@ -121,7 +121,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/substrate/client/network/src/config.rs b/substrate/client/network/src/config.rs index 01acbe6875..4914ad680a 100644 --- a/substrate/client/network/src/config.rs +++ b/substrate/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"), + None, ); 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"), + None, ); config.listen_addresses = vec![ diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index da488d2a87..091c75d635 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/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/substrate/client/network/test/src/lib.rs b/substrate/client/network/test/src/lib.rs index ae129871db..7b070f8041 100644 --- a/substrate/client/network/test/src/lib.rs +++ b/substrate/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"), + 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(), - &std::env::current_dir().expect("current directory must exist"), + None, ); network_config.transport = TransportConfig::MemoryOnly; network_config.listen_addresses = vec![listen_addr.clone()]; diff --git a/substrate/client/service/test/src/lib.rs b/substrate/client/service/test/src/lib.rs index a532014658..1e824cb273 100644 --- a/substrate/client/service/test/src/lib.rs +++ b/substrate/client/service/test/src/lib.rs @@ -143,12 +143,11 @@ fn node_config