From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Mon, 14 Aug 2023 19:41:25 +0000 (+0000) Subject: Merge pull request #114 from TheBlueMatt/2023-08-last-ditch-write X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=5dc3629d0cef7b20685abbb2ae9942fe28fd6ddc;hp=0be8a1b35092b7ff8f1ac0a2efb8708e5a18a80c;p=ldk-sample Merge pull request #114 from TheBlueMatt/2023-08-last-ditch-write Attempt a last-ditch ChannelManager persistence if the BP exits --- diff --git a/src/main.rs b/src/main.rs index 9fd1190..d438682 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; }, } @@ -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();