Skip to content

Commit 739832e

Browse files
committed
Make PaymentFailureReason downgradable
The PaymentFailureReason variants for invoice request failures will cause downgrades to break. Instead, use a new TLV for the reason and continue to write the old TLV, only use None for the new reasons.
1 parent 4350290 commit 739832e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lightning/src/events/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,10 +1555,17 @@ impl Writeable for Event {
15551555
Some(payment_hash) => payment_hash,
15561556
None => &PaymentHash([0; 32]),
15571557
};
1558+
let legacy_reason = match reason {
1559+
Some(PaymentFailureReason::UnknownRequiredFeatures)
1560+
| Some(PaymentFailureReason::InvoiceRequestExpired)
1561+
| Some(PaymentFailureReason::InvoiceRequestRejected) => &None,
1562+
reason => reason,
1563+
};
15581564
write_tlv_fields!(writer, {
15591565
(0, payment_id, required),
1560-
(1, reason, option),
1566+
(1, legacy_reason, option),
15611567
(2, payment_hash, required),
1568+
(3, reason, option),
15621569
})
15631570
},
15641571
&Event::OpenChannelRequest { .. } => {
@@ -1926,12 +1933,15 @@ impl MaybeReadable for Event {
19261933
let mut payment_hash = PaymentHash([0; 32]);
19271934
let mut payment_id = PaymentId([0; 32]);
19281935
let mut reason = None;
1936+
let mut legacy_reason = None;
19291937
read_tlv_fields!(reader, {
19301938
(0, payment_id, required),
1931-
(1, reason, upgradable_option),
1939+
(1, legacy_reason, upgradable_option),
19321940
(2, payment_hash, required),
1941+
(3, reason, upgradable_option),
19331942
});
19341943
let invoice_received = payment_hash != PaymentHash([0; 32]);
1944+
let reason = reason.or(legacy_reason);
19351945
Ok(Some(Event::PaymentFailed {
19361946
payment_id,
19371947
payment_hash: invoice_received.then(|| payment_hash),

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
* Any `Event::PaymentFailed` generated without a payment hash will deserialize
1111
with `PaymentHash([0; 32])` when downgrading. This can be treated like an
1212
`Event::InvoiceRequestFailed` (#3192).
13+
* 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).

0 commit comments

Comments
 (0)