Skip to content

Commit 605cc3c

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 43029bf commit 605cc3c

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
@@ -10046,6 +10046,7 @@ where
1004610046
let retryable_invoice_request = RetryableInvoiceRequest {
1004710047
invoice_request: invoice_request.clone(),
1004810048
nonce,
10049+
needs_retry: true,
1004910050
};
1005010051
self.pending_outbound_payments
1005110052
.add_new_awaiting_invoice(
@@ -11915,7 +11916,7 @@ where
1191511916
.pending_outbound_payments
1191611917
.release_invoice_requests_awaiting_invoice()
1191711918
{
11918-
let RetryableInvoiceRequest { invoice_request, nonce } = retryable_invoice_request;
11919+
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
1191911920
let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key);
1192011921
let context = MessageContext::Offers(OffersContext::OutboundPayment {
1192111922
payment_id,
@@ -12250,6 +12251,7 @@ where
1225012251
let retryable_invoice_request = RetryableInvoiceRequest {
1225112252
invoice_request: invoice_request.clone(),
1225212253
nonce,
12254+
needs_retry: true,
1225312255
};
1225412256
self.pending_outbound_payments
1225512257
.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 {
@@ -2228,11 +2236,12 @@ impl OutboundPayments {
22282236
.iter_mut()
22292237
.filter_map(|(payment_id, payment)| {
22302238
if let PendingOutboundPayment::AwaitingInvoice {
2231-
retryable_invoice_request, ..
2239+
retryable_invoice_request: Some(invreq), ..
22322240
} = payment {
2233-
retryable_invoice_request.take().map(|retryable_invoice_request| {
2234-
(*payment_id, retryable_invoice_request)
2235-
})
2241+
if invreq.needs_retry {
2242+
invreq.needs_retry = false;
2243+
Some((*payment_id, invreq.clone()))
2244+
} else { None }
22362245
} else {
22372246
None
22382247
}

0 commit comments

Comments
 (0)