-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #592: gui: configure and start bitcoind
698eff7 doc: Add step to choose bitcoind type (jp1ac4) 36cf85d gui: add option to use internal bitcoind (jp1ac4) 765c68b installer: allow for different previous messages (jp1ac4) Pull request description: This is to resolve part of #570 (configure and start an already-installed bitcoind). I'm opening this draft PR so that you can provide feedback and check if any changes in approach are required. I've added optional steps to the installer for the user to configure and start an "internal" bitcoind that uses `~/.liana/bitcoind_datadir` as its data directory. The main things missing are: - [x] Make it work on Windows. - [x] Stop internal bitcoind when Liana is not running. - [x] Start this internal bitcoind, if applicable, when returning to Liana after installation. One option for this would be to check in the Liana config file whether the bitcoind `.cookie` file is within the `~/.liana/bitcoind_datadir` folder, which would indicate that the internal bitcoind should be used, and then to start it (we might need to store the executable path if it's not in PATH). - [x] Tests! ACKs for top commit: edouardparis: ACK 698eff7 Tree-SHA512: ce561cd74944b9a80e73bf0f45eafc613a033b115276c208cba95a00920409d3ec56b81cf50fd29eb60c82b96c1d9295a51b8df7e7ca62a4474dd77461564dd0
- Loading branch information
Showing
15 changed files
with
1,073 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use liana::{config::BitcoindConfig, miniscript::bitcoin}; | ||
|
||
use tracing::{info, warn}; | ||
|
||
use crate::app::config::InternalBitcoindExeConfig; | ||
|
||
/// Possible errors when starting bitcoind. | ||
#[derive(PartialEq, Eq, Debug, Clone)] | ||
pub enum StartInternalBitcoindError { | ||
CommandError(String), | ||
CouldNotCanonicalizeDataDir(String), | ||
CouldNotCanonicalizeCookiePath(String), | ||
CookieFileNotFound(String), | ||
BitcoinDError(String), | ||
} | ||
|
||
impl std::fmt::Display for StartInternalBitcoindError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
match self { | ||
Self::CommandError(e) => { | ||
write!(f, "Command to start bitcoind returned an error: {}", e) | ||
} | ||
Self::CouldNotCanonicalizeDataDir(e) => { | ||
write!(f, "Failed to canonicalize datadir: {}", e) | ||
} | ||
Self::CouldNotCanonicalizeCookiePath(e) => { | ||
write!(f, "Failed to canonicalize cookie path: {}", e) | ||
} | ||
Self::CookieFileNotFound(path) => { | ||
write!( | ||
f, | ||
"Cookie file was not found at the expected path: {}", | ||
path | ||
) | ||
} | ||
Self::BitcoinDError(e) => write!(f, "bitcoind connection check failed: {}", e), | ||
} | ||
} | ||
} | ||
|
||
/// Start internal bitcoind for the given network. | ||
pub fn start_internal_bitcoind( | ||
network: &bitcoin::Network, | ||
exe_config: InternalBitcoindExeConfig, | ||
) -> Result<std::process::Child, StartInternalBitcoindError> { | ||
let args = vec![ | ||
format!("-chain={}", network.to_core_arg()), | ||
format!( | ||
"-datadir={}", | ||
exe_config | ||
.data_dir | ||
.canonicalize() | ||
.map_err(|e| StartInternalBitcoindError::CouldNotCanonicalizeDataDir( | ||
e.to_string() | ||
))? | ||
.to_string_lossy() | ||
), | ||
]; | ||
std::process::Command::new(exe_config.exe_path) | ||
.args(&args) | ||
.stdout(std::process::Stdio::null()) // We still get bitcoind's logs in debug.log. | ||
.spawn() | ||
.map_err(|e| StartInternalBitcoindError::CommandError(e.to_string())) | ||
} | ||
|
||
/// Stop (internal) bitcoind. | ||
pub fn stop_internal_bitcoind(bitcoind_config: &BitcoindConfig) { | ||
match liana::BitcoinD::new(bitcoind_config, "internal_bitcoind_stop".to_string()) { | ||
Ok(bitcoind) => { | ||
info!("Stopping internal bitcoind..."); | ||
bitcoind.stop(); | ||
} | ||
Err(e) => { | ||
warn!("Could not create interface to internal bitcoind: '{}'.", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.