Skip to content

Commit

Permalink
Remove pending probes on update_fail
Browse files Browse the repository at this point in the history
Previously we had a memory leak where probes would not be removed from
outbound_payments on htlc fail
  • Loading branch information
valentinewallace committed Feb 16, 2023
1 parent 30b9d9f commit a2b956d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lightning/src/ln/outbound_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
3 changes: 3 additions & 0 deletions lightning/src/ln/payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ fn successful_probe_yields_event() {
},
_ => panic!(),
};
assert!(!nodes[0].node.has_pending_payments());
}

#[test]
Expand Down Expand Up @@ -986,6 +987,7 @@ fn failed_probe_yields_event() {
},
_ => panic!(),
};
assert!(!nodes[0].node.has_pending_payments());
}

#[test]
Expand Down Expand Up @@ -1040,6 +1042,7 @@ fn onchain_failed_probe_yields_event() {
}
}
assert!(found_probe_failed);
assert!(!nodes[0].node.has_pending_payments());
}

#[test]
Expand Down

0 comments on commit a2b956d

Please sign in to comment.