Skip to content

Commit 74c0ec3

Browse files
committed
f - map PaymentFailureReason
1 parent 57219a6 commit 74c0ec3

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lightning/src/events/mod.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ impl_writeable_tlv_based_enum!(InterceptNextHop,
502502
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
503503
pub enum PaymentFailureReason {
504504
/// The intended recipient rejected our payment.
505+
///
506+
/// Also used for [`UnknownRequiredFeatures`] and [`InvoiceRequestRejected`] when downgrading to
507+
/// version prior to 0.0.124.
508+
///
509+
/// [`UnknownRequiredFeatures`]: Self::UnknownRequiredFeatures
510+
/// [`InvoiceRequestRejected`]: Self::InvoiceRequestRejected
505511
RecipientRejected,
506512
/// The user chose to abandon this payment by calling [`ChannelManager::abandon_payment`].
507513
///
@@ -517,7 +523,10 @@ pub enum PaymentFailureReason {
517523
/// The payment expired while retrying, based on the provided
518524
/// [`PaymentParameters::expiry_time`].
519525
///
526+
/// Also used for [`InvoiceRequestExpired`] when downgrading to version prior to 0.0.124.
527+
///
520528
/// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
529+
/// [`InvoiceRequestExpired`]: Self::InvoiceRequestExpired
521530
PaymentExpired,
522531
/// We failed to find a route while retrying the payment.
523532
///
@@ -1556,10 +1565,22 @@ impl Writeable for Event {
15561565
None => (&PaymentHash([0; 32]), false),
15571566
};
15581567
let legacy_reason = match reason {
1559-
Some(PaymentFailureReason::UnknownRequiredFeatures)
1560-
| Some(PaymentFailureReason::InvoiceRequestExpired)
1561-
| Some(PaymentFailureReason::InvoiceRequestRejected) => &None,
1562-
reason => reason,
1568+
None => &None,
1569+
// Variants available prior to version 0.0.124.
1570+
Some(PaymentFailureReason::RecipientRejected)
1571+
| Some(PaymentFailureReason::UserAbandoned)
1572+
| Some(PaymentFailureReason::RetriesExhausted)
1573+
| Some(PaymentFailureReason::PaymentExpired)
1574+
| Some(PaymentFailureReason::RouteNotFound)
1575+
| Some(PaymentFailureReason::UnexpectedError) => reason,
1576+
// Variants introduced at version 0.0.124 or later. Prior versions fail to parse
1577+
// unknown variants, while versions 0.0.124 or later will use None.
1578+
Some(PaymentFailureReason::UnknownRequiredFeatures) =>
1579+
&Some(PaymentFailureReason::RecipientRejected),
1580+
Some(PaymentFailureReason::InvoiceRequestExpired) =>
1581+
&Some(PaymentFailureReason::RetriesExhausted),
1582+
Some(PaymentFailureReason::InvoiceRequestRejected) =>
1583+
&Some(PaymentFailureReason::RecipientRejected),
15631584
};
15641585
write_tlv_fields!(writer, {
15651586
(0, payment_id, required),

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
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 deserialize with reason `None` after downgrading
15-
to a version prior to 0.0.124: `UnknownRequiredFeatures`,
16-
`InvoiceRequestExpired`, or `InvoiceRequestRejected` (#3192).
14+
`PaymentFailureReason`s will deserialize with the corresponding reason after
15+
downgrading to a version prior to 0.0.124:
16+
- `UnknownRequiredFeatures` to `RecipientRejected`,
17+
- `InvoiceRequestExpired` to `RetriesExhausted`, and
18+
- `InvoiceRequestRejected` to `RecipientRejected` (#3192).

0 commit comments

Comments
 (0)