Merge PR 'Drop accepted closing_signed state on peer disconnection' (#5532)
What changed, and why it matters
This patch fixes a state-handling bug during Lightning channel close negotiations. If a user's signing device was slow or offline and the peer disconnected in the middle, the node could later combine an old accepted fee with a freshly proposed fee, potentially broadcasting an unintended closing transaction. The fix clears the stale 'closing_signed' state when the peer reconnects, forcing the negotiation to restart cleanly.
Review and merge if not already merged; backport to maintained release branches; consider audit of other async-signer pending states for similar reconnect cleanup gaps.
Security signals we found
State desynchronization across disconnect/reconnect in async signing path
Potential broadcast of closing tx with stale accepted fee
Missing reset of pending signer state on peer reconnection
Regression test added for reconnect-while-signer-blocked scenario
Evidence from the diff
In rust-lightning’s channel closing flow, when the local node accepts a counterparty closing_signed but the signer is unavailable, it stores last_received_closing_sig and sets signer_pending_closing. If the peer disconnected before the signer returned, these fields were not reset on reconnection. After reconnect, a fresh closing_signed exchange could occur while the pending signature later completed, creating a mismatch between the fee in the stored signature and the new negotiated fee. The patch resets last_received_closing_sig and signer_pending_closing alongside other closing state in the reconnect handler. A regression test verifies the node re-proposes its initial fee instead of broadcasting after the signer unblocks.
Changed components
lightning/src/ln/channel.rslightning/src/ln/async_signer_tests.rsInspect captured patch +68 / −0
### lightning/src/ln/async_signer_tests.rs
@@ -1379,6 +1379,72 @@ fn test_closing_signed() {
do_test_closing_signed(true, true);
}
+#[test]
+fn test_closing_signed_reconnect_while_signer_blocked() {
+ // If the counterparty disconnects while our signer is still unavailable, we drop the
+ // `closing_signed` state on reconnect rather than pairing a signature over the previously
+ // accepted fee with a fresh local signature over the re-proposed fee.
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
+ let 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();
+ let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1);
+ send_payment(&nodes[0], &vec![&nodes[1]][..], 8_000_000);
+
+ nodes[0].node.close_channel(&chan_id, &node_b_id).unwrap();
+ let node_a_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, node_b_id);
+ nodes[1].node.handle_shutdown(node_a_id, &node_a_shutdown);
+ let node_b_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, node_a_id);
+ nodes[0].node.handle_shutdown(node_b_id, &node_b_shutdown);
+ let node_a_proposal = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, node_b_id);
+ nodes[1].node.handle_closing_signed(node_a_id, &node_a_proposal);
+ let node_b_response = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id);
+ assert_ne!(node_a_proposal.fee_satoshis, node_b_response.fee_satoshis);
+
+ // Accept the counterparty's fee while our signature over it is unavailable.
+ nodes[0].disable_channel_signer_op(&node_b_id, &chan_id, SignerOp::SignClosingTransaction);
+ nodes[0].node.handle_closing_signed(node_b_id, &node_b_response);
+ assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
+ assert!(nodes[0].tx_broadcaster.txn_broadcast().is_empty());
+
+ // The counterparty disconnects before the signer returns. Keep the signer blocked through
+ // reestablishment and the polling of a fresh closing proposal.
+ nodes[0].node.peer_disconnected(node_b_id);
+ nodes[1].node.peer_disconnected(node_a_id);
+ connect_nodes(&nodes[0], &nodes[1]);
+ let node_a_reestablish = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap();
+ let node_b_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap();
+ nodes[1].node.handle_channel_reestablish(node_a_id, &node_a_reestablish);
+ nodes[0].node.handle_channel_reestablish(node_b_id, &node_b_reestablish);
+ nodes[0].node.get_and_clear_pending_msg_events();
+ nodes[1].node.get_and_clear_pending_msg_events();
+
+ nodes[0].enable_channel_signer_op(&node_b_id, &chan_id, SignerOp::SignClosingTransaction);
+ nodes[0].node.signer_unblocked(None);
+
+ // The signer unblocks before any counterparty signature is available, so we re-propose the
+ // initial minimum fee rather than broadcasting anything.
+ assert!(nodes[0].tx_broadcaster.txn_broadcast().is_empty());
+ let node_a_reproposal =
+ get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, node_b_id);
+ nodes[1].node.handle_closing_signed(node_a_id, &node_a_reproposal);
+ let node_b_re_response =
+ get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, node_a_id);
+ assert_ne!(node_a_reproposal.fee_satoshis, node_b_re_response.fee_satoshis);
+ nodes[0].node.handle_closing_signed(node_b_id, &node_b_re_response);
+ let broadcasts = nodes[0].tx_broadcaster.txn_broadcast();
+ assert_eq!(broadcasts.len(), 1);
+ check_spends!(broadcasts[0], funding_tx);
+ assert!(nodes[0].node.list_channels().is_empty());
+ for node in &nodes {
+ node.node.get_and_clear_pending_msg_events();
+ node.node.get_and_clear_pending_events();
+ node.chain_monitor.added_monitors.lock().unwrap().clear();
+ }
+}
+
fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
// Based off of `expect_channel_shutdown_state`.
// Test that we can asynchronously sign closing transactions.
### lightning/src/ln/channel.rs
@@ -10142,6 +10142,8 @@ where
// Upon reconnect we have to start the closing_signed dance over, but shutdown messages
// will be retransmitted.
self.context.last_sent_closing_fee = None;
+ self.context.last_received_closing_sig = None;
+ self.context.signer_pending_closing = false;
self.context.pending_counterparty_closing_signed = None;
self.context.closing_fee_limits = None;
Why this scored 59/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.