Skip to content

Commit 8f10f90

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 b088b35 commit 8f10f90

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/event.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,26 @@ where
691691
if info.status == PaymentStatus::Succeeded
692692
|| matches!(info.kind, PaymentKind::Spontaneous { .. })
693693
{
694+
let stored_preimage = match info.kind {
695+
PaymentKind::Bolt11 { preimage, .. }
696+
| PaymentKind::Bolt11Jit { preimage, .. }
697+
| PaymentKind::Bolt12Offer { preimage, .. }
698+
| PaymentKind::Bolt12Refund { preimage, .. }
699+
| PaymentKind::Spontaneous { preimage, .. } => preimage,
700+
_ => None,
701+
};
702+
703+
if let Some(preimage) = stored_preimage {
704+
log_info!(
705+
self.logger,
706+
"Re-claiming previously succeeded payment with hash {} of {}msat",
707+
hex_utils::to_string(&payment_hash.0),
708+
amount_msat,
709+
);
710+
self.channel_manager.claim_funds(preimage);
711+
return Ok(());
712+
}
713+
694714
log_info!(
695715
self.logger,
696716
"Refused duplicate inbound payment from payment hash {} of {}msat",

0 commit comments

Comments
 (0)