Skip to content

Commit 6d0c5f0

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 6d0c5f0

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
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.

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,22 +3381,32 @@ where
33813381
}
33823382

33833383

3384-
/// Signals that no further retries for the given payment should occur. Useful if you have a
3384+
/// Signals that no further attempts for the given payment should occur. Useful if you have a
33853385
/// pending outbound payment with retries remaining, but wish to stop retrying the payment before
33863386
/// retries are exhausted.
33873387
///
3388+
/// # Event Generation
3389+
///
33883390
/// If no [`Event::PaymentFailed`] event had been generated before, one will be generated as soon
33893391
/// as there are no remaining pending HTLCs for this payment.
33903392
///
33913393
/// Note that calling this method does *not* prevent a payment from succeeding. You must still
33923394
/// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
33933395
/// determine the ultimate status of a payment.
33943396
///
3395-
/// If an [`Event::PaymentFailed`] event is generated and we restart without this
3396-
/// [`ChannelManager`] having been persisted, another [`Event::PaymentFailed`] may be generated.
3397+
/// # Requested Invoices
33973398
///
3398-
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed
3399-
/// [`Event::PaymentSent`]: events::Event::PaymentSent
3399+
/// In the case of paying a [`Bolt12Invoice`], abandoning the payment prior to receiving the
3400+
/// invoice will result in an [`Event::InvoiceRequestFailed`] and prevent any attempts at paying
3401+
/// it once received. The other events may only be generated once the invoice has been received.
3402+
///
3403+
/// # Restart Behavior
3404+
///
3405+
/// If an [`Event::PaymentFailed`] is generated and we restart without first persisting the
3406+
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for
3407+
/// [`Event::InvoiceRequestFailed`].
3408+
///
3409+
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
34003410
pub fn abandon_payment(&self, payment_id: PaymentId) {
34013411
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
34023412
self.pending_outbound_payments.abandon_payment(payment_id, PaymentFailureReason::UserAbandoned, &self.pending_events);
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)