channeld: tell lightningd the HTLC sigs for a splice's first commitment
What changed, and why it matters
This patch fixes a bug in Core Lightning's channel splicing feature. When a Bitcoin Lightning channel is being spliced (a fancy way of resizing the channel while it stays open), the software was forgetting to save the peer's signatures for any pending HTLC payments on the very first version of the new commitment transaction. If the channel later closed using that commitment, the node might not be able to claim its funds from those pending payments on the blockchain, potentially leading to loss of money. The fix makes sure those signatures are passed along and stored in the wallet database.
Apply the patch. Nodes that support Lightning channel splicing should upgrade, especially if they handle HTLCs across splice operations. Monitor for any on-chain close scenarios involving pending HTLCs during a splice and verify HTLC signature storage completeness.
Security signals we found
Missing cryptographic material (HTLC signatures) for a commitment transaction
Potential inability to spend HTLC outputs on channel close or splice lock
Funds-at-risk scenario for pending HTLCs during a splice
Patch adds persistence of HTLC signatures for splice inflight commitments
Changelog-None: vendor did not flag security relevance in commit message
Evidence from the diff
During splice negotiation, channeld_update_inflight carries the new inflight commitment and its signature to lightningd, but previously omitted the peer’s HTLC signatures for that first commitment. Later commitment updates store HTLC sigs via got_commitsig, but the splice’s initial commitment did not. Once splice_locked promotes inflight sigs, or if the channel closes on the splice before splice_locked, the missing HTLC signatures mean onchaind cannot spend the HTLC outputs. The patch adds htlc_sigs to the channeld_update_inflight wire message, updates handlers to persist them via a new wallet_inflight_htlc_sigs_save() function that atomically deletes old sigs and inserts new ones, and ensures a resent update without a commitment cannot wipe stored sigs.
Changed components
channeld/channeld.cchanneld/channeld_wire.csvlightningd/channel_control.cwallet/wallet.cwallet/wallet.hInspect captured patch +43 / −7
### channeld/channeld.c
@@ -3950,6 +3950,7 @@ static void resume_splice_negotiation(struct peer *peer,
msg = towire_channeld_update_inflight(NULL, current_psbt,
their_commit->tx,
&their_commit->commit_signature,
+ their_commit->htlc_signatures,
inflight->locked_scid,
inflight->i_sent_sigs);
wire_sync_write(MASTER_FD, take(msg));
@@ -4022,7 +4023,7 @@ static void resume_splice_negotiation(struct peer *peer,
inflight->force_sign_first)
&& send_signature) {
msg = towire_channeld_update_inflight(NULL, current_psbt,
- NULL, NULL,
+ NULL, NULL, NULL,
inflight->locked_scid,
inflight->i_sent_sigs);
wire_sync_write(MASTER_FD, take(msg));
@@ -4201,7 +4202,7 @@ static void resume_splice_negotiation(struct peer *peer,
if (recv_signature || send_signature) {
/* We let core validate our peer's signatures are correct. */
msg = towire_channeld_update_inflight(NULL, current_psbt, NULL,
- NULL,
+ NULL, NULL,
inflight->locked_scid,
inflight->i_sent_sigs);
wire_sync_write(MASTER_FD, take(msg));
@@ -4844,6 +4845,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
outmsg = towire_channeld_update_inflight(NULL, new_inflight->psbt,
their_commit->tx,
&their_commit->commit_signature,
+ their_commit->htlc_signatures,
new_inflight->locked_scid,
new_inflight->i_sent_sigs);
wire_sync_write(MASTER_FD, take(outmsg));
@@ -5040,8 +5042,7 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg)
/* Save the user provided signatures to DB incase we have to
* restart and reestablish later. */
outmsg = towire_channeld_update_inflight(NULL, inflight->psbt,
- inflight->last_tx,
- &inflight->last_sig,
+ NULL, NULL, NULL,
inflight->locked_scid,
inflight->i_sent_sigs);
@@ -6443,6 +6444,7 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
inflight->psbt,
NULL,
NULL,
+ NULL,
inflight->locked_scid,
inflight->i_sent_sigs);
wire_sync_write(MASTER_FD, take(msg));
### channeld/channeld_wire.csv
@@ -280,6 +280,9 @@ msgtype,channeld_update_inflight,7219
msgdata,channeld_update_inflight,psbt,wally_psbt,
msgdata,channeld_update_inflight,last_tx,?bitcoin_tx,
msgdata,channeld_update_inflight,last_sig,?bitcoin_signature,
+# If last_tx is set, their HTLC signatures for it.
+msgdata,channeld_update_inflight,num_htlc_sigs,u16,
+msgdata,channeld_update_inflight,htlc_sigs,bitcoin_signature,num_htlc_sigs
msgdata,channeld_update_inflight,locked_scid,?short_channel_id,
msgdata,channeld_update_inflight,i_sent_sigs,bool,
### lightningd/channel_control.c
@@ -970,13 +970,13 @@ static void handle_update_inflight(struct lightningd *ld,
struct wally_psbt *psbt;
struct bitcoin_txid txid;
struct bitcoin_tx *last_tx;
- struct bitcoin_signature *last_sig;
+ struct bitcoin_signature *last_sig, *htlc_sigs;
struct short_channel_id *locked_scid;
bool i_sent_sigs;
if (!fromwire_channeld_update_inflight(tmpctx, msg, &psbt, &last_tx,
- &last_sig, &locked_scid,
- &i_sent_sigs)) {
+ &last_sig, &htlc_sigs,
+ &locked_scid, &i_sent_sigs)) {
channel_internal_error(channel,
"bad channel_add_inflight %s",
tal_hex(channel, msg));
@@ -1003,6 +1003,11 @@ static void handle_update_inflight(struct lightningd *ld,
if (last_tx) {
tal_free(inflight->last_tx);
inflight->last_tx = clone_bitcoin_tx(inflight, last_tx);
+ /* Its HTLC outputs need their sigs too, should we ever
+ * close with it. */
+ wallet_inflight_htlc_sigs_save(ld->wallet, channel->dbid,
+ &inflight->funding->outpoint,
+ htlc_sigs);
}
if (last_sig)
### wallet/wallet.c
@@ -4783,6 +4783,24 @@ void wallet_htlc_sigs_add(struct wallet *w, u64 channel_id,
}
}
+void wallet_inflight_htlc_sigs_save(struct wallet *w, u64 channel_id,
+ const struct bitcoin_outpoint *inflight_outpoint,
+ const struct bitcoin_signature *htlc_sigs)
+{
+ struct db_stmt *stmt;
+
+ stmt = db_prepare_v2(w->db, SQL("DELETE FROM htlc_sigs"
+ " WHERE channelid=?"
+ " AND inflight_tx_id=?"
+ " AND inflight_tx_outnum=?"));
+ db_bind_u64(stmt, channel_id);
+ db_bind_txid(stmt, &inflight_outpoint->txid);
+ db_bind_int(stmt, inflight_outpoint->n);
+ db_exec_prepared_v2(take(stmt));
+
+ wallet_htlc_sigs_add(w, channel_id, *inflight_outpoint, htlc_sigs);
+}
+
bool wallet_sanity_check(struct wallet *w)
{
struct bitcoin_blkid chainhash;
### wallet/wallet.h
@@ -1187,6 +1187,14 @@ void wallet_htlc_sigs_add(struct wallet *w, u64 channel_id,
struct bitcoin_outpoint inflight_outpoint,
const struct bitcoin_signature *htlc_sigs);
+/**
+ * wallet_inflight_htlc_sigs_save - Replace the HTLC sigs for an inflight splice.
+ * `inflight_outpoint` is the funding outpoint for the given splice.
+ */
+void wallet_inflight_htlc_sigs_save(struct wallet *w, u64 channel_id,
+ const struct bitcoin_outpoint *inflight_outpoint,
+ const struct bitcoin_signature *htlc_sigs);
+
/**
* wallet_sanity_check - Check that the wallet is setup for this node_id and chain
*Why this scored 64/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.