From: Valentine Wallace Date: Sat, 4 Feb 2023 02:44:08 +0000 (-0500) Subject: When processing pending htlcs, abandon outbounds that are not retryable X-Git-Tag: v0.0.114-beta~17^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=13e60da7fa88df2830b1673ce182071a8ba5b3e0;p=rust-lightning When processing pending htlcs, abandon outbounds that are not retryable --- 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] {