lightningd: don't forget a channel once we've sent tx_signatures
What changed, and why it matters
This patch fixes a bug in Core Lightning's dual-funded channel opening. Previously, if the peer sent an 'abort' message or an error occurred after we had already sent our transaction signatures, the node might forget the channel. Because those signatures could let the peer broadcast the funding transaction on the Bitcoin network, forgetting the channel could leave the node unaware of funds it had committed to. The fix makes the node remember the channel until the funding transaction's inputs are spent, as required by the Lightning protocol specification.
Apply the patch. Nodes running dual-funded channel opens should upgrade, as the bug could cause them to lose track of a channel whose funding transaction they have already signed. Monitor for any channels that may have been prematurely forgotten and reconcile on-chain state if necessary.
Security signals we found
Protocol compliance fix for BOLT #2 tx_abort receiver rule
Prevents premature channel deletion after signature publication
Guards against loss of funds/tracking if peer broadcasts funding tx after abort
Adds defensive logging for unusual abort-after-signatures cases
Cherry-pick from upstream fix indicates backport of a recognized correction
Evidence from the diff
The commit guards channel deletion paths with a new i_sent_sigs / channel_funding_sigs_sent() flag. Once tx_signatures have been sent during a dual-funded channel open, BOLT #2 requires the receiving node to retain the channel until any input of the negotiated funding transaction has been spent. The patch prevents delete_channel(), channel_fail_forget(), and inflight cleanup from running after signatures are sent, and adds logging when tx_abort is received after signatures have been transmitted. It also clarifies the protocol error condition: tx_abort after the peer’s tx_signatures is a fatal protocol violation, whereas tx_abort after our own tx_signatures must be remembered, not forgotten.
Changed components
lightningd/channel.clightningd/dual_open_control.copeningd/dualopend.cInspect captured patch +44 / −5
### lightningd/channel.c
@@ -138,6 +138,11 @@ bool maybe_cleanup_last_inflight(struct channel *channel)
if (inflight->last_tx)
return false;
+ /* Don't drop an inflight we already signed (BOLT #2 tx_abort
+ * receiver rule). */
+ if (inflight->i_sent_sigs)
+ return false;
+
/* Remove from database */
wallet_channel_inflight_cleanup_incomplete(
channel->peer->ld->wallet, channel->dbid);
@@ -1114,6 +1119,15 @@ static void channel_fail_perm(struct channel *channel,
/* FIXME: We only implement a subset of this; we keep waiting
* as long as it was finished opening. */
if (channel_state_open_uncommitted(channel->state)) {
+ /* If we already sent tx_signatures we must not forget the
+ * channel until an input of the negotiated tx is spent (the
+ * BOLT #2 tx_abort receiver rule). */
+ if (channel_funding_sigs_sent(channel)) {
+ log_unusual(channel->log,
+ "Already sent tx_signatures, remembering"
+ " channel after permanent failure");
+ return;
+ }
delete_channel(channel, false);
return;
}
### lightningd/dual_open_control.c
@@ -4044,7 +4044,8 @@ static void dualopen_errmsg(struct channel *channel,
delete_channel(channel, false);
return;
}
- if ((warning || disconnect) && channel_state_open_uncommitted(channel->state)) {
+ if ((warning || disconnect) && channel_state_open_uncommitted(channel->state)
+ && !channel_funding_sigs_sent(channel)) {
log_info(channel->log, "%s", "Commit ready peer failed."
" Deleting channel.");
delete_channel(channel, false);
@@ -4088,12 +4089,16 @@ static void dualopen_errmsg(struct channel *channel,
if (!disconnect) {
- if (channel_state_open_uncommitted(channel->state)) {
+ if (channel_state_open_uncommitted(channel->state)
+ && !channel_funding_sigs_sent(channel)) {
log_info(channel->log, "%s", "Commit ready peer can't reconnect."
" Deleting channel.");
delete_channel(channel, false);
return;
}
+ if (channel_funding_sigs_sent(channel))
+ log_info(channel->log,
+ "Already sent tx_signatures, remembering channel");
char *err = restart_dualopend(tmpctx,
channel->peer->ld,
channel, true);
@@ -4136,7 +4141,8 @@ static void dualopen_errmsg(struct channel *channel,
/* FIXME: We don't close all channels */
/* We should immediately forget the channel if we receive error during
* CHANNELD_AWAITING_LOCKIN if we are fundee. */
- if (!err_for_them && channel_state_open_uncommitted(channel->state))
+ if (!err_for_them && channel_state_open_uncommitted(channel->state)
+ && !channel_funding_sigs_sent(channel))
channel_fail_forget(channel, "%s: %s ERROR %s",
channel->owner->name,
err_for_them ? "sent" : "received", desc);
### openingd/dualopend.c
@@ -1590,12 +1590,31 @@ static void handle_tx_abort(struct state *state, u8 *msg)
* process without worrying about stale messages.
*/
if (!state->aborted_err) {
- /* If they sent this after tx-sigs, it's a
- * protocol error */
+ /* If they sent this after their tx-sigs, it's a
+ * protocol error (they MUST NOT send tx_abort after
+ * transmitting tx_signatures). */
if (state->tx_state->remote_funding_sigs_rcvd)
open_err_fatal(state, "tx-abort rcvd after"
" tx-sigs");
+ /* BOLT #2:
+ *
+ * A receiving node:
+ * - if they have already sent `tx_signatures` to the peer:
+ * - MUST NOT forget the channel until any inputs to the
+ * negotiated tx have been spent.
+ * - if they have not sent `tx_signatures`:
+ * - SHOULD forget the current negotiation and reset their
+ * state.
+ */
+ /* We echo the abort either way; if we already sent our
+ * signatures the peer may still broadcast, so lightningd
+ * must remember the channel (it checks our sigs-sent flag
+ * before deleting anything). */
+ if (state->tx_state->local_funding_sigs_sent)
+ status_unusual("tx-abort rcvd after we sent tx-sigs;"
+ " remembering channel");
+
open_abort(state, "%s", "Rcvd tx-abort");
desc = tal_fmt(tmpctx, "They sent %s",
sanitize_error(tmpctx, msg, NULL));Why 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.