From 22eabde826c4d55850f3f35cdce567ac266d7ebb Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 18 Sep 2024 11:17:49 -0400 Subject: [PATCH] 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 , 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. --- lightning/src/ln/outbound_payment.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 382fb33acf6..88b112c89e6 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -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!(