Skip to content

Commit a1d7412

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 fa3dc77 commit a1d7412

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
@@ -951,20 +951,26 @@ impl OutboundPayments {
951951
payment_hash, recipient_onion.clone(), keysend_preimage, &route, Some(retry_strategy),
952952
payment_params, entropy_source, best_block_height
953953
);
954-
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
955-
hash_map::Entry::Occupied(entry) => match entry.get() {
956-
PendingOutboundPayment::InvoiceReceived { .. }
957-
| PendingOutboundPayment::StaticInvoiceReceived { .. } => {
958-
*entry.into_mut() = retryable_payment;
954+
let mut invoice_request_opt = None;
955+
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
956+
match outbounds.entry(payment_id) {
957+
hash_map::Entry::Occupied(entry) => match entry.remove() {
958+
PendingOutboundPayment::InvoiceReceived { .. } => {
959+
outbounds.insert(payment_id, retryable_payment);
960+
},
961+
PendingOutboundPayment::StaticInvoiceReceived { invoice_request, .. } => {
962+
invoice_request_opt = Some(invoice_request);
963+
outbounds.insert(payment_id, retryable_payment);
959964
},
960965
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
961966
},
962967
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
963968
}
969+
core::mem::drop(outbounds);
964970

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

0 commit comments

Comments
 (0)