]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add PaymentFailureReason::InvoiceRequestRejected
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 6 Aug 2024 23:33:51 +0000 (18:33 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 14 Aug 2024 15:55:59 +0000 (10:55 -0500)
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.

lightning/src/events/mod.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/offers_tests.rs

index 51bf7832ae5b08c5cdba28c742ac82a54f6a52bc..b993de76e668af81e3a177887cae0d2b22a494be 100644 (file)
@@ -501,7 +501,7 @@ impl_writeable_tlv_based_enum!(InterceptNextHop,
 /// The reason the payment failed. Used in [`Event::PaymentFailed`].
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
 pub enum PaymentFailureReason {
-       /// The intended recipient rejected our payment or invoice request.
+       /// The intended recipient rejected our payment.
        RecipientRejected,
        /// The user chose to abandon this payment by calling [`ChannelManager::abandon_payment`].
        ///
@@ -532,6 +532,10 @@ pub enum PaymentFailureReason {
        UnknownRequiredFeatures,
        /// A [`Bolt12Invoice`] was not received in a reasonable amount of time.
        InvoiceRequestExpired,
+       /// An [`InvoiceRequest`] for the payment was rejected by the recipient.
+       ///
+       /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
+       InvoiceRequestRejected,
 }
 
 impl_writeable_tlv_based_enum!(PaymentFailureReason,
@@ -540,6 +544,7 @@ impl_writeable_tlv_based_enum!(PaymentFailureReason,
        (2, UserAbandoned) => {},
        (3, InvoiceRequestExpired) => {},
        (4, RetriesExhausted) => {},
+       (5, InvoiceRequestRejected) => {},
        (6, PaymentExpired) => {},
        (8, RouteNotFound) => {},
        (10, UnexpectedError) => {},
index 267fb24552677921f67ce05e37eb479a64bc5d22..c6645956b18decbcad3639f91f5db1f9015d7c61 100644 (file)
@@ -10902,7 +10902,7 @@ where
                                        Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
                                                if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
                                                        self.abandon_payment_with_reason(
-                                                               payment_id, PaymentFailureReason::RecipientRejected,
+                                                               payment_id, PaymentFailureReason::InvoiceRequestRejected,
                                                        );
                                                }
                                        },
index b430196c4cf58a7c7901bcd4af823238c3b2c093..fd496b5f639cbd57cb8af24c6c4c05e1f90e179f 100644 (file)
@@ -1932,8 +1932,9 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
 
        // Confirm that david drops this failed payment from his pending outbound payments.
        match get_event!(david, Event::PaymentFailed) {
-               Event::PaymentFailed { payment_id: actual_payment_id, .. } => {
+               Event::PaymentFailed { payment_id: actual_payment_id, reason, .. } => {
                        assert_eq!(payment_id, actual_payment_id);
+                       assert_eq!(reason, Some(PaymentFailureReason::InvoiceRequestRejected));
                },
                _ => panic!("No Event::PaymentFailed"),
        }