]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add PaymentFailureReason::InvoiceRequestExpired
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 6 Aug 2024 23:13:45 +0000 (18:13 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 14 Aug 2024 15:55:59 +0000 (10:55 -0500)
Now that Event::PaymentFailed is generated when an InvoiceRequest times
out, define a new PaymentFailureReason for this situation.

lightning/src/events/mod.rs
lightning/src/ln/outbound_payment.rs

index 780713b331bfb6b4ccf0ff7217b8e421f9fc8bd0..51bf7832ae5b08c5cdba28c742ac82a54f6a52bc 100644 (file)
@@ -530,12 +530,15 @@ pub enum PaymentFailureReason {
        UnexpectedError,
        /// An invoice was received that required unknown features.
        UnknownRequiredFeatures,
+       /// A [`Bolt12Invoice`] was not received in a reasonable amount of time.
+       InvoiceRequestExpired,
 }
 
 impl_writeable_tlv_based_enum!(PaymentFailureReason,
        (0, RecipientRejected) => {},
        (1, UnknownRequiredFeatures) => {},
        (2, UserAbandoned) => {},
+       (3, InvoiceRequestExpired) => {},
        (4, RetriesExhausted) => {},
        (6, PaymentExpired) => {},
        (8, RouteNotFound) => {},
@@ -870,8 +873,7 @@ pub enum Event {
                /// [`Offer`]: crate::offers::offer::Offer
                payment_hash: Option<PaymentHash>,
                /// The reason the payment failed. This is only `None` for events generated or serialized
-               /// by versions prior to 0.0.115 or when deserializing an `Event::InvoiceRequestFailed`,
-               /// which was removed in 0.0.124.
+               /// by versions prior to 0.0.115.
                reason: Option<PaymentFailureReason>,
        },
        /// Indicates that a path for an outbound payment was successful.
@@ -2080,7 +2082,7 @@ impl MaybeReadable for Event {
                                        Ok(Some(Event::PaymentFailed {
                                                payment_id: payment_id.0.unwrap(),
                                                payment_hash: None,
-                                               reason: None,
+                                               reason: Some(PaymentFailureReason::InvoiceRequestExpired),
                                        }))
                                };
                                f()
index 6585dfbe67cd2e699a5f41fedb2c00bedc56f1ed..a2e9e6b9b01a3f8d400699142f8a5d2a1ad7dbb8 100644 (file)
@@ -1711,7 +1711,7 @@ impl OutboundPayments {
                                        let event = events::Event::PaymentFailed {
                                                payment_id: *payment_id,
                                                payment_hash: None,
-                                               reason: None,
+                                               reason: Some(PaymentFailureReason::InvoiceRequestExpired),
                                        };
                                        pending_events.push_back((event, None));
                                        false
@@ -2205,7 +2205,11 @@ mod tests {
                assert!(!pending_events.lock().unwrap().is_empty());
                assert_eq!(
                        pending_events.lock().unwrap().pop_front(),
-                       Some((Event::PaymentFailed { payment_id, payment_hash: None, reason: None }, None)),
+                       Some((Event::PaymentFailed {
+                               payment_id,
+                               payment_hash: None,
+                               reason: Some(PaymentFailureReason::InvoiceRequestExpired),
+                       }, None)),
                );
                assert!(pending_events.lock().unwrap().is_empty());
 
@@ -2254,7 +2258,11 @@ mod tests {
                assert!(!pending_events.lock().unwrap().is_empty());
                assert_eq!(
                        pending_events.lock().unwrap().pop_front(),
-                       Some((Event::PaymentFailed { payment_id, payment_hash: None, reason: None }, None)),
+                       Some((Event::PaymentFailed {
+                               payment_id,
+                               payment_hash: None,
+                               reason: Some(PaymentFailureReason::InvoiceRequestExpired),
+                       }, None)),
                );
                assert!(pending_events.lock().unwrap().is_empty());