@@ -8270,12 +8270,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
8270
8270
let entropy = &*$self.entropy_source;
8271
8271
let secp_ctx = &$self.secp_ctx;
8272
8272
8273
- let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8273
+ // TODO: Introduce a parameter to allow adding more paths to the created Offer.
8274
+ let paths = $self.create_blinded_path(1)
8275
+ .map_err(|_| Bolt12SemanticError::MissingPaths)?;
8276
+
8274
8277
let builder = OfferBuilder::deriving_signing_pubkey(
8275
8278
node_id, expanded_key, entropy, secp_ctx
8276
8279
)
8277
8280
.chain_hash($self.chain_hash)
8278
- .path(path );
8281
+ .path(paths );
8279
8282
8280
8283
Ok(builder.into())
8281
8284
}
@@ -8337,13 +8340,16 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8337
8340
let entropy = &*$self.entropy_source;
8338
8341
let secp_ctx = &$self.secp_ctx;
8339
8342
8340
- let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8343
+ // TODO: Introduce a parameter to allow adding more paths to the created Refund.
8344
+ let paths = $self.create_blinded_path(1)
8345
+ .map_err(|_| Bolt12SemanticError::MissingPaths)?;
8346
+
8341
8347
let builder = RefundBuilder::deriving_payer_id(
8342
8348
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
8343
8349
)?
8344
8350
.chain_hash($self.chain_hash)
8345
8351
.absolute_expiry(absolute_expiry)
8346
- .path(path );
8352
+ .path(paths );
8347
8353
8348
8354
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
8349
8355
@@ -8460,7 +8466,8 @@ where
8460
8466
Some(payer_note) => builder.payer_note(payer_note),
8461
8467
};
8462
8468
let invoice_request = builder.build_and_sign()?;
8463
- let reply_path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
8469
+ let reply_paths = self.create_blinded_path(5)
8470
+ .map_err(|_| Bolt12SemanticError::MissingPaths)?;
8464
8471
8465
8472
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
8466
8473
@@ -8473,25 +8480,32 @@ where
8473
8480
8474
8481
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8475
8482
if !offer.paths().is_empty() {
8476
- // Send as many invoice requests as there are paths in the offer (with an upper bound).
8477
- // Using only one path could result in a failure if the path no longer exists. But only
8478
- // one invoice for a given payment id will be paid, even if more than one is received.
8483
+ // Send as many invoice requests as there are paths in the offer using as many different
8484
+ // reply_paths possible (with an upper bound).
8485
+ // Using only one path could result in a failure if the path no longer exists.
8486
+ // But only one invoice for a given payment ID will be paid, even if more than one is received.
8479
8487
const REQUEST_LIMIT: usize = 10;
8480
- for path in offer.paths().into_iter().take(REQUEST_LIMIT) {
8488
+ reply_paths
8489
+ .iter()
8490
+ .flat_map(|reply_path| offer.paths().iter().map(|path| (path.clone(), reply_path.clone())))
8491
+ .take(REQUEST_LIMIT)
8492
+ .for_each(|(path, reply_path)| {
8493
+ let message = new_pending_onion_message(
8494
+ OffersMessage::InvoiceRequest(invoice_request.clone()),
8495
+ Destination::BlindedPath(path.clone()),
8496
+ Some(reply_path.clone()),
8497
+ );
8498
+ pending_offers_messages.push(message);
8499
+ });
8500
+ } else if let Some(signing_pubkey) = offer.signing_pubkey() {
8501
+ for reply_path in reply_paths {
8481
8502
let message = new_pending_onion_message(
8482
8503
OffersMessage::InvoiceRequest(invoice_request.clone()),
8483
- Destination::BlindedPath(path.clone() ),
8484
- Some(reply_path.clone() ),
8504
+ Destination::Node(signing_pubkey ),
8505
+ Some(reply_path),
8485
8506
);
8486
8507
pending_offers_messages.push(message);
8487
8508
}
8488
- } else if let Some(signing_pubkey) = offer.signing_pubkey() {
8489
- let message = new_pending_onion_message(
8490
- OffersMessage::InvoiceRequest(invoice_request),
8491
- Destination::Node(signing_pubkey),
8492
- Some(reply_path),
8493
- );
8494
- pending_offers_messages.push(message);
8495
8509
} else {
8496
8510
debug_assert!(false);
8497
8511
return Err(Bolt12SemanticError::MissingSigningPubkey);
@@ -8560,26 +8574,30 @@ where
8560
8574
)?;
8561
8575
let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
8562
8576
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
8563
- let reply_path = self.create_blinded_path()
8577
+ let reply_paths = self.create_blinded_path(5 )
8564
8578
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8565
8579
8566
8580
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8567
8581
if refund.paths().is_empty() {
8568
- let message = new_pending_onion_message(
8569
- OffersMessage::Invoice(invoice.clone()),
8570
- Destination::Node(refund.payer_id()),
8571
- Some(reply_path),
8572
- );
8573
- pending_offers_messages.push(message);
8574
- } else {
8575
- for path in refund.paths() {
8582
+ for reply_path in reply_paths {
8576
8583
let message = new_pending_onion_message(
8577
8584
OffersMessage::Invoice(invoice.clone()),
8578
- Destination::BlindedPath(path.clone ()),
8579
- Some(reply_path.clone() ),
8585
+ Destination::Node(refund.payer_id ()),
8586
+ Some(reply_path),
8580
8587
);
8581
8588
pending_offers_messages.push(message);
8582
8589
}
8590
+ } else {
8591
+ for path in refund.paths() {
8592
+ for reply_path in reply_paths.clone() {
8593
+ let message = new_pending_onion_message(
8594
+ OffersMessage::Invoice(invoice.clone()),
8595
+ Destination::BlindedPath(path.clone()),
8596
+ Some(reply_path.clone()),
8597
+ );
8598
+ pending_offers_messages.push(message);
8599
+ }
8600
+ }
8583
8601
}
8584
8602
8585
8603
Ok(invoice)
@@ -8689,7 +8707,7 @@ where
8689
8707
/// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
8690
8708
///
8691
8709
/// Errors if the `MessageRouter` errors or returns an empty `Vec`.
8692
- fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
8710
+ fn create_blinded_path(&self, count: usize ) -> Result<Vec< BlindedPath> , ()> {
8693
8711
let recipient = self.get_our_node_id();
8694
8712
let secp_ctx = &self.secp_ctx;
8695
8713
@@ -8708,8 +8726,7 @@ where
8708
8726
.collect::<Vec<_>>();
8709
8727
8710
8728
self.router
8711
- .create_blinded_paths(recipient, peers, secp_ctx)
8712
- .and_then(|paths| paths.into_iter().next().ok_or(()))
8729
+ .create_blinded_paths(recipient, peers, secp_ctx, count)
8713
8730
}
8714
8731
8715
8732
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
0 commit comments