@@ -8285,8 +8285,11 @@ 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
+ // TODO: Introduce a parameter to allow adding more paths to the created Offer.
8288
8289
let path = $self.create_blinded_path_using_absolute_expiry(absolute_expiry)
8290
+ .and_then(|paths| paths.into_iter().next().ok_or(()))
8289
8291
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8292
+
8290
8293
let builder = OfferBuilder::deriving_signing_pubkey(
8291
8294
node_id, expanded_key, entropy, secp_ctx
8292
8295
)
@@ -8357,8 +8360,11 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8357
8360
let entropy = &*$self.entropy_source;
8358
8361
let secp_ctx = &$self.secp_ctx;
8359
8362
8363
+ // TODO: Introduce a parameter to allow adding more paths to the created Refund.
8360
8364
let path = $self.create_blinded_path_using_absolute_expiry(Some(absolute_expiry))
8365
+ .and_then(|paths| paths.into_iter().next().ok_or(()))
8361
8366
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8367
+
8362
8368
let builder = RefundBuilder::deriving_payer_id(
8363
8369
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
8364
8370
)?
@@ -8480,7 +8486,7 @@ where
8480
8486
Some(payer_note) => builder.payer_note(payer_note),
8481
8487
};
8482
8488
let invoice_request = builder.build_and_sign()?;
8483
- let reply_path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8489
+ let reply_paths = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8484
8490
8485
8491
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8486
8492
@@ -8493,25 +8499,32 @@ where
8493
8499
8494
8500
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8495
8501
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.
8502
+ // Send as many invoice requests as there are paths in the offer using as many different
8503
+ // reply_paths possible (with an upper bound).
8504
+ // Using only one path could result in a failure if the path no longer exists.
8505
+ // But only one invoice for a given payment ID will be paid, even if more than one is received.
8499
8506
const REQUEST_LIMIT: usize = 10;
8500
- for path in offer.paths().into_iter().take(REQUEST_LIMIT) {
8507
+ reply_paths
8508
+ .iter()
8509
+ .flat_map(|reply_path| offer.paths().iter().map(move |path| (path, reply_path)))
8510
+ .take(REQUEST_LIMIT)
8511
+ .for_each(|(path, reply_path)| {
8512
+ let message = new_pending_onion_message(
8513
+ OffersMessage::InvoiceRequest(invoice_request.clone()),
8514
+ Destination::BlindedPath(path.clone()),
8515
+ Some(reply_path.clone()),
8516
+ );
8517
+ pending_offers_messages.push(message);
8518
+ });
8519
+ } else if let Some(signing_pubkey) = offer.signing_pubkey() {
8520
+ for reply_path in reply_paths {
8501
8521
let message = new_pending_onion_message(
8502
8522
OffersMessage::InvoiceRequest(invoice_request.clone()),
8503
- Destination::BlindedPath(path.clone() ),
8504
- Some(reply_path.clone() ),
8523
+ Destination::Node(signing_pubkey ),
8524
+ Some(reply_path),
8505
8525
);
8506
8526
pending_offers_messages.push(message);
8507
8527
}
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
8528
} else {
8516
8529
debug_assert!(false);
8517
8530
return Err(Bolt12SemanticError::MissingSigningPubkey);
@@ -8580,26 +8593,37 @@ where
8580
8593
)?;
8581
8594
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
8582
8595
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
8583
- let reply_path = self.create_blinded_path()
8596
+ let reply_paths = self.create_blinded_path()
8584
8597
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8585
8598
8586
8599
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8587
8600
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() {
8601
+ for reply_path in reply_paths {
8596
8602
let message = new_pending_onion_message(
8597
8603
OffersMessage::Invoice(invoice.clone()),
8598
- Destination::BlindedPath(path.clone ()),
8599
- Some(reply_path.clone() ),
8604
+ Destination::Node(refund.payer_id ()),
8605
+ Some(reply_path),
8600
8606
);
8601
8607
pending_offers_messages.push(message);
8602
8608
}
8609
+ } else {
8610
+ // Send as many BOLT12Invoices as there are paths in the refund using as many different
8611
+ // reply_paths possible (with an upper bound).
8612
+ // Using only one path could result in a failure if the path no longer exists.
8613
+ // But only one invoice for a given payment ID will be paid, even if more than one is received.
8614
+ const REQUEST_LIMIT: usize = 10;
8615
+ reply_paths
8616
+ .iter()
8617
+ .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
8618
+ .take(REQUEST_LIMIT)
8619
+ .for_each(|(path, reply_path)| {
8620
+ let message = new_pending_onion_message(
8621
+ OffersMessage::Invoice(invoice.clone()),
8622
+ Destination::BlindedPath(path.clone()),
8623
+ Some(reply_path.clone()),
8624
+ );
8625
+ pending_offers_messages.push(message);
8626
+ });
8603
8627
}
8604
8628
8605
8629
Ok(invoice)
@@ -8714,7 +8738,7 @@ where
8714
8738
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
8715
8739
fn create_blinded_path_using_absolute_expiry(
8716
8740
&self, absolute_expiry: Option<Duration>
8717
- ) -> Result<BlindedPath, ()> {
8741
+ ) -> Result<Vec< BlindedPath> , ()> {
8718
8742
let now = self.duration_since_epoch();
8719
8743
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
8720
8744
@@ -8741,7 +8765,7 @@ where
8741
8765
/// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
8742
8766
///
8743
8767
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
8744
- fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
8768
+ fn create_blinded_path(&self) -> Result<Vec< BlindedPath> , ()> {
8745
8769
let recipient = self.get_our_node_id();
8746
8770
let secp_ctx = &self.secp_ctx;
8747
8771
@@ -8755,13 +8779,12 @@ where
8755
8779
8756
8780
self.router
8757
8781
.create_blinded_paths(recipient, peers, secp_ctx)
8758
- .and_then(|paths| paths.into_iter().next().ok_or(()))
8759
8782
}
8760
8783
8761
8784
/// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
8762
8785
///
8763
8786
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
8764
- fn create_compact_blinded_path(&self) -> Result<BlindedPath, ()> {
8787
+ fn create_compact_blinded_path(&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