lightningd: use a splice's HTLC sigs once we move onto its commitment
What changed, and why it matters
This fix repairs a bug in Core Lightning's splicing feature. When a channel was moved onto a new 'splice' commitment transaction, the old HTLC (multi-hop payment) signatures were still being used. If the channel later closed using that new splice commitment, the stored signatures could not actually spend the HTLC outputs, meaning the node could lose money it was owed. The patch makes sure the correct HTLC signatures are kept and used whenever the channel switches to a splice commitment.
Apply the patch and ensure nodes running splicing are upgraded. Operators who performed splices that confirmed but did not lock, and then closed the channel, should review on-chain history for any HTLC outputs that may have become unclaimable and consider manual recovery if possible.
Security signals we found
Loss of funds via invalid HTLC-timeout transactions after a splice close
Mismatched commitment transaction and HTLC signature state
State inconsistency between channel->last_tx and channel->last_htlc_sigs
Fix moves signature activation into the same code path that activates the commitment
Evidence from the diff
The bug is in how HTLC signatures are tracked across splice commitments. update_channel_from_inflight() updates channel->last_tx to a splice’s commitment both when splice_locked is received and when a splice output is spent before splice_locked. However, channel->last_htlc_sigs was not updated at the same time; it continued to hold the peer’s signatures for the pre-splice commitment until a later commitment update or restart. If the channel closed using the splice commitment, onchaind received mismatched HTLC signatures, making HTLC-timeout transactions invalid and causing loss of HTLC funds. The patch changes wallet_htlcsigs_confirm_inflight() to return the newly active HTLC signatures and has update_channel_from_inflight() assign them to channel->last_htlc_sigs when moving to a splice commitment. The call is removed from handle_peer_splice_locked() to avoid duplication.
Changed components
lightningd/channel_control.clightningd/peer_control.cwallet/wallet.cwallet/wallet.hlightningd/test/run-invoice-select-inchan.cwallet/test/run-wallet.cInspect captured patch +41 / −10
### lightningd/channel_control.c
@@ -1211,9 +1211,6 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
return;
}
- wallet_htlcsigs_confirm_inflight(channel->peer->ld->wallet, channel,
- &inflight->funding->outpoint);
-
/* Stash prev funding data so we can log it after scid is updated
* (to get the blockheight) */
prev_our_msats = channel->our_msat;
### lightningd/peer_control.c
@@ -2511,6 +2511,16 @@ void update_channel_from_inflight(struct lightningd *ld,
inflight->last_tx->psbt),
&inflight->last_sig);
+ /* The peer's HTLC sigs go with that commitment: onchaind needs them
+ * to spend its HTLC outputs if it's the one we close with. */
+ if (is_splice) {
+ tal_free(channel->last_htlc_sigs);
+ channel->last_htlc_sigs
+ = wallet_htlcsigs_confirm_inflight(channel, ld->wallet,
+ channel,
+ &inflight->funding->outpoint);
+ }
+
/* If the remote side rotated their pubkey during splice, update now */
if (inflight->funding->splice_remote_funding)
channel->channel_info.remote_fundingkey = *inflight->funding->splice_remote_funding;
### lightningd/test/run-invoice-select-inchan.c
@@ -708,6 +708,12 @@ bool wallet_htlcs_load_out_for_channel(struct wallet *wallet UNNEEDED,
struct htlc_out_map *htlcs_out UNNEEDED,
struct htlc_in_map *remaining_htlcs_in UNNEEDED)
{ fprintf(stderr, "wallet_htlcs_load_out_for_channel called!\n"); abort(); }
+/* Generated stub for wallet_htlcsigs_confirm_inflight */
+struct bitcoin_signature *wallet_htlcsigs_confirm_inflight(const tal_t *ctx UNNEEDED,
+ struct wallet *w UNNEEDED,
+ struct channel *chan UNNEEDED,
+ const struct bitcoin_outpoint *confirmed_outpoint UNNEEDED)
+{ fprintf(stderr, "wallet_htlcsigs_confirm_inflight called!\n"); abort(); }
/* Generated stub for wallet_init_channels */
bool wallet_init_channels(struct wallet *w UNNEEDED)
{ fprintf(stderr, "wallet_init_channels called!\n"); abort(); }
### wallet/test/run-wallet.c
@@ -1661,7 +1661,7 @@ static bool test_htlcsigs_confirm_inflight(struct wallet *w,
struct channel *chan)
{
struct bitcoin_outpoint winner, same_txid, same_outnum, neither;
- struct bitcoin_signature *active, *win, *lose, *loaded;
+ struct bitcoin_signature *active, *win, *lose, *loaded, *confirmed;
memset(&winner.txid, 1, sizeof(winner.txid));
winner.n = 0;
@@ -1689,12 +1689,14 @@ static bool test_htlcsigs_confirm_inflight(struct wallet *w,
/* The active set and all four inflight candidates were stored */
CHECK(count_htlc_sigs(w, chan->dbid) == 5);
- wallet_htlcsigs_confirm_inflight(w, chan, &winner);
+ confirmed = wallet_htlcsigs_confirm_inflight(tmpctx, w, chan, &winner);
- /* Winner's sigs are now the active set */
+ /* Winner's sigs are now the active set, and that's what we got back */
loaded = wallet_htlc_sigs_load(tmpctx, w, chan->dbid, false);
CHECK(tal_count(loaded) == 1);
CHECK(memeq(&loaded[0].s, sizeof(loaded[0].s), &win[0].s, sizeof(win[0].s)));
+ CHECK(tal_count(confirmed) == 1);
+ CHECK(memeq(&confirmed[0].s, sizeof(confirmed[0].s), &win[0].s, sizeof(win[0].s)));
/* Old active set and losing inflights are gone */
CHECK(count_htlc_sigs(w, chan->dbid) == 1);
### wallet/wallet.c
@@ -2631,8 +2631,10 @@ void wallet_announcement_save(struct wallet *w, u64 id,
}
-void wallet_htlcsigs_confirm_inflight(struct wallet *w, struct channel *chan,
- const struct bitcoin_outpoint *confirmed_outpoint)
+struct bitcoin_signature *
+wallet_htlcsigs_confirm_inflight(const tal_t *ctx,
+ struct wallet *w, struct channel *chan,
+ const struct bitcoin_outpoint *confirmed_outpoint)
{
struct db_stmt *stmt;
@@ -2657,6 +2659,9 @@ void wallet_htlcsigs_confirm_inflight(struct wallet *w, struct channel *chan,
" WHERE channelid=?"));
db_bind_u64(stmt, chan->dbid);
db_exec_prepared_v2(take(stmt));
+
+ return wallet_htlc_sigs_load(ctx, w, chan->dbid,
+ channel_type_has_anchors(chan->type));
}
void wallet_channel_save(struct wallet *w, struct channel *chan)
### wallet/wallet.h
@@ -647,8 +647,19 @@ bool wallet_shachain_add_hash(struct wallet *wallet,
*/
u64 wallet_get_channel_dbid(struct wallet *wallet);
-void wallet_htlcsigs_confirm_inflight(struct wallet *w, struct channel *chan,
- const struct bitcoin_outpoint *confirmed_outpoint);
+/**
+ * wallet_htlcsigs_confirm_inflight - Make an inflight's HTLC sigs the channel's
+ *
+ * Drops the HTLC sigs for the channel's current commitment and for every other
+ * inflight, keeping only those for @confirmed_outpoint's commitment.
+ *
+ * Returns those sigs, allocated off @ctx: they go with that commitment, so
+ * whoever moves the channel onto it needs them too.
+ */
+struct bitcoin_signature *wallet_htlcsigs_confirm_inflight(const tal_t *ctx,
+ struct wallet *w,
+ struct channel *chan,
+ const struct bitcoin_outpoint *confirmed_outpoint);
/**
* wallet_channel_save -- Upsert the channel into the databaseWhy this scored 68/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.