Merge #662: loader: try to stop bitcoind if connected
0a432d081dbdfce72e11751e080a941e24dd04ff limit retry to loader stop (edouard)
68a2278f2afdcd54ce866ed6179bda528550cf7a fix loader: add waiting_for_bitcoind_daemon (edouard)
320a6d700c19b644d58d30381f92e76f7b3257a0 loader: try to stop bitcoind if connected (edouard)
Pull request description:
ACKs for top commit:
darosior:
ACK 0a432d081dbdfce72e11751e080a941e24dd04ff
Tree-SHA512: 11afb43260352df33c29d79adbef36fbe3925a2016b27cb8a9bcf5c50b78094afbf514ac437776f880b85380b7f5c7d778949e956e9eb758ff4afc22a579c700
This commit is contained in:
commit
24a04af51f
@ -234,15 +234,21 @@ impl Bitcoind {
|
||||
|
||||
/// Stop (internal) bitcoind.
|
||||
pub fn stop(&self) {
|
||||
match liana::BitcoinD::new(&self.config, "internal_bitcoind_stop".to_string()) {
|
||||
Ok(bitcoind) => {
|
||||
info!("Stopping internal bitcoind...");
|
||||
bitcoind.stop();
|
||||
info!("Stopped liana managed bitcoind");
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Could not create interface to internal bitcoind: '{}'.", e);
|
||||
}
|
||||
stop_bitcoind(&self.config);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop_bitcoind(config: &BitcoindConfig) -> bool {
|
||||
match liana::BitcoinD::new(config, "internal_bitcoind_stop".to_string()) {
|
||||
Ok(bitcoind) => {
|
||||
info!("Stopping internal bitcoind...");
|
||||
bitcoind.stop();
|
||||
info!("Stopped liana managed bitcoind");
|
||||
true
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Could not create interface to internal bitcoind: '{}'.", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ use crate::{
|
||||
config::Config as GUIConfig,
|
||||
wallet::{Wallet, WalletError},
|
||||
},
|
||||
bitcoind::{Bitcoind, StartInternalBitcoindError},
|
||||
bitcoind::{stop_bitcoind, Bitcoind, StartInternalBitcoindError},
|
||||
daemon::{client, embedded::EmbeddedDaemon, model::*, Daemon, DaemonError},
|
||||
};
|
||||
|
||||
@ -39,6 +39,7 @@ pub struct Loader {
|
||||
pub gui_config: GUIConfig,
|
||||
pub daemon_started: bool,
|
||||
pub internal_bitcoind: Option<Bitcoind>,
|
||||
pub waiting_daemon_bitcoind: bool,
|
||||
|
||||
step: Step,
|
||||
}
|
||||
@ -96,6 +97,7 @@ impl Loader {
|
||||
step: Step::Connecting,
|
||||
daemon_started: false,
|
||||
internal_bitcoind,
|
||||
waiting_daemon_bitcoind: false,
|
||||
},
|
||||
Command::perform(connect(path), Message::Loaded),
|
||||
)
|
||||
@ -124,6 +126,7 @@ impl Loader {
|
||||
if let Some(daemon_config_path) = self.gui_config.daemon_config_path.clone() {
|
||||
self.step = Step::StartingDaemon;
|
||||
self.daemon_started = true;
|
||||
self.waiting_daemon_bitcoind = true;
|
||||
return Command::perform(
|
||||
start_bitcoind_and_daemon(
|
||||
daemon_config_path,
|
||||
@ -165,6 +168,7 @@ impl Loader {
|
||||
if let Some(bitcoind) = bitcoind {
|
||||
self.internal_bitcoind = Some(bitcoind);
|
||||
}
|
||||
self.waiting_daemon_bitcoind = false;
|
||||
self.step = Step::Syncing {
|
||||
daemon: daemon.clone(),
|
||||
progress: 0.0,
|
||||
@ -225,6 +229,16 @@ impl Loader {
|
||||
|
||||
if let Some(bitcoind) = &self.internal_bitcoind {
|
||||
bitcoind.stop();
|
||||
} else if self.waiting_daemon_bitcoind && self.gui_config.start_internal_bitcoind {
|
||||
if let Ok(config) = Config::from_file(self.gui_config.daemon_config_path.clone()) {
|
||||
if let Some(bitcoind_config) = &config.bitcoind_config {
|
||||
let mut retry = 0;
|
||||
while !stop_bitcoind(bitcoind_config) && retry < 10 {
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
retry += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user