From 13e60da7fa88df2830b1673ce182071a8ba5b3e0 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Fri, 3 Feb 2023 21:44:08 -0500 Subject: [PATCH] When processing pending htlcs, abandon outbounds that are not retryable --- lightning/src/ln/outbound_payment.rs | 15 +++++++++++++++ lightning/src/ln/payment_tests.rs | 2 -- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 55719c405..0373d2ddd 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -536,6 +536,21 @@ impl OutboundPayments { } } else { break } } + + let mut outbounds = self.pending_outbound_payments.lock().unwrap(); + outbounds.retain(|pmt_id, pmt| { + let mut retain = true; + if !pmt.is_auto_retryable_now() && pmt.remaining_parts() == 0 { + if pmt.mark_abandoned().is_ok() { + pending_events.lock().unwrap().push(events::Event::PaymentFailed { + payment_id: *pmt_id, + payment_hash: pmt.payment_hash().expect("PendingOutboundPayments::Retryable always has a payment hash set"), + }); + retain = false; + } + } + retain + }); } /// Will return `Ok(())` iff at least one HTLC is sent for the payment. diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index f75cbd436..5001242bb 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -1729,7 +1729,6 @@ fn do_automatic_retries(test: AutoRetry) { let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 0); - nodes[0].node.abandon_payment(PaymentId(payment_hash.0)); let mut events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); match events[0] { @@ -1764,7 +1763,6 @@ fn do_automatic_retries(test: AutoRetry) { let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 0); - nodes[0].node.abandon_payment(PaymentId(payment_hash.0)); let mut events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); match events[0] { -- 2.39.5