]> git.bitcoin.ninja Git - rust-lightning/commitdiff
When processing pending htlcs, abandon outbounds that are not retryable
authorValentine Wallace <vwallace@protonmail.com>
Sat, 4 Feb 2023 02:44:08 +0000 (21:44 -0500)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 15 Feb 2023 22:57:13 +0000 (17:57 -0500)
lightning/src/ln/outbound_payment.rs
lightning/src/ln/payment_tests.rs

index 55719c4053f62a704d7f72704d2d787bbdc85258..0373d2dddeedb0c9484d7dd55adcf8ba08d3c6a9 100644 (file)
@@ -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.
index f75cbd436e81091768c0fd43568f432dc0f035e5..5001242bb6cbb7c7b56a466e1e1a49ca1ff2c3b0 100644 (file)
@@ -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] {