Skip to content

Commit 6982d0a

Browse files
committed
Attempt a last-ditch ChannelManager persistence if the BP exits
If the BP exits because it failed to write our ChannelManager to disk, we'll probably lose some channels on startup. However, there's still some chance for us to write the `ChannelManager` in a retry, which we should do before we exit.
1 parent 34a748c commit 6982d0a

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
@@ -914,12 +914,11 @@ async fn start_ldk() {
914914

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

@@ -928,6 +927,21 @@ async fn start_ldk() {
928927
stop_listen_connect.store(true, Ordering::Release);
929928
peer_manager.disconnect_all_peers();
930929

930+
if let Err(e) = bg_res {
931+
let persist_res = persister.persist("manager", &*channel_manager).unwrap();
932+
use lightning::util::logger::Logger;
933+
lightning::log_error!(
934+
&*logger,
935+
"Last-ditch ChannelManager persistence result: {:?}",
936+
persist_res
937+
);
938+
panic!(
939+
"ERR: background processing stopped with result {:?}, exiting.\n\
940+
Last-ditch ChannelManager persistence result {:?}",
941+
e, persist_res
942+
);
943+
}
944+
931945
// Stop the background processor.
932946
if !bp_exit.is_closed() {
933947
bp_exit.send(()).unwrap();

0 commit comments

Comments
 (0)