@@ -8285,8 +8285,10 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
8285
8285
let entropy = &*$self.entropy_source;
8286
8286
let secp_ctx = &$self.secp_ctx;
8287
8287
8288
- let path = $self.create_blinded_path_using_absolute_expiry(absolute_expiry)
8288
+ let path = $self.create_blinded_paths_using_absolute_expiry(absolute_expiry)
8289
+ .and_then(|paths| paths.into_iter().next().ok_or(()))
8289
8290
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8291
+
8290
8292
let builder = OfferBuilder::deriving_signing_pubkey(
8291
8293
node_id, expanded_key, entropy, secp_ctx
8292
8294
)
@@ -8357,8 +8359,10 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8357
8359
let entropy = &*$self.entropy_source;
8358
8360
let secp_ctx = &$self.secp_ctx;
8359
8361
8360
- let path = $self.create_blinded_path_using_absolute_expiry(Some(absolute_expiry))
8362
+ let path = $self.create_blinded_paths_using_absolute_expiry(Some(absolute_expiry))
8363
+ .and_then(|paths| paths.into_iter().next().ok_or(()))
8361
8364
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8365
+
8362
8366
let builder = RefundBuilder::deriving_payer_id(
8363
8367
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
8364
8368
)?
@@ -8480,7 +8484,7 @@ where
8480
8484
Some(payer_note) => builder.payer_note(payer_note),
8481
8485
};
8482
8486
let invoice_request = builder.build_and_sign()?;
8483
- let reply_path = self.create_blinded_path ().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8487
+ let reply_paths = self.create_blinded_paths ().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8484
8488
8485
8489
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8486
8490
@@ -8493,25 +8497,32 @@ where
8493
8497
8494
8498
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8495
8499
if !offer.paths().is_empty() {
8496
- // Send as many invoice requests as there are paths in the offer (with an upper bound).
8497
- // Using only one path could result in a failure if the path no longer exists. But only
8498
- // one invoice for a given payment id will be paid, even if more than one is received.
8500
+ // Send as many invoice requests as there are paths in the offer using as many different
8501
+ // reply_paths possible (with an upper bound).
8502
+ // Using only one path could result in a failure if the path no longer exists.
8503
+ // But only one invoice for a given payment ID will be paid, even if more than one is received.
8499
8504
const REQUEST_LIMIT: usize = 10;
8500
- for path in offer.paths().into_iter().take(REQUEST_LIMIT) {
8505
+ reply_paths
8506
+ .iter()
8507
+ .flat_map(|reply_path| offer.paths().iter().map(move |path| (path, reply_path)))
8508
+ .take(REQUEST_LIMIT)
8509
+ .for_each(|(path, reply_path)| {
8510
+ let message = new_pending_onion_message(
8511
+ OffersMessage::InvoiceRequest(invoice_request.clone()),
8512
+ Destination::BlindedPath(path.clone()),
8513
+ Some(reply_path.clone()),
8514
+ );
8515
+ pending_offers_messages.push(message);
8516
+ });
8517
+ } else if let Some(signing_pubkey) = offer.signing_pubkey() {
8518
+ for reply_path in reply_paths {
8501
8519
let message = new_pending_onion_message(
8502
8520
OffersMessage::InvoiceRequest(invoice_request.clone()),
8503
- Destination::BlindedPath(path.clone() ),
8504
- Some(reply_path.clone() ),
8521
+ Destination::Node(signing_pubkey ),
8522
+ Some(reply_path),
8505
8523
);
8506
8524
pending_offers_messages.push(message);
8507
8525
}
8508
- } else if let Some(signing_pubkey) = offer.signing_pubkey() {
8509
- let message = new_pending_onion_message(
8510
- OffersMessage::InvoiceRequest(invoice_request),
8511
- Destination::Node(signing_pubkey),
8512
- Some(reply_path),
8513
- );
8514
- pending_offers_messages.push(message);
8515
8526
} else {
8516
8527
debug_assert!(false);
8517
8528
return Err(Bolt12SemanticError::MissingSigningPubkey);
@@ -8580,26 +8591,37 @@ where
8580
8591
)?;
8581
8592
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
8582
8593
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
8583
- let reply_path = self.create_blinded_path ()
8594
+ let reply_paths = self.create_blinded_paths ()
8584
8595
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8585
8596
8586
8597
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8587
8598
if refund.paths().is_empty() {
8588
- let message = new_pending_onion_message(
8589
- OffersMessage::Invoice(invoice.clone()),
8590
- Destination::Node(refund.payer_id()),
8591
- Some(reply_path),
8592
- );
8593
- pending_offers_messages.push(message);
8594
- } else {
8595
- for path in refund.paths() {
8599
+ for reply_path in reply_paths {
8596
8600
let message = new_pending_onion_message(
8597
8601
OffersMessage::Invoice(invoice.clone()),
8598
- Destination::BlindedPath(path.clone ()),
8599
- Some(reply_path.clone() ),
8602
+ Destination::Node(refund.payer_id ()),
8603
+ Some(reply_path),
8600
8604
);
8601
8605
pending_offers_messages.push(message);
8602
8606
}
8607
+ } else {
8608
+ // Send as many BOLT12Invoices as there are paths in the refund using as many different
8609
+ // reply_paths possible (with an upper bound).
8610
+ // Using only one path could result in a failure if the path no longer exists.
8611
+ // But only one invoice for a given payment ID will be paid, even if more than one is received.
8612
+ const REQUEST_LIMIT: usize = 10;
8613
+ reply_paths
8614
+ .iter()
8615
+ .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
8616
+ .take(REQUEST_LIMIT)
8617
+ .for_each(|(path, reply_path)| {
8618
+ let message = new_pending_onion_message(
8619
+ OffersMessage::Invoice(invoice.clone()),
8620
+ Destination::BlindedPath(path.clone()),
8621
+ Some(reply_path.clone()),
8622
+ );
8623
+ pending_offers_messages.push(message);
8624
+ });
8603
8625
}
8604
8626
8605
8627
Ok(invoice)
@@ -8706,22 +8728,22 @@ where
8706
8728
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
8707
8729
}
8708
8730
8709
- /// Creates a blinded path by delegating to [`MessageRouter`] based on the path's intended
8710
- /// lifetime.
8731
+ /// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
8732
+ /// the path's intended lifetime.
8711
8733
///
8712
8734
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
8713
8735
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
8714
8736
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
8715
- fn create_blinded_path_using_absolute_expiry (
8737
+ fn create_blinded_paths_using_absolute_expiry (
8716
8738
&self, absolute_expiry: Option<Duration>
8717
- ) -> Result<BlindedPath, ()> {
8739
+ ) -> Result<Vec< BlindedPath> , ()> {
8718
8740
let now = self.duration_since_epoch();
8719
8741
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
8720
8742
8721
8743
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
8722
- self.create_compact_blinded_path ()
8744
+ self.create_compact_blinded_paths ()
8723
8745
} else {
8724
- self.create_blinded_path ()
8746
+ self.create_blinded_paths ()
8725
8747
}
8726
8748
}
8727
8749
@@ -8738,10 +8760,11 @@ where
8738
8760
now
8739
8761
}
8740
8762
8741
- /// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
8763
+ /// Creates a collection of blinded paths by delegating to
8764
+ /// [`MessageRouter::create_blinded_paths`].
8742
8765
///
8743
- /// Errors if the `MessageRouter` errors or returns an empty `Vec` .
8744
- fn create_blinded_path (&self) -> Result<BlindedPath, ()> {
8766
+ /// Errors if the `MessageRouter` errors.
8767
+ fn create_blinded_paths (&self) -> Result<Vec< BlindedPath> , ()> {
8745
8768
let recipient = self.get_our_node_id();
8746
8769
let secp_ctx = &self.secp_ctx;
8747
8770
@@ -8755,13 +8778,13 @@ where
8755
8778
8756
8779
self.router
8757
8780
.create_blinded_paths(recipient, peers, secp_ctx)
8758
- .and_then(|paths| paths.into_iter().next().ok_or(()))
8759
8781
}
8760
8782
8761
- /// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
8783
+ /// Creates a collection of blinded paths by delegating to
8784
+ /// [`MessageRouter::create_compact_blinded_paths`].
8762
8785
///
8763
- /// Errors if the `MessageRouter` errors or returns an empty `Vec` .
8764
- fn create_compact_blinded_path (&self) -> Result<BlindedPath, ()> {
8786
+ /// Errors if the `MessageRouter` errors.
8787
+ fn create_compact_blinded_paths (&self) -> Result<Vec< BlindedPath> , ()> {
8765
8788
let recipient = self.get_our_node_id();
8766
8789
let secp_ctx = &self.secp_ctx;
8767
8790
@@ -8782,7 +8805,6 @@ where
8782
8805
8783
8806
self.router
8784
8807
.create_compact_blinded_paths(recipient, peers, secp_ctx)
8785
- .and_then(|paths| paths.into_iter().next().ok_or(()))
8786
8808
}
8787
8809
8788
8810
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
0 commit comments