Skip to content

Commit 5c0b804

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 847b43b commit 5c0b804

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
@@ -9612,6 +9612,7 @@ where
96129612
let retryable_invoice_request = RetryableInvoiceRequest {
96139613
invoice_request: invoice_request.clone(),
96149614
nonce,
9615+
needs_retry: true,
96159616
};
96169617
self.pending_outbound_payments
96179618
.add_new_awaiting_invoice(
@@ -11452,7 +11453,7 @@ where
1145211453
.pending_outbound_payments
1145311454
.release_invoice_requests_awaiting_invoice()
1145411455
{
11455-
let RetryableInvoiceRequest { invoice_request, nonce } = retryable_invoice_request;
11456+
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
1145611457
let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key);
1145711458
let context = MessageContext::Offers(OffersContext::OutboundPayment {
1145811459
payment_id,
@@ -11787,6 +11788,7 @@ where
1178711788
let retryable_invoice_request = RetryableInvoiceRequest {
1178811789
invoice_request: invoice_request.clone(),
1178911790
nonce,
11791+
needs_retry: true,
1179011792
};
1179111793
self.pending_outbound_payments
1179211794
.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

@@ -746,7 +749,12 @@ pub(super) struct OutboundPayments {
746749
impl OutboundPayments {
747750
pub(super) fn new(pending_outbound_payments: HashMap<PaymentId, PendingOutboundPayment>) -> Self {
748751
let has_invoice_requests = pending_outbound_payments.values().any(|payment| {
749-
matches!(payment, PendingOutboundPayment::AwaitingInvoice { retryable_invoice_request: Some(_), .. })
752+
matches!(
753+
payment,
754+
PendingOutboundPayment::AwaitingInvoice {
755+
retryable_invoice_request: Some(invreq), ..
756+
} if invreq.needs_retry
757+
)
750758
});
751759

752760
Self {
@@ -2217,11 +2225,12 @@ impl OutboundPayments {
22172225
.iter_mut()
22182226
.filter_map(|(payment_id, payment)| {
22192227
if let PendingOutboundPayment::AwaitingInvoice {
2220-
retryable_invoice_request, ..
2228+
retryable_invoice_request: Some(invreq), ..
22212229
} = payment {
2222-
retryable_invoice_request.take().map(|retryable_invoice_request| {
2223-
(*payment_id, retryable_invoice_request)
2224-
})
2230+
if invreq.needs_retry {
2231+
invreq.needs_retry = false;
2232+
Some((*payment_id, invreq.clone()))
2233+
} else { None }
22252234
} else {
22262235
None
22272236
}

0 commit comments

Comments
 (0)