Skip to content

Commit be742dd

Browse files
Don't take() outbound invoice requests on retry
Prior to this patch, we would take() the invoice request stored for AwaitingInvoice outbound payments when retrying sending the invoice request onion message. This doesn't work for async payments because we need to keep the invoice request stored for inclusion in the payment onion. Therefore, clone it instead of take()ing it.
1 parent edf2405 commit be742dd

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10016,6 +10016,7 @@ where
1001610016
let retryable_invoice_request = RetryableInvoiceRequest {
1001710017
invoice_request: invoice_request.clone(),
1001810018
nonce,
10019+
needs_retry: true,
1001910020
};
1002010021
self.pending_outbound_payments
1002110022
.add_new_awaiting_invoice(
@@ -11897,7 +11898,7 @@ where
1189711898
.pending_outbound_payments
1189811899
.release_invoice_requests_awaiting_invoice()
1189911900
{
11900-
let RetryableInvoiceRequest { invoice_request, nonce } = retryable_invoice_request;
11901+
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
1190111902
let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key);
1190211903
let context = MessageContext::Offers(OffersContext::OutboundPayment {
1190311904
payment_id,
@@ -12232,6 +12233,7 @@ where
1223212233
let retryable_invoice_request = RetryableInvoiceRequest {
1223312234
invoice_request: invoice_request.clone(),
1223412235
nonce,
12236+
needs_retry: true,
1223512237
};
1223612238
self.pending_outbound_payments
1223712239
.received_offer(payment_id, Some(retryable_invoice_request))

lightning/src/ln/outbound_payment.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,16 @@ pub(crate) enum PendingOutboundPayment {
134134
},
135135
}
136136

137+
#[derive(Clone)]
137138
pub(crate) struct RetryableInvoiceRequest {
138139
pub(crate) invoice_request: InvoiceRequest,
139140
pub(crate) nonce: Nonce,
141+
pub(super) needs_retry: bool,
140142
}
141143

142144
impl_writeable_tlv_based!(RetryableInvoiceRequest, {
143145
(0, invoice_request, required),
146+
(1, needs_retry, (default_value, true)),
144147
(2, nonce, required),
145148
});
146149

@@ -760,7 +763,12 @@ pub(super) struct OutboundPayments {
760763
impl OutboundPayments {
761764
pub(super) fn new(pending_outbound_payments: HashMap<PaymentId, PendingOutboundPayment>) -> Self {
762765
let has_invoice_requests = pending_outbound_payments.values().any(|payment| {
763-
matches!(payment, PendingOutboundPayment::AwaitingInvoice { retryable_invoice_request: Some(_), .. })
766+
matches!(
767+
payment,
768+
PendingOutboundPayment::AwaitingInvoice {
769+
retryable_invoice_request: Some(invreq), ..
770+
} if invreq.needs_retry
771+
)
764772
});
765773

766774
Self {
@@ -2229,11 +2237,12 @@ impl OutboundPayments {
22292237
.iter_mut()
22302238
.filter_map(|(payment_id, payment)| {
22312239
if let PendingOutboundPayment::AwaitingInvoice {
2232-
retryable_invoice_request, ..
2240+
retryable_invoice_request: Some(invreq), ..
22332241
} = payment {
2234-
retryable_invoice_request.take().map(|retryable_invoice_request| {
2235-
(*payment_id, retryable_invoice_request)
2236-
})
2242+
if invreq.needs_retry {
2243+
invreq.needs_retry = false;
2244+
Some((*payment_id, invreq.clone()))
2245+
} else { None }
22372246
} else {
22382247
None
22392248
}

0 commit comments

Comments
 (0)