Skip to content

Commit c7219e4

Browse files
committed
Config-guard Event::InvoiceRequestFailed
The event cannot be generated publicly, so remove it for now to avoid users needing to handle it.
1 parent 955e810 commit c7219e4

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

lightning/src/events/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ pub enum Event {
517517
/// or was explicitly abandoned by [`ChannelManager::abandon_payment`].
518518
///
519519
/// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
520+
#[cfg(invreqfailed)]
520521
InvoiceRequestFailed {
521522
/// The `payment_id` to have been associated with payment for the requested invoice.
522523
payment_id: PaymentId,
@@ -1163,6 +1164,7 @@ impl Writeable for Event {
11631164
(8, funding_txo, required),
11641165
});
11651166
},
1167+
#[cfg(invreqfailed)]
11661168
&Event::InvoiceRequestFailed { ref payment_id } => {
11671169
33u8.write(writer)?;
11681170
write_tlv_fields!(writer, {
@@ -1556,6 +1558,7 @@ impl MaybeReadable for Event {
15561558
};
15571559
f()
15581560
},
1561+
#[cfg(invreqfailed)]
15591562
33u8 => {
15601563
let f = || {
15611564
_init_and_read_len_prefixed_tlv_fields!(reader, {

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,19 +3541,10 @@ where
35413541
/// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
35423542
/// determine the ultimate status of a payment.
35433543
///
3544-
/// # Requested Invoices
3545-
///
3546-
/// In the case of paying a [`Bolt12Invoice`], abandoning the payment prior to receiving the
3547-
/// invoice will result in an [`Event::InvoiceRequestFailed`] and prevent any attempts at paying
3548-
/// it once received. The other events may only be generated once the invoice has been received.
3549-
///
35503544
/// # Restart Behavior
35513545
///
35523546
/// If an [`Event::PaymentFailed`] is generated and we restart without first persisting the
3553-
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for
3554-
/// [`Event::InvoiceRequestFailed`].
3555-
///
3556-
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
3547+
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated.
35573548
pub fn abandon_payment(&self, payment_id: PaymentId) {
35583549
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
35593550
self.pending_outbound_payments.abandon_payment(payment_id, PaymentFailureReason::UserAbandoned, &self.pending_events);

lightning/src/ln/outbound_payment.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,9 @@ impl OutboundPayments {
15021502
&self, pending_events: &Mutex<VecDeque<(events::Event, Option<EventCompletionAction>)>>)
15031503
{
15041504
let mut pending_outbound_payments = self.pending_outbound_payments.lock().unwrap();
1505+
#[cfg(not(invreqfailed))]
1506+
let pending_events = pending_events.lock().unwrap();
1507+
#[cfg(invreqfailed)]
15051508
let mut pending_events = pending_events.lock().unwrap();
15061509
pending_outbound_payments.retain(|payment_id, payment| {
15071510
// If an outbound payment was completed, and no pending HTLCs remain, we should remove it
@@ -1540,6 +1543,7 @@ impl OutboundPayments {
15401543
if *timer_ticks_without_response <= INVOICE_REQUEST_TIMEOUT_TICKS {
15411544
true
15421545
} else {
1546+
#[cfg(invreqfailed)]
15431547
pending_events.push_back(
15441548
(events::Event::InvoiceRequestFailed { payment_id: *payment_id }, None)
15451549
);
@@ -1692,6 +1696,7 @@ impl OutboundPayments {
16921696
payment.remove();
16931697
}
16941698
} else if let PendingOutboundPayment::AwaitingInvoice { .. } = payment.get() {
1699+
#[cfg(invreqfailed)]
16951700
pending_events.lock().unwrap().push_back((events::Event::InvoiceRequestFailed {
16961701
payment_id,
16971702
}, None));
@@ -1782,7 +1787,9 @@ mod tests {
17821787
use crate::ln::channelmanager::{PaymentId, RecipientOnionFields};
17831788
use crate::ln::features::{ChannelFeatures, NodeFeatures};
17841789
use crate::ln::msgs::{ErrorAction, LightningError};
1785-
use crate::ln::outbound_payment::{Bolt12PaymentError, INVOICE_REQUEST_TIMEOUT_TICKS, OutboundPayments, Retry, RetryableSendFailure};
1790+
use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, Retry, RetryableSendFailure};
1791+
#[cfg(invreqfailed)]
1792+
use crate::ln::outbound_payment::INVOICE_REQUEST_TIMEOUT_TICKS;
17861793
use crate::offers::invoice::DEFAULT_RELATIVE_EXPIRY;
17871794
use crate::offers::offer::OfferBuilder;
17881795
use crate::offers::test_utils::*;
@@ -1985,6 +1992,7 @@ mod tests {
19851992
}
19861993

19871994
#[test]
1995+
#[cfg(invreqfailed)]
19881996
fn removes_stale_awaiting_invoice() {
19891997
let pending_events = Mutex::new(VecDeque::new());
19901998
let outbound_payments = OutboundPayments::new();
@@ -2023,6 +2031,7 @@ mod tests {
20232031
}
20242032

20252033
#[test]
2034+
#[cfg(invreqfailed)]
20262035
fn removes_abandoned_awaiting_invoice() {
20272036
let pending_events = Mutex::new(VecDeque::new());
20282037
let outbound_payments = OutboundPayments::new();

0 commit comments

Comments
 (0)