Skip to content

Commit fbce6d6

Browse files
committed
Add an InvoiceRequestFailed event
When an invoice is requested but either receives an error or never receives a response, surface an event to indicate to the user that the corresponding future payment has failed.
1 parent 072a6ff commit fbce6d6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lightning/src/events/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ pub enum Event {
508508
/// serialized prior to LDK version 0.0.117.
509509
sender_intended_total_msat: Option<u64>,
510510
},
511+
/// Indicates a request for an invoice failed to yield a response in a reasonable amount of time
512+
/// or was explicitly abandoned by [`ChannelManager::abandon_payment`].
513+
///
514+
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
515+
InvoiceRequestFailed {
516+
/// The `payment_id` to have been associated with payment for the requested invoice.
517+
payment_id: PaymentId,
518+
},
511519
/// Indicates an outbound payment we made succeeded (i.e. it made it all the way to its target
512520
/// and we got back the payment preimage for it).
513521
///
@@ -1148,6 +1156,12 @@ impl Writeable for Event {
11481156
(8, funding_txo, required),
11491157
});
11501158
},
1159+
&Event::InvoiceRequestFailed { ref payment_id } => {
1160+
33u8.write(writer)?;
1161+
write_tlv_fields!(writer, {
1162+
(0, payment_id, required),
1163+
})
1164+
},
11511165
// Note that, going forward, all new events must only write data inside of
11521166
// `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
11531167
// data via `write_tlv_fields`.
@@ -1535,6 +1549,17 @@ impl MaybeReadable for Event {
15351549
};
15361550
f()
15371551
},
1552+
33u8 => {
1553+
let f = || {
1554+
_init_and_read_len_prefixed_tlv_fields!(reader, {
1555+
(0, payment_id, required),
1556+
});
1557+
Ok(Some(Event::InvoiceRequestFailed {
1558+
payment_id: payment_id.0.unwrap(),
1559+
}))
1560+
};
1561+
f()
1562+
},
15381563
// Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
15391564
// Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
15401565
// reads.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Backwards Compatibility
2+
3+
* If an `Event::InvoiceRequestFailed` was generated for a BOLT 12 payment (#2371), downgrading will result in the payment silently failing if the event had not been processed yet.

0 commit comments

Comments
 (0)