]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Log when a channel is closed on startup due to stale ChannelManager
authorMatt Corallo <git@bluematt.me>
Sun, 1 Aug 2021 02:13:36 +0000 (02:13 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 5 Aug 2021 20:24:21 +0000 (20:24 +0000)
This is one of the riskiest parts of our API from the perspective
of accidental force-closes - if users delay persisting the
ChannelManager much at all after a ChannelMonitor we may hit a
force-close after restart.

The fact that we don't log at all when this happens is criminal.

lightning/src/ln/channelmanager.rs

index 0aa3f1d0bef33d2dddb0fbf00ceea63bc11ef559..c5db4075626fb93972037d10e1e5f60d68a57404 100644 (file)
@@ -4960,6 +4960,10 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
                                                channel.get_cur_counterparty_commitment_transaction_number() > monitor.get_cur_counterparty_commitment_number() ||
                                                channel.get_latest_monitor_update_id() < monitor.get_latest_update_id() {
                                        // But if the channel is behind of the monitor, close the channel:
+                                       log_error!(args.logger, "A ChannelManager is stale compared to the current ChannelMonitor!");
+                                       log_error!(args.logger, " The channel will be force-closed and the latest commitment transaction from the ChannelMonitor broadcast.");
+                                       log_error!(args.logger, " The ChannelMonitor for channel {} is at update_id {} but the ChannelManager is at update_id {}.",
+                                               log_bytes!(channel.channel_id()), monitor.get_latest_update_id(), channel.get_latest_monitor_update_id());
                                        let (_, mut new_failed_htlcs) = channel.force_shutdown(true);
                                        failed_htlcs.append(&mut new_failed_htlcs);
                                        monitor.broadcast_latest_holder_commitment_txn(&args.tx_broadcaster, &args.logger);