Skip to content

Commit b1c56eb

Browse files
Include invreq in payment onion when sending async payments
Past commits have set us up to include invoice requests in outbound async payment onions. Here we actually pull the invoice request from where it's stored in outbound_payments and pass it into the correct utility for inclusion in the onion on initial send. Per <lightning/bolts#1149>, when paying a static invoice we need to include our original invoice request in the HTLC onion since the recipient wouldn't have received it previously.
1 parent 4943976 commit b1c56eb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -952,20 +952,26 @@ impl OutboundPayments {
952952
payment_hash, recipient_onion.clone(), keysend_preimage, &route, Some(retry_strategy),
953953
payment_params, entropy_source, best_block_height
954954
);
955-
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
956-
hash_map::Entry::Occupied(entry) => match entry.get() {
957-
PendingOutboundPayment::InvoiceReceived { .. }
958-
| PendingOutboundPayment::StaticInvoiceReceived { .. } => {
959-
*entry.into_mut() = retryable_payment;
955+
let mut invoice_request_opt = None;
956+
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
957+
match outbounds.entry(payment_id) {
958+
hash_map::Entry::Occupied(entry) => match entry.remove() {
959+
PendingOutboundPayment::InvoiceReceived { .. } => {
960+
outbounds.insert(payment_id, retryable_payment);
961+
},
962+
PendingOutboundPayment::StaticInvoiceReceived { invoice_request, .. } => {
963+
invoice_request_opt = Some(invoice_request);
964+
outbounds.insert(payment_id, retryable_payment);
960965
},
961966
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
962967
},
963968
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
964969
}
970+
core::mem::drop(outbounds);
965971

966972
let result = self.pay_route_internal(
967-
&route, payment_hash, &recipient_onion, keysend_preimage, None, payment_id,
968-
Some(route_params.final_value_msat), onion_session_privs, node_signer,
973+
&route, payment_hash, &recipient_onion, keysend_preimage, invoice_request_opt.as_ref(),
974+
payment_id, Some(route_params.final_value_msat), onion_session_privs, node_signer,
969975
best_block_height, &send_payment_along_path
970976
);
971977
log_info!(

0 commit comments

Comments
 (0)