From 7584b6347bf6525d57d09596a60b4bdd2bccfb7f Mon Sep 17 00:00:00 2001 From: jp1ac4 <121959000+jp1ac4@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:22:15 +0000 Subject: [PATCH] gui: start internal bitcoind with given config This will allow bitcoind to start also in case of using rpcauth. The cookie file is canonicalized in the installer beforehand instead. There is now no need for the config parameter to be mutable. --- gui/src/bitcoind.rs | 8 ++------ gui/src/installer/step/bitcoind.rs | 29 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/gui/src/bitcoind.rs b/gui/src/bitcoind.rs index eb486d28..c39c9fb2 100644 --- a/gui/src/bitcoind.rs +++ b/gui/src/bitcoind.rs @@ -1,7 +1,7 @@ use base64::Engine; use bitcoin_hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine}; use liana::{ - config::{BitcoindConfig, BitcoindRpcAuth}, + config::BitcoindConfig, miniscript::bitcoin::{self, Network}, random::{random_bytes, RandomnessError}, }; @@ -402,7 +402,7 @@ impl Bitcoind { /// Start internal bitcoind for the given network. pub fn start( network: &bitcoin::Network, - mut config: BitcoindConfig, + config: BitcoindConfig, liana_datadir: &PathBuf, ) -> Result { let bitcoind_datadir = internal_bitcoind_datadir(liana_datadir); @@ -477,10 +477,6 @@ impl Bitcoind { thread::sleep(time::Duration::from_millis(500)); } - config.rpc_auth = BitcoindRpcAuth::CookieFile(cookie_path.canonicalize().map_err(|e| { - StartInternalBitcoindError::CouldNotCanonicalizeCookiePath(e.to_string()) - })?); - liana::BitcoinD::new(&config, "internal_bitcoind_start".to_string()) .map_err(|e| StartInternalBitcoindError::BitcoinDError(e.to_string()))?; diff --git a/gui/src/installer/step/bitcoind.rs b/gui/src/installer/step/bitcoind.rs index 2f1ad1f2..1a8874c4 100644 --- a/gui/src/installer/step/bitcoind.rs +++ b/gui/src/installer/step/bitcoind.rs @@ -693,17 +693,24 @@ impl Step for InternalBitcoindStep { } } message::InternalBitcoindMsg::Start => { - if let Err(e) = self.bitcoind_datadir.canonicalize() { - self.started = Some(Err( - StartInternalBitcoindError::CouldNotCanonicalizeDataDir(e.to_string()), - )); - return Command::none(); - } - - let cookie_path = bitcoind::internal_bitcoind_cookie_path( - &self.bitcoind_datadir, - &self.network, - ); + let bitcoind_datadir = match self.bitcoind_datadir.canonicalize() { + Ok(path) => path, + Err(e) => { + self.started = Some(Err( + StartInternalBitcoindError::CouldNotCanonicalizeDataDir( + e.to_string(), + ), + )); + return Command::none(); + } + }; + // Pass the canonicalized `bitcoind_datadir` so that the cookie path returned + // by `internal_bitcoind_cookie_path` is also canonicalized. This way, the + // canonicalized path will later be saved to the config file. + // We cannot use `cookie_path.canonicalize()` as we have not yet started + // bitcoind and so the path does not exist. + let cookie_path = + bitcoind::internal_bitcoind_cookie_path(&bitcoind_datadir, &self.network); let rpc_port = self .internal_bitcoind_config