]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Pass pending events to outbound_payments::abandon_payment
authorValentine Wallace <vwallace@protonmail.com>
Fri, 3 Feb 2023 17:44:14 +0000 (12:44 -0500)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 15 Feb 2023 03:51:28 +0000 (22:51 -0500)
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
lightning/src/ln/outbound_payment.rs

index a1148b692b102b15754386bfc620a116f4d5fb8d..35a3c96a393486f0bcdf5872f7062bccdc125bba 100644 (file)
@@ -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
index c7151def6d3b0605deec5381af57a3ca863cd48c..05987e7505d24c32cd7afb0100e18c82a26333dd 100644 (file)
@@ -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<events::Event> {
-               let mut failed_ev = None;
+       pub(super) fn abandon_payment(
+               &self, payment_id: PaymentId, pending_events: &Mutex<Vec<events::Event>>
+       ) {
                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)]