lightningd: tidy dualopen_errmsg's forget-channel paths
What changed, and why it matters
This change refactors how Core Lightning cleans up unfinished channel openings when something goes wrong mid-negotiation. It funnels all 'forget this channel' paths through one helper that refuses to delete the channel once the node has already sent its transaction signatures. Before, the same safety check was repeated in several spots, which made it easier to accidentally skip it in future changes. The patch is a defensive hardening fix rather than a clear-cut vulnerability repair, but it directly enforces a protocol rule meant to prevent funds from being lost or stuck.
Treat as a low-to-moderate hardening patch. Review whether any other code paths outside dualopen_errmsg delete an in-progress dual-funding channel without using forget_channel_open(), and consider adding regression tests that simulate error/disconnect after tx_signatures are sent to confirm the channel is retained.
Security signals we found
Centralizes a safety invariant (do not delete channel after tx_signatures sent) into a single helper
Directly quotes and enforces BOLT #2 protocol requirement
Removes duplicated guards that could drift or be bypassed in future edits
Targets dual-funding channel open error handling, a sensitive state machine
No explicit bug or CVE described in commit message
Evidence from the diff
The commit introduces forget_channel_open() in lightningd/dual_open_control.c and routes all dualopen_errmsg deletion paths through it. The helper checks channel_funding_sigs_sent() and returns early if signatures have already been sent, thereby enforcing the BOLT #2 rule that a node MUST NOT forget a channel until any inputs to the negotiated tx have been spent. Previously, each deletion site duplicated the !channel_funding_sigs_sent() guard (or relied on the caller to supply it). The patch also merges duplicated BOLT #1 error-message quotes and moves a FIXME comment. It is a code-quality/hardening change with a clear security-relevant invariant.
Changed components
lightningd/dual_open_control.cdualopen_errmsg() state machinein-progress dual-funding channel open cleanupInspect captured patch +33 / −26
### lightningd/dual_open_control.c
@@ -4036,6 +4036,27 @@ AUTODATA(json_command, &openchannel_signed_command);
AUTODATA(json_command, &openchannel_bump_command);
AUTODATA(json_command, &openchannel_abort_command);
+/* 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.
+ */
+/* Every path in dualopen_errmsg which forgets a channel funnels through
+ * here, so the MUST NOT half of the rule above is enforced in a single
+ * place. Does nothing if we've already sent our tx_signatures. */
+static void forget_channel_open(struct channel *channel, const char *why)
+{
+ if (channel_funding_sigs_sent(channel))
+ return;
+
+ log_info(channel->log, "%s. Deleting channel.", why);
+ delete_channel(channel, false);
+}
+
static void dualopen_errmsg(struct channel *channel,
struct peer_fd *peer_fd,
const char *desc,
@@ -4046,17 +4067,16 @@ static void dualopen_errmsg(struct channel *channel,
/* Clean up any in-progress open attempts */
channel_cleanup_commands(channel, desc);
+ /* An unsaved channel has nothing to remember (and cannot have
+ * sent tx_signatures). */
if (channel_state_uncommitted(channel->state)) {
- log_info(channel->log, "%s", "Unsaved peer failed."
- " Deleting channel.");
- delete_channel(channel, false);
+ forget_channel_open(channel, "Unsaved peer failed");
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);
+ forget_channel_open(channel, "Commit ready peer failed");
return;
}
@@ -4099,20 +4119,16 @@ static void dualopen_errmsg(struct channel *channel,
if (!disconnect) {
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);
+ forget_channel_open(channel,
+ "Commit ready peer can't reconnect");
return;
}
- /* Negotiation was cleanly aborted after commitments
- * were exchanged, but before we sent tx_signatures:
- * safe to forget (BOLT #2 tx_abort sender rule). */
if (!warning
&& channel->state == DUALOPEND_OPEN_COMMITTED
&& !channel_funding_sigs_sent(channel)) {
- log_info(channel->log, "%s", "Open aborted before we sent"
- " tx_signatures. Deleting channel.");
- delete_channel(channel, false);
+ forget_channel_open(channel,
+ "Open aborted before we sent"
+ " tx_signatures");
return;
}
if (channel_funding_sigs_sent(channel))
@@ -4130,16 +4146,6 @@ static void dualopen_errmsg(struct channel *channel,
return;
}
- /* BOLT #1:
- *
- * A sending node:
- *...
- * - when sending `error`:
- * - MUST fail the channel(s) referred to by the error message.
- * - MAY set `channel_id` to all zero to indicate all channels.
- */
- /* FIXME: Close if it's an all-channels error sent or rcvd */
-
/* BOLT #1:
*
* A sending node:
@@ -4157,6 +4163,7 @@ static void dualopen_errmsg(struct channel *channel,
* sending node.
*/
+ /* FIXME: Close if it's an all-channels error sent or rcvd */
/* 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. */Why this scored 42/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.