Skip to content

Commit

Permalink
Include invreq in payment onion when sending async payments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valentinewallace committed Oct 24, 2024
1 parent 039d289 commit d072621
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lightning/src/ln/outbound_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,20 +952,26 @@ impl OutboundPayments {
payment_hash, recipient_onion.clone(), keysend_preimage, &route, Some(retry_strategy),
payment_params, entropy_source, best_block_height
);
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
hash_map::Entry::Occupied(entry) => match entry.get() {
PendingOutboundPayment::InvoiceReceived { .. }
| PendingOutboundPayment::StaticInvoiceReceived { .. } => {
*entry.into_mut() = retryable_payment;
let mut invoice_request_opt = None;
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
match outbounds.entry(payment_id) {
hash_map::Entry::Occupied(entry) => match entry.remove() {
PendingOutboundPayment::InvoiceReceived { .. } => {
outbounds.insert(payment_id, retryable_payment);
},
PendingOutboundPayment::StaticInvoiceReceived { invoice_request, .. } => {
invoice_request_opt = Some(invoice_request);
outbounds.insert(payment_id, retryable_payment);
},
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
},
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
}
core::mem::drop(outbounds);

let result = self.pay_route_internal(
&route, payment_hash, &recipient_onion, keysend_preimage, None, payment_id,
Some(route_params.final_value_msat), onion_session_privs, node_signer,
&route, payment_hash, &recipient_onion, keysend_preimage, invoice_request_opt.as_ref(),
payment_id, Some(route_params.final_value_msat), onion_session_privs, node_signer,
best_block_height, &send_payment_along_path
);
log_info!(
Expand Down

0 comments on commit d072621

Please sign in to comment.