Skip to content

Commit 9443083

Browse files
joostjagerclaude
andcommitted
Re-claim inbound payments when preimage is already known
When a PaymentClaimable event arrives for a payment already marked as Succeeded or Spontaneous in the payment store, re-claim using the stored preimage instead of failing the HTLC backwards. This prevents fund loss in scenarios where the channel monitor state was not yet persisted (e.g. with deferred monitor writes) but the payment store already recorded the claim as successful. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a1adae5 commit 9443083

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/event.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,26 @@ where
669669
if info.status == PaymentStatus::Succeeded
670670
|| matches!(info.kind, PaymentKind::Spontaneous { .. })
671671
{
672+
let stored_preimage = match info.kind {
673+
PaymentKind::Bolt11 { preimage, .. }
674+
| PaymentKind::Bolt11Jit { preimage, .. }
675+
| PaymentKind::Bolt12Offer { preimage, .. }
676+
| PaymentKind::Bolt12Refund { preimage, .. }
677+
| PaymentKind::Spontaneous { preimage, .. } => preimage,
678+
_ => None,
679+
};
680+
681+
if let Some(preimage) = stored_preimage {
682+
log_info!(
683+
self.logger,
684+
"Re-claiming previously succeeded payment with hash {} of {}msat",
685+
hex_utils::to_string(&payment_hash.0),
686+
amount_msat,
687+
);
688+
self.channel_manager.claim_funds(preimage);
689+
return Ok(());
690+
}
691+
672692
log_info!(
673693
self.logger,
674694
"Refused duplicate inbound payment from payment hash {} of {}msat",

0 commit comments

Comments
 (0)