Skip to content

Commit 074fca1

Browse files
valentinewallacetnull
authored andcommitted
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 c0d920c commit 074fca1

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
@@ -10007,6 +10007,7 @@ where
1000710007
let retryable_invoice_request = RetryableInvoiceRequest {
1000810008
invoice_request: invoice_request.clone(),
1000910009
nonce,
10010+
needs_retry: true,
1001010011
};
1001110012
self.pending_outbound_payments
1001210013
.add_new_awaiting_invoice(
@@ -11871,7 +11872,7 @@ where
1187111872
.pending_outbound_payments
1187211873
.release_invoice_requests_awaiting_invoice()
1187311874
{
11874-
let RetryableInvoiceRequest { invoice_request, nonce } = retryable_invoice_request;
11875+
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
1187511876
let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key);
1187611877
let context = MessageContext::Offers(OffersContext::OutboundPayment {
1187711878
payment_id,
@@ -12206,6 +12207,7 @@ where
1220612207
let retryable_invoice_request = RetryableInvoiceRequest {
1220712208
invoice_request: invoice_request.clone(),
1220812209
nonce,
12210+
needs_retry: true,
1220912211
};
1221012212
self.pending_outbound_payments
1221112213
.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)