Resume channels awaiting a completed monitor persistence on load
What changed, and why it matters
This commit fixes a bug in the Lightning Dev Kit where a newly-created channel could get permanently stuck after a restart. If the channel's first monitor save finished after the last ChannelManager save, the channel would reload believing it was still waiting for that save, but nothing would ever clear the wait. As a result, the funding transaction was never broadcast and the channel could never become usable. The fix detects this situation on load and resumes the channel automatically. It is a reliability/availability bug, not a direct theft-of-funds vulnerability, because the channel simply fails to open rather than funds being stolen.
Review and merge the fix, then backport to maintained release branches. Operators running nodes with deferred monitor writes or custom Persist implementations returning InProgress should upgrade to avoid channels getting stuck after unclean restarts. No immediate incident response is required because the bug causes channels to stall rather than exposing keys or funds.
Security signals we found
Denial-of-service/availability impact: new channels can become permanently stuck after restart
State inconsistency between ChannelManager serialization and ChannelMonitor persistence
Fix includes regression tests for both completed-initial-monitor and blocked-update replay scenarios
No direct funds-loss path identified in the diff; stuck channel prevents funding broadcast
Evidence from the diff
The bug affects channels serialized with MONITOR_UPDATE_IN_PROGRESS. The initial ChannelMonitor write triggered by funding_created/funding_signed is not tracked as an in-flight ChannelMonitorUpdate, and blocked updates are dropped at load if the monitor already applied them. Therefore, a channel whose initial monitor persistence completed after the last ChannelManager serialization reloads with the awaiting-monitor flag set and no mechanism to clear it. The patch adds a branch in ChannelManager deserialization: if a funded channel is_awaiting_monitor_update(), has zero blocked_monitor_updates_pending(), and monitor.get_latest_update_id() equals funded_chan.get_latest_unblocked_monitor_update_id(), it pushes a BackgroundEvent::MonitorUpdatesComplete to resume the channel. New and updated tests cover the outbound reload-with-completed-initial-monitor case and adjust the blocked-update replay test to expect channel resumption.
Changed components
lightning/src/ln/channelmanager.rslightning/src/ln/chanmon_update_fail_tests.rslightning/src/ln/monitor_tests.rsInspect captured patch +163 / −2
### lightning/src/ln/chanmon_update_fail_tests.rs
@@ -3298,6 +3298,136 @@ fn test_outbound_reload_without_init_mon() {
do_test_outbound_reload_without_init_mon(false);
}
+fn do_test_outbound_reload_with_completed_init_mon(use_0conf: bool) {
+ // Test that if the monitor update generated in funding_signed is stored async and we restart
+ // with a ChannelManager serialized while it was pending, but the ChannelMonitor persistence
+ // did complete before the restart, we resume the channel and broadcast the funding
+ // transaction.
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+
+ let persister;
+ let new_chain_monitor;
+
+ let mut chan_config = test_default_channel_config();
+ chan_config.channel_handshake_limits.trust_own_funding_0conf = true;
+
+ let node_chanmgrs =
+ create_node_chanmgrs(2, &node_cfgs, &[Some(chan_config.clone()), Some(chan_config)]);
+ let node_a_reload;
+
+ let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+
+ let node_a_id = nodes[0].node.get_our_node_id();
+ let node_b_id = nodes[1].node.get_our_node_id();
+
+ nodes[0].node.create_channel(node_b_id, 100000, 10001, 43, None, None).unwrap();
+ nodes[1].node.handle_open_channel(
+ node_a_id,
+ &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id),
+ );
+
+ let events = nodes[1].node.get_and_clear_pending_events();
+ assert_eq!(events.len(), 1);
+ match events[0] {
+ Event::OpenChannelRequest { temporary_channel_id: chan_id, .. } => {
+ if use_0conf {
+ nodes[1]
+ .node
+ .accept_inbound_channel_from_trusted_peer(
+ &chan_id,
+ &node_a_id,
+ 0,
+ TrustedChannelFeatures::ZeroConf,
+ None,
+ )
+ .unwrap();
+ } else {
+ nodes[1].node.accept_inbound_channel(&chan_id, &node_a_id, 0, None).unwrap();
+ }
+ },
+ _ => panic!("Unexpected event"),
+ };
+
+ nodes[0].node.handle_accept_channel(
+ node_b_id,
+ &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, node_a_id),
+ );
+
+ let (temporary_channel_id, funding_tx, ..) =
+ create_funding_transaction(&nodes[0], &node_b_id, 100000, 43);
+
+ nodes[0]
+ .node
+ .funding_transaction_generated(temporary_channel_id, node_b_id, funding_tx.clone())
+ .unwrap();
+ check_added_monitors(&nodes[0], 0);
+
+ let funding_created_msg =
+ get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, node_b_id);
+ nodes[1].node.handle_funding_created(node_a_id, &funding_created_msg);
+ check_added_monitors(&nodes[1], 1);
+ expect_channel_pending_event(&nodes[1], &node_a_id);
+
+ let bs_signed_locked = nodes[1].node.get_and_clear_pending_msg_events();
+ assert_eq!(bs_signed_locked.len(), if use_0conf { 2 } else { 1 });
+ let chan_id = match &bs_signed_locked[0] {
+ MessageSendEvent::SendFundingSigned { msg, .. } => {
+ chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
+
+ nodes[0].node.handle_funding_signed(node_b_id, &msg);
+ check_added_monitors(&nodes[0], 1);
+ msg.channel_id
+ },
+ _ => panic!("Unexpected event"),
+ };
+ if use_0conf {
+ match &bs_signed_locked[1] {
+ MessageSendEvent::SendChannelReady { msg, .. } => {
+ nodes[0].node.handle_channel_ready(node_b_id, &msg);
+ },
+ _ => panic!("Unexpected event"),
+ }
+ }
+
+ assert!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().is_empty());
+ assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
+ assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
+
+ // nodes[0] is now waiting on the first ChannelMonitor persistence to complete in order to
+ // broadcast the funding transaction. If nodes[0] restarts at this point with the
+ // ChannelMonitor persisted, it should resume the channel.
+ let node_a_ser = nodes[0].node.encode();
+ let mon_ser = get_monitor!(nodes[0], chan_id).encode();
+ reload_node!(nodes[0], &node_a_ser, &[&mon_ser], persister, new_chain_monitor, node_a_reload);
+
+ nodes[0].node.test_process_background_events();
+ assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0), [funding_tx]);
+ let events = nodes[0].node.get_and_clear_pending_events();
+ assert_eq!(events.len(), if use_0conf { 2 } else { 1 });
+ assert!(matches!(events[0], Event::ChannelPending { .. }));
+ if use_0conf {
+ // We already have the peer's channel_ready, so the channel is ready immediately.
+ assert!(matches!(events[1], Event::ChannelReady { .. }));
+ }
+
+ nodes[1].node.peer_disconnected(node_a_id);
+ let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]);
+ reconnect_args.send_channel_ready = (use_0conf, use_0conf);
+ reconnect_nodes(reconnect_args);
+ if use_0conf {
+ expect_channel_ready_event(&nodes[1], &node_a_id);
+ assert_eq!(nodes[0].node.list_usable_channels().len(), 1);
+ assert_eq!(nodes[1].node.list_usable_channels().len(), 1);
+ }
+}
+
+#[test]
+fn test_outbound_reload_with_completed_init_mon() {
+ do_test_outbound_reload_with_completed_init_mon(true);
+ do_test_outbound_reload_with_completed_init_mon(false);
+}
+
fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: bool) {
// Test that if the monitor update generated by funding_transaction_generated is stored async
// and we restart with the latest ChannelManager but the ChannelMonitor persistence never
### lightning/src/ln/channelmanager.rs
@@ -20733,6 +20733,31 @@ impl<
""
),
);
+ } else if funded_chan.is_awaiting_monitor_update()
+ && funded_chan.blocked_monitor_updates_pending() == 0
+ && monitor.get_latest_update_id()
+ == funded_chan.get_latest_unblocked_monitor_update_id()
+ {
+ // Neither the initial `ChannelMonitor` persistence nor blocked updates
+ // (which we dropped above if the `ChannelMonitor` already applied them)
+ // are tracked as in-flight updates. If the channel is still awaiting a
+ // monitor update, but has none in-flight or blocked, the persistence it
+ // was waiting on (whose result we have a `ChannelMonitor` for) completed
+ // after we were last serialized. Resume the channel the same way we do
+ // when all of its in-flight updates completed, otherwise it would never
+ // make progress (e.g. an outbound channel would never broadcast its
+ // funding transaction).
+ //
+ // The update id equality above implies the `ChannelMonitor` has applied
+ // every update the channel generated: a channel lagging its
+ // `ChannelMonitor` was force-closed above, and one ahead of it is
+ // rejected by the stale-`ChannelManager` check below.
+ log_debug!(logger, "A ChannelMonitor persistence completed since the ChannelManager was last serialized");
+ pending_background_events.push(BackgroundEvent::MonitorUpdatesComplete {
+ counterparty_node_id: *counterparty_id,
+ channel_id: *chan_id,
+ highest_update_id_completed: monitor.get_latest_update_id(),
+ });
}
if funded_chan.get_latest_unblocked_monitor_update_id()
> max_in_flight_update_id
### lightning/src/ln/monitor_tests.rs
@@ -3466,8 +3466,14 @@ fn test_event_replay_causing_monitor_replay() {
let serialized_monitor = get_monitor!(nodes[0], chan.2).encode();
reload_node!(nodes[0], &serialized_channel_manager, &[&serialized_monitor], persister, new_chain_monitor, node_deserialized);
- // Expect the `PaymentSent` to get replayed, this time without the duplicate monitor update
- expect_payment_sent(&nodes[0], payment_preimage, None, false, false /* expected post-event monitor update*/);
+ // Expect the `PaymentSent` to get replayed, this time without the duplicate monitor update.
+ // As the RAA `ChannelMonitorUpdate` already completed, the channel is resumed on startup,
+ // finalizing the claim.
+ expect_payment_sent(&nodes[0], payment_preimage, None, true, false /* expected post-event monitor update*/);
+
+ nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id());
+ reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1]));
+ send_payment(&nodes[0], &[&nodes[1]], 100_000);
}
#[test]Why this scored 53/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.