Skip to content

Commit 3dcb4f4

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 3629c9c commit 3dcb4f4

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,11 +1555,18 @@ impl Writeable for Event {
15551555
Some(payment_hash) => (payment_hash, true),
15561556
None => (&PaymentHash([0; 32]), false),
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),
15621568
(3, invoice_received, required),
1569+
(5, reason, option),
15631570
})
15641571
},
15651572
&Event::OpenChannelRequest { .. } => {
@@ -1927,17 +1934,20 @@ impl MaybeReadable for Event {
19271934
let mut payment_hash = PaymentHash([0; 32]);
19281935
let mut payment_id = PaymentId([0; 32]);
19291936
let mut reason = None;
1937+
let mut legacy_reason = None;
19301938
let mut invoice_received: Option<bool> = None;
19311939
read_tlv_fields!(reader, {
19321940
(0, payment_id, required),
1933-
(1, reason, upgradable_option),
1941+
(1, legacy_reason, upgradable_option),
19341942
(2, payment_hash, required),
19351943
(3, invoice_received, option),
1944+
(5, reason, upgradable_option),
19361945
});
19371946
let payment_hash = match invoice_received {
19381947
Some(invoice_received) => invoice_received.then(|| payment_hash),
19391948
None => (payment_hash != PaymentHash([0; 32])).then(|| payment_hash),
19401949
};
1950+
let reason = reason.or(legacy_reason);
19411951
Ok(Some(Event::PaymentFailed {
19421952
payment_id,
19431953
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)