From c7219e46831751c52026932294c33fce24121d84 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 29 Sep 2023 13:47:25 -0700 Subject: [PATCH 1/4] Config-guard Event::InvoiceRequestFailed The event cannot be generated publicly, so remove it for now to avoid users needing to handle it. --- lightning/src/events/mod.rs | 3 +++ lightning/src/ln/channelmanager.rs | 11 +---------- lightning/src/ln/outbound_payment.rs | 11 ++++++++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 269887a3dba..c8c736c1f71 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -517,6 +517,7 @@ pub enum Event { /// or was explicitly abandoned by [`ChannelManager::abandon_payment`]. /// /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment + #[cfg(invreqfailed)] InvoiceRequestFailed { /// The `payment_id` to have been associated with payment for the requested invoice. payment_id: PaymentId, @@ -1163,6 +1164,7 @@ impl Writeable for Event { (8, funding_txo, required), }); }, + #[cfg(invreqfailed)] &Event::InvoiceRequestFailed { ref payment_id } => { 33u8.write(writer)?; write_tlv_fields!(writer, { @@ -1556,6 +1558,7 @@ impl MaybeReadable for Event { }; f() }, + #[cfg(invreqfailed)] 33u8 => { let f = || { _init_and_read_len_prefixed_tlv_fields!(reader, { diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index cfa17295a53..5985e0c7227 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3541,19 +3541,10 @@ where /// wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to /// determine the ultimate status of a payment. /// - /// # Requested Invoices - /// - /// In the case of paying a [`Bolt12Invoice`], abandoning the payment prior to receiving the - /// invoice will result in an [`Event::InvoiceRequestFailed`] and prevent any attempts at paying - /// it once received. The other events may only be generated once the invoice has been received. - /// /// # Restart Behavior /// /// If an [`Event::PaymentFailed`] is generated and we restart without first persisting the - /// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated; likewise for - /// [`Event::InvoiceRequestFailed`]. - /// - /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice + /// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated. pub fn abandon_payment(&self, payment_id: PaymentId) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); self.pending_outbound_payments.abandon_payment(payment_id, PaymentFailureReason::UserAbandoned, &self.pending_events); diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 2522f99fbe8..1642f28efc7 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -1502,6 +1502,9 @@ impl OutboundPayments { &self, pending_events: &Mutex)>>) { let mut pending_outbound_payments = self.pending_outbound_payments.lock().unwrap(); + #[cfg(not(invreqfailed))] + let pending_events = pending_events.lock().unwrap(); + #[cfg(invreqfailed)] let mut pending_events = pending_events.lock().unwrap(); pending_outbound_payments.retain(|payment_id, payment| { // If an outbound payment was completed, and no pending HTLCs remain, we should remove it @@ -1540,6 +1543,7 @@ impl OutboundPayments { if *timer_ticks_without_response <= INVOICE_REQUEST_TIMEOUT_TICKS { true } else { + #[cfg(invreqfailed)] pending_events.push_back( (events::Event::InvoiceRequestFailed { payment_id: *payment_id }, None) ); @@ -1692,6 +1696,7 @@ impl OutboundPayments { payment.remove(); } } else if let PendingOutboundPayment::AwaitingInvoice { .. } = payment.get() { + #[cfg(invreqfailed)] pending_events.lock().unwrap().push_back((events::Event::InvoiceRequestFailed { payment_id, }, None)); @@ -1782,7 +1787,9 @@ mod tests { use crate::ln::channelmanager::{PaymentId, RecipientOnionFields}; use crate::ln::features::{ChannelFeatures, NodeFeatures}; use crate::ln::msgs::{ErrorAction, LightningError}; - use crate::ln::outbound_payment::{Bolt12PaymentError, INVOICE_REQUEST_TIMEOUT_TICKS, OutboundPayments, Retry, RetryableSendFailure}; + use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, Retry, RetryableSendFailure}; + #[cfg(invreqfailed)] + use crate::ln::outbound_payment::INVOICE_REQUEST_TIMEOUT_TICKS; use crate::offers::invoice::DEFAULT_RELATIVE_EXPIRY; use crate::offers::offer::OfferBuilder; use crate::offers::test_utils::*; @@ -1985,6 +1992,7 @@ mod tests { } #[test] + #[cfg(invreqfailed)] fn removes_stale_awaiting_invoice() { let pending_events = Mutex::new(VecDeque::new()); let outbound_payments = OutboundPayments::new(); @@ -2023,6 +2031,7 @@ mod tests { } #[test] + #[cfg(invreqfailed)] fn removes_abandoned_awaiting_invoice() { let pending_events = Mutex::new(VecDeque::new()); let outbound_payments = OutboundPayments::new(); From 6bd962bc51e57a6ddf2dcf0ec4042fec0ba4497f Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 29 Sep 2023 13:58:34 -0700 Subject: [PATCH 2/4] Remove an unnecessary enumerate --- lightning/src/ln/channelmanager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 5985e0c7227..63692f0e5e3 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3885,7 +3885,7 @@ where btree_map::Entry::Vacant(vacant) => Some(vacant.insert(Vec::new())), } }); - for (channel_idx, &(temporary_channel_id, counterparty_node_id)) in temporary_channels.iter().enumerate() { + for &(temporary_channel_id, counterparty_node_id) in temporary_channels.iter() { result = result.and_then(|_| self.funding_transaction_generated_intern( temporary_channel_id, counterparty_node_id, From 5f58f8d127d0b12cb02f4a96d4637394c8e692e9 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 29 Sep 2023 14:03:39 -0700 Subject: [PATCH 3/4] Fix build warning for unused method --- lightning/src/sign/type_resolver.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lightning/src/sign/type_resolver.rs b/lightning/src/sign/type_resolver.rs index 8b6e8091785..73d2cceb3e8 100644 --- a/lightning/src/sign/type_resolver.rs +++ b/lightning/src/sign/type_resolver.rs @@ -24,6 +24,7 @@ impl ChannelSignerType{ } } + #[allow(unused)] pub(crate) fn as_mut_ecdsa(&mut self) -> Option<&mut ECS> { match self { ChannelSignerType::Ecdsa(ecs) => Some(ecs) From 92e5cb6805045ef56877ed189c01b063df8bc697 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 29 Sep 2023 14:04:21 -0700 Subject: [PATCH 4/4] Remove unused imports --- lightning/src/ln/reload_tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/lightning/src/ln/reload_tests.rs b/lightning/src/ln/reload_tests.rs index 151861411b9..5f4009d6429 100644 --- a/lightning/src/ln/reload_tests.rs +++ b/lightning/src/ln/reload_tests.rs @@ -25,7 +25,6 @@ use crate::util::ser::{Writeable, ReadableArgs}; use crate::util::config::UserConfig; use crate::util::string::UntrustedString; -use bitcoin::{PackedLockTime, Transaction, TxOut}; use bitcoin::hash_types::BlockHash; use crate::prelude::*;