Skip to content

Commit f6e2196

Browse files
valentinewallacetnull
authored andcommitted
Fix failure to abandon async payments on invalid static invoice
Prior to this fix, we would attempt to mark outbound async payments as abandoned but silently fail because they were in state AwaitingInvoice, which the mark_abandoned utility doesn't currently work for. These payments would eventually be removed by the remove_stale_payments method, but there would be a delay in generating the PaymentFailed event. Move to manually removing the outbound payment entry.
1 parent 074fca1 commit f6e2196

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,17 +1016,16 @@ impl OutboundPayments {
10161016
) -> Result<(), Bolt12PaymentError> where ES::Target: EntropySource {
10171017
macro_rules! abandon_with_entry {
10181018
($payment: expr, $reason: expr) => {
1019-
$payment.get_mut().mark_abandoned($reason);
1020-
if let PendingOutboundPayment::Abandoned { reason, .. } = $payment.get() {
1021-
if $payment.get().remaining_parts() == 0 {
1022-
pending_events.lock().unwrap().push_back((events::Event::PaymentFailed {
1023-
payment_id,
1024-
payment_hash: None,
1025-
reason: *reason,
1026-
}, None));
1027-
$payment.remove();
1028-
}
1029-
}
1019+
assert!(
1020+
matches!($payment.get(), PendingOutboundPayment::AwaitingInvoice { .. }),
1021+
"Generating PaymentFailed for unexpected outbound payment type can result in funds loss"
1022+
);
1023+
pending_events.lock().unwrap().push_back((events::Event::PaymentFailed {
1024+
payment_id,
1025+
payment_hash: None,
1026+
reason: Some($reason),
1027+
}, None));
1028+
$payment.remove();
10301029
}
10311030
}
10321031

0 commit comments

Comments
 (0)