Merge pull request #114 from TheBlueMatt/2023-08-last-ditch-write
[ldk-sample] / src / main.rs
index f1e1cbfedc300e563dba70e19007839af334d9ea..d438682f7a9dd355a119746943b6a3f0256008eb 100644 (file)
@@ -607,6 +607,7 @@ async fn start_ldk() {
        // Step 11: Initialize the ChannelManager
        let mut user_config = UserConfig::default();
        user_config.channel_handshake_limits.force_announced_channel_preference = false;
+       user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
        user_config.manually_accept_inbound_channels = true;
        let mut restarting_node = true;
        let (channel_manager_blockhash, channel_manager) = {
@@ -958,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;
                },
        }
 
@@ -972,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();