]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Make PaymentFailureReason upgradable
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 7 Aug 2024 22:16:54 +0000 (17:16 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 14 Aug 2024 15:55:59 +0000 (10:55 -0500)
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
lightning/src/ln/outbound_payment.rs

index b993de76e668af81e3a177887cae0d2b22a494be..938100a901cb3f4740bde150670f42c7896406bb 100644 (file)
@@ -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<PaymentHash>,
                /// 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<PaymentFailureReason>,
        },
        /// 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()
index a2e9e6b9b01a3f8d400699142f8a5d2a1ad7dbb8..c36f2c5c1a931faf3c5ea0a6949b638c7cc601c9 100644 (file)
@@ -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<PaymentFailureReason>,
        },
 }
@@ -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) => {