From: Valentine Wallace Date: Wed, 15 Feb 2023 22:30:47 +0000 (-0500) Subject: Remove pending probes on update_fail X-Git-Tag: v0.0.114-beta~15^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=a2b956d46eb9ec32824eddd1eff585a342c4f606;p=rust-lightning Remove pending probes on update_fail Previously we had a memory leak where probes would not be removed from outbound_payments on htlc fail --- diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 490aa9069..8cb5a07ca 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -1062,17 +1062,19 @@ impl OutboundPayments { }); } - if !payment_is_probe && (!is_retryable_now || !payment_retryable || retry.is_none()) { + if payment_is_probe || !is_retryable_now || !payment_retryable || retry.is_none() { let _ = payment.get_mut().mark_abandoned(); // we'll only Err if it's a legacy payment is_retryable_now = false; } if payment.get().remaining_parts() == 0 { all_paths_failed = true; if payment.get().abandoned() { - full_failure_ev = Some(events::Event::PaymentFailed { - payment_id: *payment_id, - payment_hash: payment.get().payment_hash().expect("PendingOutboundPayments::RetriesExceeded always has a payment hash set"), - }); + if !payment_is_probe { + full_failure_ev = Some(events::Event::PaymentFailed { + payment_id: *payment_id, + payment_hash: payment.get().payment_hash().expect("PendingOutboundPayments::RetriesExceeded always has a payment hash set"), + }); + } payment.remove(); } } diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index a433f796a..e398ce031 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -941,6 +941,7 @@ fn successful_probe_yields_event() { }, _ => panic!(), }; + assert!(!nodes[0].node.has_pending_payments()); } #[test] @@ -986,6 +987,7 @@ fn failed_probe_yields_event() { }, _ => panic!(), }; + assert!(!nodes[0].node.has_pending_payments()); } #[test] @@ -1040,6 +1042,7 @@ fn onchain_failed_probe_yields_event() { } } assert!(found_probe_failed); + assert!(!nodes[0].node.has_pending_payments()); } #[test]