gui: allow to bump managed bitcoind version

This makes it possible to bump the managed bitcoind version used
when installing a new Liana wallet.

The GUI will look for the most recent managed bitcoind version
available when starting bitcoind so that existing wallets
with a previous managed bitcoind version will not be affected.
This commit is contained in:
jp1ac4 2023-10-26 10:58:42 +01:00
parent 1a59d03858
commit 1808f8f1de
No known key found for this signature in database
GPG Key ID: A7ACD32423568D7B
2 changed files with 33 additions and 7 deletions

View File

@ -16,7 +16,11 @@ use std::os::windows::process::CommandExt;
#[cfg(target_os = "windows")]
const CREATE_NO_WINDOW: u32 = 0x08000000;
pub const VERSION: &str = "25.0";
/// Current and previous managed bitcoind versions, in order of descending version.
pub const VERSIONS: [&str; 1] = ["25.0"];
/// Current managed bitcoind version for new installations.
pub const VERSION: &str = VERSIONS[0];
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
pub const SHA256SUM: &str = "5708fc639cdfc27347cccfd50db9b73b53647b36fb5f3a4a93537cbe8828c27f";
@ -64,9 +68,9 @@ pub fn internal_bitcoind_datadir(liana_datadir: &PathBuf) -> PathBuf {
}
/// Internal bitcoind executable path.
pub fn internal_bitcoind_exe_path(liana_datadir: &PathBuf) -> PathBuf {
pub fn internal_bitcoind_exe_path(liana_datadir: &PathBuf, bitcoind_version: &str) -> PathBuf {
internal_bitcoind_directory(liana_datadir)
.join(format!("bitcoin-{}", &VERSION))
.join(format!("bitcoin-{}", bitcoind_version))
.join("bin")
.join(if cfg!(target_os = "windows") {
"bitcoind.exe"
@ -114,6 +118,7 @@ pub enum StartInternalBitcoindError {
CouldNotCanonicalizeCookiePath(String),
CookieFileNotFound(String),
BitcoinDError(String),
ExecutableNotFound,
}
impl std::fmt::Display for StartInternalBitcoindError {
@ -139,6 +144,7 @@ impl std::fmt::Display for StartInternalBitcoindError {
)
}
Self::BitcoinDError(e) => write!(f, "bitcoind connection check failed: {}", e),
Self::ExecutableNotFound => write!(f, "bitcoind executable not found."),
}
}
}
@ -157,7 +163,23 @@ impl Bitcoind {
liana_datadir: &PathBuf,
) -> Result<Self, StartInternalBitcoindError> {
let bitcoind_datadir = internal_bitcoind_datadir(liana_datadir);
let bitcoind_exe_path = internal_bitcoind_exe_path(liana_datadir);
// Find most recent bitcoind version available.
let bitcoind_exe_path = VERSIONS
.iter()
.filter_map(|v| {
let path = internal_bitcoind_exe_path(liana_datadir, v);
if path.exists() {
Some(path)
} else {
None
}
})
.next()
.ok_or(StartInternalBitcoindError::ExecutableNotFound)?;
info!(
"Found bitcoind executable at '{}'.",
bitcoind_exe_path.to_string_lossy()
);
let datadir_path_str = bitcoind_datadir
.canonicalize()
.map_err(|e| StartInternalBitcoindError::CouldNotCanonicalizeDataDir(e.to_string()))?

View File

@ -21,7 +21,7 @@ use liana_ui::{component::form, widget::*};
use crate::{
bitcoind::{
self, bitcoind_network_dir, internal_bitcoind_datadir, internal_bitcoind_directory,
Bitcoind, StartInternalBitcoindError,
Bitcoind, StartInternalBitcoindError, VERSION,
},
download,
hw::HardwareWallets,
@ -633,8 +633,11 @@ impl InternalBitcoindStep {
impl Step for InternalBitcoindStep {
fn load_context(&mut self, ctx: &Context) {
if self.exe_path.is_none() {
if bitcoind::internal_bitcoind_exe_path(&ctx.data_dir).exists() {
self.exe_path = Some(bitcoind::internal_bitcoind_exe_path(&ctx.data_dir))
// Check if current managed bitcoind version is already installed.
// For new installations, we ignore any previous managed bitcoind versions that might be installed.
let exe_path = bitcoind::internal_bitcoind_exe_path(&ctx.data_dir, VERSION);
if exe_path.exists() {
self.exe_path = Some(exe_path)
} else if self.exe_download.is_none() {
self.exe_download = Some(Download::new(0));
};
@ -749,6 +752,7 @@ impl Step for InternalBitcoindStep {
self.install_state = Some(InstallState::Finished);
self.exe_path = Some(bitcoind::internal_bitcoind_exe_path(
&self.liana_datadir,
VERSION,
));
return Command::perform(async {}, |_| {
Message::InternalBitcoind(