Skip to content

Commit ebb8e79

Browse files
Don't auto-fail offers payments pre-HTLC lock in
Previously, we had a bug that particularly affected async payments where if an outbound payment was in the state {Static}InvoiceReceived and there was a call to process_pending_htlc_forwards, the payment would be automatically abandoned. We would behave correctly and avoid abandoning if the payment was awaiting an invoice, but not if the payment had an invoice but the HTLCs weren't yet locked in.
1 parent c71334e commit ebb8e79

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lightning/src/ln/async_payments_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ fn pass_async_payments_oms(
240240
.next_onion_message_for_peer(sender_node_id)
241241
.unwrap();
242242
sender.onion_messenger.handle_onion_message(always_online_node_id, &static_invoice_om);
243+
// Check that the node will not lock in HTLCs yet.
244+
sender.node.process_pending_htlc_forwards();
245+
assert!(sender.node.get_and_clear_pending_msg_events().is_empty());
243246

244247
let held_htlc_available_om_0_1 =
245248
sender.onion_messenger.next_onion_message_for_peer(always_online_node_id).unwrap();

lightning/src/ln/outbound_payment.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,13 @@ impl PendingOutboundPayment {
217217
params.insert_previously_failed_blinded_path(blinded_tail);
218218
}
219219
}
220-
fn is_awaiting_invoice(&self) -> bool {
220+
// Used for payments to BOLT 12 offers where we are either waiting for an invoice or have an
221+
// invoice but have not locked in HTLCs for the payment yet.
222+
fn is_pre_htlc_lock_in(&self) -> bool {
221223
match self {
222-
PendingOutboundPayment::AwaitingInvoice { .. } => true,
224+
PendingOutboundPayment::AwaitingInvoice { .. }
225+
| PendingOutboundPayment::InvoiceReceived { .. }
226+
| PendingOutboundPayment::StaticInvoiceReceived { .. } => true,
223227
_ => false,
224228
}
225229
}
@@ -1368,7 +1372,7 @@ impl OutboundPayments {
13681372
let mut retain = true;
13691373
if !pmt.is_auto_retryable_now()
13701374
&& pmt.remaining_parts() == 0
1371-
&& !pmt.is_awaiting_invoice()
1375+
&& !pmt.is_pre_htlc_lock_in()
13721376
{
13731377
pmt.mark_abandoned(PaymentFailureReason::RetriesExhausted);
13741378
if let PendingOutboundPayment::Abandoned { payment_hash, reason, .. } = pmt {
@@ -1396,7 +1400,7 @@ impl OutboundPayments {
13961400
|| !pmt.is_auto_retryable_now()
13971401
&& pmt.remaining_parts() == 0
13981402
&& !pmt.is_fulfilled()
1399-
&& !pmt.is_awaiting_invoice()
1403+
&& !pmt.is_pre_htlc_lock_in()
14001404
})
14011405
}
14021406

0 commit comments

Comments
 (0)