From: Jeffrey Czyz Date: Wed, 7 Aug 2024 22:16:54 +0000 (-0500) Subject: Make PaymentFailureReason upgradable X-Git-Tag: v0.0.124-beta~12^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=bb94320e4095b23e4bdc025ade7a59d181f47a90;p=rust-lightning Make PaymentFailureReason upgradable This allows downgrading to version 0.0.124 or later and using None for a PaymentFailureReason that was added after. --- 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) => {