@@ -61,11 +61,11 @@ use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
6161use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
6262#[cfg(test)]
6363use crate::ln::outbound_payment;
64- use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs, StaleExpiration};
64+ use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
6565use crate::ln::wire::Encode;
6666use crate::offers::invoice::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice};
6767use crate::offers::invoice_error::InvoiceError;
68- use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
68+ use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequest, InvoiceRequestBuilder};
6969use crate::offers::nonce::Nonce;
7070use crate::offers::offer::{Offer, OfferBuilder};
7171use crate::offers::parse::Bolt12SemanticError;
@@ -3105,7 +3105,7 @@ where
31053105
31063106 outbound_scid_aliases: Mutex::new(new_hash_set()),
31073107 pending_inbound_payments: Mutex::new(new_hash_map()),
3108- pending_outbound_payments: OutboundPayments::new(),
3108+ pending_outbound_payments: OutboundPayments::new(new_hash_map() ),
31093109 forward_htlcs: Mutex::new(new_hash_map()),
31103110 decode_update_add_htlcs: Mutex::new(new_hash_map()),
31113111 claimable_payments: Mutex::new(ClaimablePayments { claimable_payments: new_hash_map(), pending_claiming_payments: new_hash_map() }),
@@ -9005,7 +9005,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
90059005 let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
90069006 $self.pending_outbound_payments
90079007 .add_new_awaiting_invoice(
9008- payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
9008+ payment_id, expiration, retry_strategy, max_total_routing_fee_msat, None,
90099009 )
90109010 .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
90119011
@@ -9131,17 +9131,30 @@ where
91319131 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
91329132
91339133 let expiration = StaleExpiration::TimerTicks(1);
9134+ let retryable_invoice_request = RetryableInvoiceRequest {
9135+ invoice_request: invoice_request.clone(),
9136+ nonce,
9137+ };
91349138 self.pending_outbound_payments
91359139 .add_new_awaiting_invoice(
9136- payment_id, expiration, retry_strategy, max_total_routing_fee_msat
9140+ payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
9141+ Some(retryable_invoice_request)
91379142 )
91389143 .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
91399144
9145+ self.enqueue_invoice_request(invoice_request, reply_paths)
9146+ }
9147+
9148+ fn enqueue_invoice_request(
9149+ &self,
9150+ invoice_request: InvoiceRequest,
9151+ reply_paths: Vec<BlindedMessagePath>,
9152+ ) -> Result<(), Bolt12SemanticError> {
91409153 let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9141- if !offer .paths().is_empty() {
9154+ if !invoice_request .paths().is_empty() {
91429155 reply_paths
91439156 .iter()
9144- .flat_map(|reply_path| offer .paths().iter().map(move |path| (path, reply_path)))
9157+ .flat_map(|reply_path| invoice_request .paths().iter().map(move |path| (path, reply_path)))
91459158 .take(OFFERS_MESSAGE_REQUEST_LIMIT)
91469159 .for_each(|(path, reply_path)| {
91479160 let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
@@ -9151,7 +9164,7 @@ where
91519164 let message = OffersMessage::InvoiceRequest(invoice_request.clone());
91529165 pending_offers_messages.push((message, instructions));
91539166 });
9154- } else if let Some(signing_pubkey) = offer .signing_pubkey() {
9167+ } else if let Some(signing_pubkey) = invoice_request .signing_pubkey() {
91559168 for reply_path in reply_paths {
91569169 let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
91579170 destination: Destination::Node(signing_pubkey),
@@ -10811,6 +10824,39 @@ where
1081110824 "Dual-funded channels not supported".to_owned(),
1081210825 msg.channel_id.clone())), counterparty_node_id);
1081310826 }
10827+
10828+ fn message_received(&self) {
10829+ for (payment_id, retryable_invoice_request) in self
10830+ .pending_outbound_payments
10831+ .release_invoice_requests_awaiting_invoice()
10832+ {
10833+ let RetryableInvoiceRequest { invoice_request, nonce } = retryable_invoice_request;
10834+ let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key);
10835+ let context = OffersContext::OutboundPayment {
10836+ payment_id,
10837+ nonce,
10838+ hmac: Some(hmac)
10839+ };
10840+ match self.create_blinded_paths(context) {
10841+ Ok(reply_paths) => match self.enqueue_invoice_request(invoice_request, reply_paths) {
10842+ Ok(_) => {}
10843+ Err(_) => {
10844+ log_warn!(self.logger,
10845+ "Retry failed for an invoice request with payment_id: {}",
10846+ payment_id
10847+ );
10848+ }
10849+ },
10850+ Err(_) => {
10851+ log_warn!(self.logger,
10852+ "Retry failed for an invoice request with payment_id: {}. \
10853+ Reason: router could not find a blinded path to include as the reply path",
10854+ payment_id
10855+ );
10856+ }
10857+ }
10858+ }
10859+ }
1081410860}
1081510861
1081610862impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>
@@ -12227,10 +12273,7 @@ where
1222712273 }
1222812274 pending_outbound_payments = Some(outbounds);
1222912275 }
12230- let pending_outbounds = OutboundPayments {
12231- pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()),
12232- retry_lock: Mutex::new(())
12233- };
12276+ let pending_outbounds = OutboundPayments::new(pending_outbound_payments.unwrap());
1223412277
1223512278 // We have to replay (or skip, if they were completed after we wrote the `ChannelManager`)
1223612279 // each `ChannelMonitorUpdate` in `in_flight_monitor_updates`. After doing so, we have to
0 commit comments