diff --git a/gui/src/installer/step/mod.rs b/gui/src/installer/step/mod.rs index 5b98bd40d..e90a08b30 100644 --- a/gui/src/installer/step/mod.rs +++ b/gui/src/installer/step/mod.rs @@ -68,7 +68,7 @@ pub struct DefineBitcoind { } pub struct StartInternalBitcoindStep { - conf_path: PathBuf, + bitcoind_datadir: PathBuf, network: Network, started: Option>, exe_path: Option, @@ -92,7 +92,6 @@ pub struct InternalBitcoindNetworkConfig { pub struct InternalBitcoindConfig { #[cfg(unix)] daemonwait: bool, // Used instead of `daemon` to ensure RPC server is running before exiting. - data_dir: PathBuf, networks: HashMap, } @@ -119,12 +118,17 @@ impl std::fmt::Display for InternalBitcoindConfigError { } } +impl Default for InternalBitcoindConfig { + fn default() -> Self { + Self::new() + } +} + impl InternalBitcoindConfig { - pub fn new(data_dir: PathBuf) -> Self { + pub fn new() -> Self { Self { #[cfg(unix)] daemonwait: true, - data_dir, networks: HashMap::new(), } } @@ -140,12 +144,6 @@ impl InternalBitcoindConfig { .get("daemonwait") .map(|v| v == "1") .ok_or_else(|| InternalBitcoindConfigError::KeyNotFound("daemonwait".to_string()))?; - let data_dir = PathBuf::from_str( - gen_sec - .get("datadir") - .ok_or_else(|| InternalBitcoindConfigError::KeyNotFound("datadir".to_string()))?, - ) - .map_err(|e| InternalBitcoindConfigError::CouldNotParseValue(e.to_string()))?; let mut networks = HashMap::new(); for (maybe_sec, prop) in &conf_ini { @@ -180,7 +178,6 @@ impl InternalBitcoindConfig { Ok(Self { #[cfg(unix)] daemonwait, - data_dir, networks, }) } @@ -199,9 +196,6 @@ impl InternalBitcoindConfig { conf_ini .with_general_section() .set("daemonwait", if self.daemonwait { "1" } else { "0" }); - conf_ini - .with_general_section() - .set("datadir", self.data_dir.to_string_lossy()); for (network, network_conf) in &self.networks { conf_ini @@ -367,7 +361,8 @@ impl Step for SelectBitcoindTypeStep { conf } else { // TODO: Should the `else` only apply for "file not found" error? - InternalBitcoindConfig::new(internal_bitcoind_datadir(&ctx.data_dir)) + // In case of error while parsing existing file, we may overwrite values from other networks by creating new config. + InternalBitcoindConfig::new() }; // Insert entry for network if not present. if conf.networks.get(&ctx.bitcoin_config.network).is_none() { @@ -561,7 +556,7 @@ impl From for Box { impl StartInternalBitcoindStep { pub fn new(liana_datadir: &PathBuf) -> Self { Self { - conf_path: internal_bitcoind_config_path(liana_datadir), + bitcoind_datadir: internal_bitcoind_datadir(liana_datadir), network: Network::Bitcoin, started: None, exe_path: None, @@ -581,9 +576,13 @@ impl Step for StartInternalBitcoindStep { match msg { message::StartInternalBitcoindMsg::Start => { if let Some(path) = &self.exe_path { + let datadir = self + .bitcoind_datadir + .canonicalize() + .expect("Failed to canonicalize bitcoind datadir path"); let args = vec![ - format!("-chain={}", self.network.to_core_arg()), - format!("-conf={}", self.conf_path.to_string_lossy()), + format!("-chain={}", &self.network.to_core_arg()), + format!("-datadir={}", &datadir.to_string_lossy()), ]; let res = std::process::Command::new(path) .args(&args)