Skip to content

Commit e0fe325

Browse files
authored
Merge pull request #2629 from jkczyz/2023-09-invreqfailed
Config-guard `Event::InvoiceRequestFailed`
2 parents 620244d + 92e5cb6 commit e0fe325

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

lightning/src/events/mod.rs

+3
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

+2-11
Original file line numberDiff line numberDiff line change
@@ -3549,19 +3549,10 @@ where
35493549
/// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
35503550
/// determine the ultimate status of a payment.
35513551
///
3552-
/// # Requested Invoices
3553-
///
3554-
/// In the case of paying a [`Bolt12Invoice`], abandoning the payment prior to receiving the
3555-
/// invoice will result in an [`Event::InvoiceRequestFailed`] and prevent any attempts at paying
3556-
/// it once received. The other events may only be generated once the invoice has been received.
3557-
///
35583552
/// # Restart Behavior
35593553
///
35603554
/// If an [`Event::PaymentFailed`] is generated and we restart without first persisting the
3561-
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for
3562-
/// [`Event::InvoiceRequestFailed`].
3563-
///
3564-
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
3555+
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated.
35653556
pub fn abandon_payment(&self, payment_id: PaymentId) {
35663557
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
35673558
self.pending_outbound_payments.abandon_payment(payment_id, PaymentFailureReason::UserAbandoned, &self.pending_events);
@@ -3902,7 +3893,7 @@ where
39023893
btree_map::Entry::Vacant(vacant) => Some(vacant.insert(Vec::new())),
39033894
}
39043895
});
3905-
for (channel_idx, &(temporary_channel_id, counterparty_node_id)) in temporary_channels.iter().enumerate() {
3896+
for &(temporary_channel_id, counterparty_node_id) in temporary_channels.iter() {
39063897
result = result.and_then(|_| self.funding_transaction_generated_intern(
39073898
temporary_channel_id,
39083899
counterparty_node_id,

lightning/src/ln/outbound_payment.rs

+10-1
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();

lightning/src/ln/reload_tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::util::ser::{Writeable, ReadableArgs};
2525
use crate::util::config::UserConfig;
2626
use crate::util::string::UntrustedString;
2727

28-
use bitcoin::{PackedLockTime, Transaction, TxOut};
2928
use bitcoin::hash_types::BlockHash;
3029

3130
use crate::prelude::*;

lightning/src/sign/type_resolver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl<ECS: EcdsaChannelSigner> ChannelSignerType<ECS>{
2424
}
2525
}
2626

27+
#[allow(unused)]
2728
pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut ECS> {
2829
match self {
2930
ChannelSignerType::Ecdsa(ecs) => Some(ecs)

0 commit comments

Comments
 (0)