@@ -3477,6 +3477,35 @@ where
3477
3477
}
3478
3478
}
3479
3479
3480
+ /// This is a variant of [`ChannelManager::fail_htlc_backwards`] that allows you to specify the
3481
+ /// reason for the failure.
3482
+ ///
3483
+ /// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
3484
+ /// after a PaymentClaimable event, failing the HTLC back to its origin and freeing resources
3485
+ /// along the path (including in our own channel on which we received it).
3486
+ ///
3487
+ /// Note that in some cases around unclean shutdown, it is possible the payment may have
3488
+ /// already been claimed by you via [`ChannelManager::claim_funds`] prior to you seeing (a
3489
+ /// second copy of) the [`events::Event::PaymentClaimable`] event. Alternatively, the payment
3490
+ /// may have already been failed automatically by LDK if it was nearing its expiration time.
3491
+ ///
3492
+ /// While LDK will never claim a payment automatically on your behalf (i.e. without you calling
3493
+ /// [`ChannelManager::claim_funds`]), you should still monitor for
3494
+ /// [`events::Event::PaymentClaimed`] events even for payments you intend to fail, especially on
3495
+ /// startup during which time claims that were in-progress at shutdown may be replayed.
3496
+ pub fn fail_htlc_backwards_with_reason ( & self , payment_hash : & PaymentHash , reason : & HTLCFailReason ) {
3497
+ let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
3498
+
3499
+ let removed_source = self . claimable_payments . lock ( ) . unwrap ( ) . claimable_htlcs . remove ( payment_hash) ;
3500
+ if let Some ( ( _, mut sources) ) = removed_source {
3501
+ for htlc in sources. drain ( ..) {
3502
+ let source = HTLCSource :: PreviousHopData ( htlc. prev_hop ) ;
3503
+ let receiver = HTLCDestination :: FailedPayment { payment_hash : * payment_hash } ;
3504
+ self . fail_htlc_backwards_internal ( & source, & payment_hash, reason, receiver) ;
3505
+ }
3506
+ }
3507
+ }
3508
+
3480
3509
/// Gets an HTLC onion failure code and error data for an `UPDATE` error, given the error code
3481
3510
/// that we want to return and a channel.
3482
3511
///
0 commit comments