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

Handle claim replay for payments which reused a payment hash

Public commit record

What the developer wrote

Authored by Matt Corallo

85/100 · Strong
Handle claim replay for payments which reused a payment hash

A payment hash may be paid, and claimed, more than once, leaving
several claims for it in a `ChannelMonitor`. On `ChannelManager` load
we replayed such claims matching them against `claimable_payments`
and `pending_claiming_payments` only by payment hash. As a result:

* if the first replayed claim's `PaymentClaimed` was delayed (the
channel was closed or had a `ChannelMonitorUpdate` in flight), the
second claim's replay found its `pending_claiming_payments` entry
and `ChannelManager::read` failed on every startup,
* a different, unclaimed, payment with the same payment hash was
dropped from `claimable_payments` and reported as claimed without
its HTLCs being claimed.

Because a replayed claim is durably in a `ChannelMonitor`, and thus
replayed again on the next startup, we don't need to wait on its
`ChannelMonitorUpdate`s to generate the `PaymentClaimed`. Thus, we
now generate it immediately and no longer track replayed claims in
`pending_claiming_payments`. We also only drop a payment from
`claimable_payments` if it shares an HTLC with the replayed claim,
i.e. it is a stale copy of the claimed payment.

Further, `MonitorUpdateCompletionAction::PaymentClaimed` identified
its payment only by payment hash, so an action completing after a
different payment with the same payment hash began being claimed
generated that payment's `PaymentClaimed` before its preimage was
durable. It now carries the claim's `PaymentId` and only generates
the event for a matching payment.

Note that a `ChannelManager` reloaded again before its startup
`ChannelMonitorUpdate`s complete now generates another redundant
preimage update for each closed channel in a replayed claim.

Thanks to Erick Cestari for reporting this issue.

Co-Authored-By: Claude <noreply@anthropic.com>
✓ Specific, 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 LDK (a Lightning Network implementation in Rust) where the same payment hash could be used for multiple payments. On restart, the software could either crash repeatedly or incorrectly mark a different, unclaimed payment as already claimed. The fix makes sure each payment is tracked by its unique ID, not just by its payment hash, so claims are replayed correctly after a restart.

Recommended action

Review and merge the patch. Run the new regression tests covering reused payment hash scenarios. Consider whether any deployed nodes may have persisted inconsistent state from prior versions and advise operators to upgrade before restarting.

Security signals we found

01

Payment hash collision handling bug

02

ChannelManager deserialization failure on startup

03

Incorrect PaymentClaimed event generation for wrong payment

04

Stale claimable payment not removed correctly

05

MonitorUpdateCompletionAction now keyed by PaymentId

06

Claim replay logic hardened against reused payment hashes

Risk score

Why this scored 66/100

Our methodology →
Potential impact 22/30
Exploitability 12/25
Stealth signal 10/15
Affected reach 10/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.