Skip to content

Commit

Permalink
Merge pull request #114 from TheBlueMatt/2023-08-last-ditch-write
Browse files Browse the repository at this point in the history
Attempt a last-ditch ChannelManager persistence if the BP exits
  • Loading branch information
TheBlueMatt authored Aug 14, 2023
2 parents 0be8a1b + 6982d0a commit 5dc3629
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,12 +959,11 @@ async fn start_ldk() {

// Exit if either CLI polling exits or the background processor exits (which shouldn't happen
// unless we fail to write to the filesystem).
let mut bg_res = Ok(Ok(()));
tokio::select! {
_ = cli_poll => {},
bg_res = &mut background_processor => {
stop_listen_connect.store(true, Ordering::Release);
peer_manager.disconnect_all_peers();
panic!("ERR: background processing stopped with result {:?}, exiting", bg_res);
bg_exit = &mut background_processor => {
bg_res = bg_exit;
},
}

Expand All @@ -973,6 +972,21 @@ async fn start_ldk() {
stop_listen_connect.store(true, Ordering::Release);
peer_manager.disconnect_all_peers();

if let Err(e) = bg_res {
let persist_res = persister.persist("manager", &*channel_manager).unwrap();
use lightning::util::logger::Logger;
lightning::log_error!(
&*logger,
"Last-ditch ChannelManager persistence result: {:?}",
persist_res
);
panic!(
"ERR: background processing stopped with result {:?}, exiting.\n\
Last-ditch ChannelManager persistence result {:?}",
e, persist_res
);
}

// Stop the background processor.
if !bp_exit.is_closed() {
bp_exit.send(()).unwrap();
Expand Down

0 comments on commit 5dc3629

Please sign in to comment.