From: Jeffrey Czyz Date: Tue, 6 Aug 2024 23:13:45 +0000 (-0500) Subject: Add PaymentFailureReason::InvoiceRequestExpired X-Git-Tag: v0.0.124-beta~12^2~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=457ba24ee5cfc66e756b298b323f107755278438;p=rust-lightning Add PaymentFailureReason::InvoiceRequestExpired Now that Event::PaymentFailed is generated when an InvoiceRequest times out, define a new PaymentFailureReason for this situation. --- diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 780713b33..51bf7832a 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -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, /// 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, }, /// 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() diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 6585dfbe6..a2e9e6b9b 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -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());