Allow monitor_pending_channel_ready on resumed outbound channels
What changed, and why it matters
This commit fixes a bug where a Lightning node could crash in a loop every time it started up. The crash happened when a channel's funding transaction had already confirmed while the node was offline, but the node still had old saved state. The old code wrongly assumed this situation was impossible and panicked. The fix removes that incorrect assumption and lets the node resume the channel normally. It is a denial-of-service/availability bug, not a theft-of-funds bug, and it can only be triggered by the node's own saved state and normal blockchain activity.
Apply the patch. It is a targeted bug fix with a regression test and should be backported to affected release branches. No immediate incident response is required unless operators have observed unrecoverable startup panics after funding transactions confirmed during downtime.
Security signals we found
Assertion failure/panic on startup caused by stale ChannelManager state
Denial of service: node cannot restart due to recurring panic
Race condition between chain sync and background event processing during channel resume
Fix removes overly strict invariant that did not account for prior-process funding broadcast
Evidence from the diff
In rust-lightning, when a channel’s initial ChannelMonitor persistence completed while the node was down, resuming the channel could race with chain synchronization. If the funding transaction had been broadcast before shutdown and confirmed to the required depth while the node was offline, chain sync would mark channel_ready as pending on the still-paused channel. The subsequent monitor_updating_restored path then hit an assertion that an outbound, non-zero-conf channel can never have monitor_pending_channel_ready set, causing a panic at every startup. Because nothing was persisted before the panic, the node would panic on every restart. The patch removes the assertion and simply sends channel_ready, and adds a regression test simulating the exact startup ordering.
Changed components
lightning/src/ln/channel.rsChannel resumption / monitor_updating_restored pathOutbound non-zero-conf channel startup after async monitor persistenceInspect captured patch +171 / −5
### lightning/src/ln/chanmon_update_fail_tests.rs
@@ -3428,6 +3428,170 @@ fn test_outbound_reload_with_completed_init_mon() {
do_test_outbound_reload_with_completed_init_mon(false);
}
+#[test]
+fn test_outbound_reload_funding_confirmed_during_downtime() {
+ // Test that an outbound channel whose funding transaction was broadcast before the node went
+ // down and confirmed to the required depth while it was down is resumed without hitting an
+ // assertion, even if the chain is synced before the pending background events are processed.
+ // Chain sync then holds channel_ready back on the still-paused channel, which the resume has
+ // to release.
+ 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, .. } => {
+ 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 chan_id = match &nodes[1].node.get_and_clear_pending_msg_events()[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"),
+ };
+
+ 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. Serializing the ChannelManager now is what a crash
+ // leaves on disk.
+ let node_a_ser = nodes[0].node.encode();
+
+ // The persistence then completes and the funding transaction is broadcast before the
+ // ChannelManager is ever written out.
+ chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
+ let (latest_update, _) = nodes[0].chain_monitor.get_latest_mon_update_id(chan_id);
+ nodes[0].chain_monitor.chain_monitor.force_channel_monitor_updated(chan_id, latest_update);
+ check_added_monitors(&nodes[0], 0);
+ expect_channel_pending_event(&nodes[0], &node_b_id);
+ assert_eq!(
+ nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0),
+ [funding_tx.clone()]
+ );
+
+ 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);
+
+ // The funding transaction confirms to the required depth while the node is down, and the
+ // chain is synced before the pending background events are processed. Note that we must not
+ // process the pending background events in between, so we connect the blocks by hand.
+ mine_transaction_without_consistency_checks(&nodes[0], &funding_tx);
+ let mut prev_blockhash = nodes[0].best_block_hash();
+ let mut height = nodes[0].best_block_info().1;
+ for _ in 0..CHAN_CONFIRM_DEPTH - 1 {
+ height += 1;
+ let header = create_dummy_header(prev_blockhash, height);
+ nodes[0].chain_monitor.chain_monitor.best_block_updated(&header, height);
+ nodes[0].chain_monitor.chain_monitor.transactions_confirmed(&header, &[], height);
+ nodes[0].node.best_block_updated(&header, height);
+ nodes[0].node.transactions_confirmed(&header, &[], height);
+ prev_blockhash = header.block_hash();
+ }
+
+ nodes[0].node.test_process_background_events();
+
+ // The channel is resumed, but as the peer is still disconnected the channel_ready it
+ // generated is held until the peers reconnect.
+ expect_channel_pending_event(&nodes[0], &node_b_id);
+ assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
+ assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
+
+ nodes[1].node.peer_disconnected(node_a_id);
+ let init_msg = msgs::Init {
+ features: nodes[1].node.init_features(),
+ networks: None,
+ remote_network_address: None,
+ };
+ nodes[0].node.peer_connected(node_b_id, &init_msg, true).unwrap();
+ let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]);
+ assert_eq!(reestablish_1.len(), 1);
+ nodes[1].node.peer_connected(node_a_id, &init_msg, false).unwrap();
+ let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]);
+ assert_eq!(reestablish_2.len(), 1);
+ nodes[1].node.handle_channel_reestablish(node_a_id, &reestablish_1[0]);
+ let resp_1 = handle_chan_reestablish_msgs!(nodes[1], nodes[0]);
+ assert!(resp_1.0.is_none() && resp_1.1.is_none() && resp_1.2.is_none());
+ nodes[0].node.handle_channel_reestablish(node_b_id, &reestablish_2[0]);
+ let resp_0 = handle_chan_reestablish_msgs!(nodes[0], nodes[1]);
+
+ // nodes[0] retransmits the channel_ready it generated when it resumed the channel.
+ let channel_ready = resp_0.0.expect("expected a retransmitted channel_ready");
+ nodes[1].node.handle_channel_ready(node_a_id, &channel_ready);
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
+ assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
+
+ confirm_transaction(&nodes[1], &funding_tx);
+ let channel_ready_b = nodes[1]
+ .node
+ .get_and_clear_pending_msg_events()
+ .iter()
+ .find_map(|ev| match ev {
+ MessageSendEvent::SendChannelReady { node_id, msg } if node_id == &node_a_id => {
+ Some(msg.clone())
+ },
+ _ => None,
+ })
+ .unwrap();
+ nodes[0].node.handle_channel_ready(node_b_id, &channel_ready_b);
+ expect_channel_ready_event(&nodes[1], &node_a_id);
+ expect_channel_ready_event(&nodes[0], &node_b_id);
+ nodes[0].node.get_and_clear_pending_msg_events();
+ nodes[1].node.get_and_clear_pending_msg_events();
+ assert_eq!(nodes[0].node.list_usable_channels().len(), 1);
+ assert_eq!(nodes[1].node.list_usable_channels().len(), 1);
+}
+
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/channel.rs
@@ -10371,13 +10371,15 @@ where
// We will never broadcast the funding transaction when we're in MonitorUpdateInProgress
// (and we assume the user never directly broadcasts the funding transaction and waits for
- // us to do it). Thus, we can only ever hit monitor_pending_channel_ready when we're
+ // us to do it). Thus, we can hit monitor_pending_channel_ready when we're
// * an inbound channel that failed to persist the monitor on funding_created and we got
- // the funding transaction confirmed before the monitor was persisted, or
- // * a 0-conf channel and intended to send the channel_ready before any broadcast at all.
+ // the funding transaction confirmed before the monitor was persisted,
+ // * a 0-conf channel and intended to send the channel_ready before any broadcast at all, or
+ // * an outbound channel resumed from a `ChannelManager` that was serialized while the
+ // initial `ChannelMonitor` persistence was pending - a prior process broadcast the
+ // funding transaction after that serialization, and chain sync can have seen it confirm
+ // before the pending completion is processed here.
let channel_ready = if self.context.monitor_pending_channel_ready {
- assert!(!self.funding.is_outbound() || self.context.minimum_depth == Some(0),
- "Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
self.context.monitor_pending_channel_ready = false;
let channel_ready = self.get_channel_ready(logger);
requires_channel_manager_persistence |= channel_ready.is_some();Why this scored 50/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.