From bb94320e4095b23e4bdc025ade7a59d181f47a90 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 7 Aug 2024 17:16:54 -0500 Subject: [PATCH] Make PaymentFailureReason upgradable This allows downgrading to version 0.0.124 or later and using None for a PaymentFailureReason that was added after. --- lightning/src/events/mod.rs | 7 ++++--- lightning/src/ln/outbound_payment.rs | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index b993de76e..938100a90 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -538,7 +538,7 @@ pub enum PaymentFailureReason { InvoiceRequestRejected, } -impl_writeable_tlv_based_enum!(PaymentFailureReason, +impl_writeable_tlv_based_enum_upgradable!(PaymentFailureReason, (0, RecipientRejected) => {}, (1, UnknownRequiredFeatures) => {}, (2, UserAbandoned) => {}, @@ -878,7 +878,8 @@ 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. + /// by versions prior to 0.0.115, or when downgrading to 0.0.124 or later with a reason that + /// was added after. reason: Option, }, /// Indicates that a path for an outbound payment was successful. @@ -1939,7 +1940,7 @@ impl MaybeReadable for Event { Ok(Some(Event::PaymentFailed { payment_id, payment_hash, - reason, + reason: _init_tlv_based_struct_field!(reason, upgradable_option), })) }; f() diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index a2e9e6b9b..c36f2c5c1 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -96,7 +96,8 @@ pub(crate) enum PendingOutboundPayment { Abandoned { session_privs: HashSet<[u8; 32]>, payment_hash: PaymentHash, - /// Will be `None` if the payment was serialized before 0.0.115. + /// Will be `None` if the payment was serialized before 0.0.115 or if downgrading to 0.0.124 + /// or later with a reason that was added after. reason: Option, }, } @@ -1940,7 +1941,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment, }, (3, Abandoned) => { (0, session_privs, required), - (1, reason, option), + (1, reason, upgradable_option), (2, payment_hash, required), }, (5, AwaitingInvoice) => { -- 2.39.5