Skip to content

Commit 5dc3629

Browse files
authored
Merge pull request #114 from TheBlueMatt/2023-08-last-ditch-write
Attempt a last-ditch ChannelManager persistence if the BP exits
2 parents 0be8a1b + 6982d0a commit 5dc3629

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/main.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,12 +959,11 @@ async fn start_ldk() {
959959

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

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

975+
if let Err(e) = bg_res {
976+
let persist_res = persister.persist("manager", &*channel_manager).unwrap();
977+
use lightning::util::logger::Logger;
978+
lightning::log_error!(
979+
&*logger,
980+
"Last-ditch ChannelManager persistence result: {:?}",
981+
persist_res
982+
);
983+
panic!(
984+
"ERR: background processing stopped with result {:?}, exiting.\n\
985+
Last-ditch ChannelManager persistence result {:?}",
986+
e, persist_res
987+
);
988+
}
989+
976990
// Stop the background processor.
977991
if !bp_exit.is_closed() {
978992
bp_exit.send(()).unwrap();

0 commit comments

Comments
 (0)