Skip to content

Commit 0552a46

Browse files
committed
Make PaymentFailureReason upgradable
This allows downgrading to version 0.0.124 or later and using None for a PaymentFailureReason that was added after.
1 parent 08f33cf commit 0552a46

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

lightning/src/events/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ pub enum PaymentFailureReason {
538538
InvoiceRequestRejected,
539539
}
540540

541-
impl_writeable_tlv_based_enum!(PaymentFailureReason,
541+
impl_writeable_tlv_based_enum_upgradable!(PaymentFailureReason,
542542
(0, RecipientRejected) => {},
543543
(1, UnknownRequiredFeatures) => {},
544544
(2, UserAbandoned) => {},
@@ -878,8 +878,9 @@ pub enum Event {
878878
/// [`Offer`]: crate::offers::offer::Offer
879879
payment_hash: Option<PaymentHash>,
880880
/// The reason the payment failed. This is only `None` for events generated or serialized
881-
/// by versions prior to 0.0.115 or when deserializing an `Event::InvoiceRequestFailed`,
882-
/// which was removed in 0.0.124.
881+
/// by versions prior to 0.0.115, when deserializing an `Event::InvoiceRequestFailed`, which
882+
/// was removed in 0.0.124, or when downgrading to 0.0.124 or later with a reason that was
883+
/// added after.
883884
reason: Option<PaymentFailureReason>,
884885
},
885886
/// Indicates that a path for an outbound payment was successful.
@@ -1932,7 +1933,7 @@ impl MaybeReadable for Event {
19321933
Ok(Some(Event::PaymentFailed {
19331934
payment_id,
19341935
payment_hash: invoice_received.then(|| payment_hash),
1935-
reason,
1936+
reason: _init_tlv_based_struct_field!(reason, upgradable_option),
19361937
}))
19371938
};
19381939
f()

lightning/src/ln/outbound_payment.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ pub(crate) enum PendingOutboundPayment {
9696
Abandoned {
9797
session_privs: HashSet<[u8; 32]>,
9898
payment_hash: PaymentHash,
99-
/// Will be `None` if the payment was serialized before 0.0.115.
99+
/// Will be `None` if the payment was serialized before 0.0.115 or if downgrading to 0.0.124
100+
/// or later with a reason that was added after.
100101
reason: Option<PaymentFailureReason>,
101102
},
102103
}
@@ -1940,7 +1941,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
19401941
},
19411942
(3, Abandoned) => {
19421943
(0, session_privs, required),
1943-
(1, reason, option),
1944+
(1, reason, upgradable_option),
19441945
(2, payment_hash, required),
19451946
},
19461947
(5, AwaitingInvoice) => {

pending_changelog/3192-invoice-request-failed-event.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
with `PaymentHash([0; 32])` when downgrading. This can be treated like an
1212
`Event::InvoiceRequestFailed` (#3192).
1313
* An `Event::PaymentFailed` generated with one of the following
14-
`PaymentFailureReason`s will fail to deserialize after downgrading:
15-
`UnknownRequiredFeatures`, `InvoiceRequestExpired`, or
16-
`InvoiceRequestRejected` (#3192).
14+
`PaymentFailureReason`s will fail to deserialize after downgrading to a
15+
version prior to 0.0.124: `UnknownRequiredFeatures`, `InvoiceRequestExpired`,
16+
or `InvoiceRequestRejected` (#3192).

0 commit comments

Comments
 (0)