Skip to content

Commit d2df48a

Browse files
committed
Add PaymentFailureReason::InvoiceRequestRejected
Instead of re-using PaymentFailureReason::RecipientRejected, define a new InvoiceRequestRejected variant for when an InvoiceError is received instead of a Bolt12Invoice. This allows user to differentiate the cause of the failure.
1 parent e998a4f commit d2df48a

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lightning/src/events/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl_writeable_tlv_based_enum!(InterceptNextHop,
501501
/// The reason the payment failed. Used in [`Event::PaymentFailed`].
502502
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
503503
pub enum PaymentFailureReason {
504-
/// The intended recipient rejected our payment or invoice request.
504+
/// The intended recipient rejected our payment.
505505
RecipientRejected,
506506
/// The user chose to abandon this payment by calling [`ChannelManager::abandon_payment`].
507507
///
@@ -532,6 +532,10 @@ pub enum PaymentFailureReason {
532532
UnknownRequiredFeatures,
533533
/// A [`Bolt12Invoice`] was not received in a reasonable amount of time.
534534
InvoiceRequestExpired,
535+
/// An [`InvoiceRequest`] for the payment was rejected by the recipient.
536+
///
537+
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
538+
InvoiceRequestRejected,
535539
}
536540

537541
impl_writeable_tlv_based_enum!(PaymentFailureReason,
@@ -540,6 +544,7 @@ impl_writeable_tlv_based_enum!(PaymentFailureReason,
540544
(2, UserAbandoned) => {},
541545
(3, InvoiceRequestExpired) => {},
542546
(4, RetriesExhausted) => {},
547+
(5, InvoiceRequestRejected) => {},
543548
(6, PaymentExpired) => {},
544549
(8, RouteNotFound) => {},
545550
(10, UnexpectedError) => {},

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10897,7 +10897,7 @@ where
1089710897
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
1089810898
if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
1089910899
self.abandon_payment_with_reason(
10900-
payment_id, PaymentFailureReason::RecipientRejected,
10900+
payment_id, PaymentFailureReason::InvoiceRequestRejected,
1090110901
);
1090210902
}
1090310903
},

lightning/src/ln/offers_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,8 +1932,9 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
19321932

19331933
// Confirm that david drops this failed payment from his pending outbound payments.
19341934
match get_event!(david, Event::PaymentFailed) {
1935-
Event::PaymentFailed { payment_id: actual_payment_id, .. } => {
1935+
Event::PaymentFailed { payment_id: actual_payment_id, reason, .. } => {
19361936
assert_eq!(payment_id, actual_payment_id);
1937+
assert_eq!(reason, Some(PaymentFailureReason::InvoiceRequestRejected));
19371938
},
19381939
_ => panic!("No Event::PaymentFailed"),
19391940
}

0 commit comments

Comments
 (0)