Merge PR 'Reject closing_signed while a fee update remains pending' (#5533)
What changed, and why it matters
This change fixes a bug in the Lightning Dev Kit where a Bitcoin Lightning channel could panic (crash) if a 'closing_signed' message was processed while a fee update was still pending. The fix rejects such messages and closes the channel gracefully instead of crashing. The test names and code confirm the previous behavior could cause a panic.
Apply the patch. It is a targeted defensive fix with regression tests. Monitor for related state-machine issues during shutdown/fee-update races.
Security signals we found
Denial-of-service vector: remote peer could trigger a node panic by sending closing_signed during a pending fee update
State-machine inconsistency between fee update and closing negotiation
Regression tests explicitly named to prevent panic
Channel force-closed defensively rather than continuing in unsafe state
Evidence from the diff
The commit adds checks in channel.rs to return a controlled ChannelError::close when a closing_signed message arrives or is retried while pending_update_fee is Some. Previously, this combination could trigger a panic. Two regression tests in shutdown_tests.rs verify both the remote-initiated and signer-pending-retry paths no longer panic.
Changed components
lightning/src/ln/channel.rslightning/src/ln/shutdown_tests.rsInspect captured patch +75 / −0
### lightning/src/ln/channel.rs
@@ -10603,6 +10603,11 @@ where
}
let (closing_signed, signed_closing_tx, shutdown_result) = if self.context.signer_pending_closing {
+ if self.context.pending_update_fee.is_some() {
+ return Err(ChannelError::close(
+ "Cannot retry closing_signed while there is still a pending fee update".to_owned(),
+ ));
+ }
debug_assert!(self.context.last_sent_closing_fee.is_some());
if let Some((fee, skip_remote_output, fee_range, holder_sig)) = self.context.last_sent_closing_fee.clone() {
debug_assert!(holder_sig.is_none());
@@ -11770,6 +11775,12 @@ where
.to_owned(),
));
}
+ if self.context.pending_update_fee.is_some() {
+ return Err(ChannelError::close(
+ "Remote end sent us a closing_signed while there was still a pending fee update"
+ .to_owned(),
+ ));
+ }
if msg.fee_satoshis > TOTAL_BITCOIN_SUPPLY_SATOSHIS {
// this is required to stop potential overflow in build_closing_transaction
return Err(ChannelError::close(
### lightning/src/ln/shutdown_tests.rs
@@ -28,6 +28,7 @@ use crate::types::string::UntrustedString;
use crate::util::config::UserConfig;
use crate::util::errors::APIError;
use crate::util::ser::Writeable;
+use crate::util::test_channel_signer::SignerOp;
use crate::util::test_utils;
use crate::util::test_utils::OnGetShutdownScriptpubkey;
@@ -85,6 +86,69 @@ fn pre_funding_lock_shutdown_test() {
check_closed_event(&nodes[1], 1, reason_b, &[node_a_id], 8000000);
}
+#[test]
+fn closing_signed_with_pending_peer_fee_does_not_panic() {
+ do_test_closing_signed_with_pending_peer_fee(false);
+}
+
+#[test]
+fn signer_pending_closing_with_pending_peer_fee_does_not_panic() {
+ do_test_closing_signed_with_pending_peer_fee(true);
+}
+
+fn do_test_closing_signed_with_pending_peer_fee(signer_pending: bool) {
+ 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 funder_id = nodes[0].node.get_our_node_id();
+ let victim_id = nodes[1].node.get_our_node_id();
+ let chan_id = create_announced_chan_between_nodes(&nodes, 0, 1).2;
+ let feerate_per_kw = get_feerate!(nodes[1], nodes[0], chan_id);
+
+ nodes[0].node.close_channel(&chan_id, &victim_id).unwrap();
+ let shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, victim_id);
+ nodes[1].node.handle_shutdown(funder_id, &shutdown);
+ let shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, funder_id);
+ nodes[0].node.handle_shutdown(victim_id, &shutdown);
+ let closing = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, victim_id);
+
+ if signer_pending {
+ nodes[1].disable_channel_signer_op(&funder_id, &chan_id, SignerOp::SignClosingTransaction);
+ nodes[1].node.handle_closing_signed(funder_id, &closing);
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
+ assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
+ check_added_monitors(&nodes[1], 0);
+ }
+
+ // Fee updates can still be committed during shutdown, but must not remain pending when
+ // negotiating the closing transaction.
+ nodes[1]
+ .node
+ .handle_update_fee(funder_id, &msgs::UpdateFee { channel_id: chan_id, feerate_per_kw });
+ assert_eq!(nodes[1].node.list_channels().len(), 1);
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
+ assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
+ check_added_monitors(&nodes[1], 0);
+
+ let err = if signer_pending {
+ nodes[1].enable_channel_signer_op(&funder_id, &chan_id, SignerOp::SignClosingTransaction);
+ nodes[1].node.signer_unblocked(Some((funder_id, chan_id)));
+ "Cannot retry closing_signed while there is still a pending fee update"
+ } else {
+ nodes[1].node.handle_closing_signed(funder_id, &closing);
+ "Remote end sent us a closing_signed while there was still a pending fee update"
+ };
+ assert!(nodes[1].node.list_channels().is_empty());
+ check_added_monitors(&nodes[1], 1);
+ let errors = check_closed_broadcast(&nodes[1], 1, true);
+ assert_eq!(errors.len(), 1);
+ assert_eq!(errors[0].channel_id, chan_id);
+ assert_eq!(errors[0].data, err);
+ let reason = ClosureReason::ProcessingError { err: err.to_owned() };
+ check_closed_events(&nodes[1], &[ExpectedCloseEvent::from_id_reason(chan_id, false, reason)]);
+}
+
#[test]
fn expect_channel_shutdown_state() {
// Test sending a shutdown prior to channel_ready after funding generationWhy this scored 60/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.