From f8712106d29275c8ed4720e83dc61c9962b5a79a Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Fri, 3 Feb 2023 12:44:14 -0500 Subject: [PATCH] Pass pending events to outbound_payments::abandon_payment This makes it uniform with the outbound payment methods that generate events and set us up for abandoning payments on behalf of the user. --- lightning/src/ln/channelmanager.rs | 4 +--- lightning/src/ln/outbound_payment.rs | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index a1148b692..35a3c96a3 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2597,9 +2597,7 @@ where /// [`Event::PaymentSent`]: events::Event::PaymentSent pub fn abandon_payment(&self, payment_id: PaymentId) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); - if let Some(payment_failed_ev) = self.pending_outbound_payments.abandon_payment(payment_id) { - self.pending_events.lock().unwrap().push(payment_failed_ev); - } + self.pending_outbound_payments.abandon_payment(payment_id, &self.pending_events); } /// Send a spontaneous payment, which is a payment that does not require the recipient to have diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index c7151def6..05987e750 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -1120,13 +1120,14 @@ impl OutboundPayments { if let Some(ev) = pending_retry_ev { pending_events.push(ev); } } - pub(super) fn abandon_payment(&self, payment_id: PaymentId) -> Option { - let mut failed_ev = None; + pub(super) fn abandon_payment( + &self, payment_id: PaymentId, pending_events: &Mutex> + ) { let mut outbounds = self.pending_outbound_payments.lock().unwrap(); if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(payment_id) { if let Ok(()) = payment.get_mut().mark_abandoned() { if payment.get().remaining_parts() == 0 { - failed_ev = Some(events::Event::PaymentFailed { + pending_events.lock().unwrap().push(events::Event::PaymentFailed { payment_id, payment_hash: payment.get().payment_hash().expect("PendingOutboundPayments::RetriesExceeded always has a payment hash set"), }); @@ -1134,7 +1135,6 @@ impl OutboundPayments { } } } - failed_ev } #[cfg(test)] -- 2.39.5