AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 57 Bitcoin

Abandon claims of irrevocably spent HTLC outputs

Public commit record

What the developer wrote

Authored by SaidAlaoui

80/100 · Strong
Abandon claims of irrevocably spent HTLC outputs

When a `ChannelMonitor` learns a preimage after a commitment
transaction confirms, it builds the claims of all HTLC outputs on that
transaction again. It removes duplicates only against the outpoints
which it still tracks. Once the spend of an HTLC output has
`ANTI_REORG_DELAY` confirmations, the outpoint is no longer tracked,
so the claim is registered again. `ChannelManager::read` replays
stored preimages on every load, so a restart is enough to create such
a claim. The claim can never confirm, but it stays in the monitor and
we yield it again on every rebroadcast.

On every block, `ChannelMonitor` now passes the outputs of the confirmed
commitment transaction which have an irrevocable spend to
`OnchainTxHandler::abandon_spent_outpoints`. A spend is irrevocable when
its HTLC is in `htlcs_resolved_on_chain`, or when its
`HTLCSpendConfirmation` has `ANTI_REORG_DELAY` confirmations. The second
case covers our own HTLC-Success transactions on our commitment
transaction, which wait for the CSV delay before their HTLC is in
`htlcs_resolved_on_chain`. A claim which only spends such outputs is
dropped, along with the `claimable_outpoints` entries of any outpoints
split out of it earlier, which would otherwise make us panic if we saw
their spends again. A claim which also spends other outputs is split,
and its timer is set to the current height, so that we build the claim
of the other outputs again in the same block. This also removes such
claims from monitors which were persisted with them.

This also drops the HTLC-Timeout claims of non-anchor channels for
HTLC outputs which our counterparty claimed with the preimage. Those
packages cannot be split, so they stayed in `locktimed_packages`, and
we broadcast an HTLC-Timeout transaction which could never confirm at
the HTLC expiry. `test_htlc_on_chain_success` and
`retry_with_no_persist` expected those broadcasts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit fixes a bug in the Lightning Dev Kit where the wallet could keep trying to claim bitcoin that was already spent by someone else. After a channel closes on-chain, the code normally tries to grab any HTLC outputs it can. A bug caused it to recreate already-impossible claims every time it learned a new payment secret or restarted, because it only avoided duplicate claims for outputs it was still actively tracking. Once an output's spend was buried under enough confirmations, it was dropped from tracking, so the old claim was added again. These impossible claims could never confirm, but they stayed in the monitor forever and were re-broadcast repeatedly. In rare cases they could also trigger a panic if a previously-split claim later saw its output spent again. The fix detects outputs that are already irreversibly spent and tells the on-chain transaction handler to abandon those claims, splitting or dropping them as needed.

Recommended action

Review and merge the patch, then backport to supported release branches. Operators should upgrade nodes that may have persisted stale claims from older versions, as the fix also cleans up already-persisted invalid claims on block connection. No immediate on-chain funds are at risk, but upgrade avoids rebroadcast noise and possible monitor panics.

Security signals we found

01

Denial-of-service via persistent invalid on-chain claims that bloat the monitor and are rebroadcast forever

02

Potential panic when a claim split out earlier sees its spent output again because claimable_outpoints still maps to the old claim

03

State inconsistency after restart because ChannelManager::read replays preimages, recreating abandoned claims

04

Fix removes impossible HTLC-Timeout broadcasts for outputs already claimed by counterparty with preimage

05

New defensive cleanup of claimable_outpoints entries for removed claims

Risk score

Why this scored 57/100

Our methodology →
Potential impact 18/30
Exploitability 8/25
Stealth signal 7/15
Affected reach 12/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.