Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bubble up errors from the Bitcoin interface instead of panic'ing there #909

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
28 changes: 25 additions & 3 deletions src/bin/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::{
env,
io::{self, Write},
path::PathBuf,
process, thread, time,
process,
sync::{atomic, Arc},
thread, time,
};

use liana::{config::Config, DaemonHandle};
Expand Down Expand Up @@ -70,13 +72,33 @@ fn main() {
process::exit(1);
});

let daemon = DaemonHandle::start_default(config).unwrap_or_else(|e| {
let poll_interval = config.bitcoin_config.poll_interval_secs;
let DaemonHandle {
control,
bitcoin_poller,
} = DaemonHandle::start_default(config).unwrap_or_else(|e| {
log::error!("Error starting Liana daemon: {}", e);
process::exit(1);
});
daemon
let poller_shutdown = Arc::from(atomic::AtomicBool::from(false));
let poller_thread = thread::Builder::new()
.name("Bitcoin Core poller".to_string())
.spawn({
let shutdown = poller_shutdown.clone();
move || {
bitcoin_poller
.poll_forever(poll_interval, shutdown)
.expect("We assume the bitcoind connection never fails") // FIXME
}
})
.expect("Spawning the poller thread must never fail.");
control
.rpc_server()
.expect("JSONRPC server must terminate cleanly");
poller_shutdown.store(true, atomic::Ordering::Relaxed);
poller_thread
.join()
.expect("Bitcoin Core poller must terminate cleanly");

// We are always logging to stdout, should it be then piped to the log file (if self) or
// not. So just make sure that all messages were actually written.
Expand Down
Loading
Loading