From: Jeffrey Czyz Date: Tue, 6 Aug 2024 23:33:51 +0000 (-0500) Subject: Add PaymentFailureReason::InvoiceRequestRejected X-Git-Tag: v0.0.124-beta~12^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=1563186c2b40098c1872d718ed75891c2a42c702;p=rust-lightning 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. --- diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 51bf7832a..b993de76e 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -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) => {}, diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 267fb2455..c6645956b 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -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, ); } }, diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index b430196c4..fd496b5f6 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -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"), }