diff --git a/client/cli/src/commands/mod.rs b/client/cli/src/commands/mod.rs index 68c22c4868565..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: &::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 8c8490ff1a2b2..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: &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/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/network/src/config.rs b/client/network/src/config.rs index 01acbe68755be..4914ad680a45f 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"), + 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/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/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index ae129871db95e..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(), - &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/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