diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 2c2dcc9c78a..b205ce026e2 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -94,6 +94,7 @@ pub(crate) enum PendingOutboundPayment { payment_secret: Option, payment_metadata: Option>, keysend_preimage: Option, + invoice_request: Option, custom_tlvs: Vec<(u64, Vec)>, pending_amt_msat: u64, /// Used to track the fee paid. Present iff the payment was serialized on 0.0.103+. @@ -947,12 +948,18 @@ impl OutboundPayments { }; let payment_params = Some(route_params.payment_params.clone()); + let mut outbounds = self.pending_outbound_payments.lock().unwrap(); + let mut invoice_request_opt = outbounds.get(&payment_id).and_then(|pmt| { + if let PendingOutboundPayment::StaticInvoiceReceived { invoice_request, .. } = pmt { + Some(invoice_request.clone()) + } else { + None + } + }); let (retryable_payment, onion_session_privs) = self.create_pending_payment( - payment_hash, recipient_onion.clone(), keysend_preimage, &route, Some(retry_strategy), - payment_params, entropy_source, best_block_height + payment_hash, recipient_onion.clone(), keysend_preimage, invoice_request_opt.take(), &route, + Some(retry_strategy), payment_params, entropy_source, best_block_height ); - 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 { .. } => { @@ -1328,14 +1335,14 @@ impl OutboundPayments { } } } - let (total_msat, recipient_onion, keysend_preimage, onion_session_privs) = { + let (total_msat, recipient_onion, keysend_preimage, onion_session_privs, invoice_request) = { let mut outbounds = self.pending_outbound_payments.lock().unwrap(); match outbounds.entry(payment_id) { hash_map::Entry::Occupied(mut payment) => { match payment.get() { PendingOutboundPayment::Retryable { total_msat, keysend_preimage, payment_secret, payment_metadata, - custom_tlvs, pending_amt_msat, .. + custom_tlvs, pending_amt_msat, invoice_request, .. } => { const RETRY_OVERFLOW_PERCENTAGE: u64 = 10; let retry_amt_msat = route.get_total_amount(); @@ -1358,6 +1365,7 @@ impl OutboundPayments { custom_tlvs: custom_tlvs.clone(), }; let keysend_preimage = *keysend_preimage; + let invoice_request = invoice_request.clone(); let mut onion_session_privs = Vec::with_capacity(route.paths.len()); for _ in 0..route.paths.len() { @@ -1370,7 +1378,7 @@ impl OutboundPayments { payment.get_mut().increment_attempts(); - (total_msat, recipient_onion, keysend_preimage, onion_session_privs) + (total_msat, recipient_onion, keysend_preimage, onion_session_privs, invoice_request) }, PendingOutboundPayment::Legacy { .. } => { log_error!(logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102"); @@ -1408,8 +1416,8 @@ impl OutboundPayments { } }; let res = self.pay_route_internal(&route, payment_hash, &recipient_onion, keysend_preimage, - None, payment_id, Some(total_msat), onion_session_privs, node_signer, best_block_height, - &send_payment_along_path); + invoice_request.as_ref(), payment_id, Some(total_msat), onion_session_privs, node_signer, + best_block_height, &send_payment_along_path); log_info!(logger, "Result retrying payment id {}: {:?}", &payment_id, res); if let Err(e) = res { self.handle_pay_route_err(e, payment_id, payment_hash, route, route_params, router, first_hops, inflight_htlcs, entropy_source, node_signer, best_block_height, logger, pending_events, send_payment_along_path); @@ -1561,7 +1569,7 @@ impl OutboundPayments { hash_map::Entry::Occupied(_) => Err(PaymentSendFailure::DuplicatePayment), hash_map::Entry::Vacant(entry) => { let (payment, onion_session_privs) = self.create_pending_payment( - payment_hash, recipient_onion, keysend_preimage, route, retry_strategy, + payment_hash, recipient_onion, keysend_preimage, None, route, retry_strategy, payment_params, entropy_source, best_block_height ); entry.insert(payment); @@ -1572,8 +1580,9 @@ impl OutboundPayments { fn create_pending_payment( &self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, - keysend_preimage: Option, route: &Route, retry_strategy: Option, - payment_params: Option, entropy_source: &ES, best_block_height: u32 + keysend_preimage: Option, invoice_request: Option, + route: &Route, retry_strategy: Option, payment_params: Option, + entropy_source: &ES, best_block_height: u32 ) -> (PendingOutboundPayment, Vec<[u8; 32]>) where ES::Target: EntropySource, @@ -1594,6 +1603,7 @@ impl OutboundPayments { payment_secret: recipient_onion.payment_secret, payment_metadata: recipient_onion.payment_metadata, keysend_preimage, + invoice_request, custom_tlvs: recipient_onion.custom_tlvs, starting_block_height: best_block_height, total_msat: route.get_total_amount(), @@ -2155,6 +2165,7 @@ impl OutboundPayments { payment_secret: None, // only used for retries, and we'll never retry on startup payment_metadata: None, // only used for retries, and we'll never retry on startup keysend_preimage: None, // only used for retries, and we'll never retry on startup + invoice_request: None, // only used for retries, and we'll never retry on startup custom_tlvs: Vec::new(), // only used for retries, and we'll never retry on startup pending_amt_msat: path_amt, pending_fee_msat: Some(path_fee), @@ -2241,6 +2252,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment, (9, custom_tlvs, optional_vec), (10, starting_block_height, required), (11, remaining_max_total_routing_fee_msat, option), + (13, invoice_request, option), (not_written, retry_strategy, (static_value, None)), (not_written, attempts, (static_value, PaymentAttempts::new())), },