@@ -78,6 +78,7 @@ use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailab
78
78
use crate::onion_message::dns_resolution::HumanReadableName;
79
79
use crate::onion_message::messenger::{Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions};
80
80
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
81
+ use crate::onion_message::packet::OnionMessageContents;
81
82
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
82
83
use crate::sign::ecdsa::EcdsaChannelSigner;
83
84
use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelConfigOverrides, UserConfig};
@@ -4867,19 +4868,10 @@ where
4867
4868
};
4868
4869
4869
4870
let mut pending_async_payments_messages = self.pending_async_payments_messages.lock().unwrap();
4870
- const HTLC_AVAILABLE_LIMIT: usize = 10;
4871
- reply_paths
4872
- .iter()
4873
- .flat_map(|reply_path| invoice.message_paths().iter().map(move |invoice_path| (invoice_path, reply_path)))
4874
- .take(HTLC_AVAILABLE_LIMIT)
4875
- .for_each(|(invoice_path, reply_path)| {
4876
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
4877
- destination: Destination::BlindedPath(invoice_path.clone()),
4878
- reply_path: reply_path.clone(),
4879
- };
4880
- let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
4881
- pending_async_payments_messages.push((message, instructions));
4882
- });
4871
+ let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
4872
+ queue_onion_message_with_reply_paths(
4873
+ message, invoice.message_paths(), reply_paths, &mut pending_async_payments_messages
4874
+ );
4883
4875
4884
4876
NotifyOption::DoPersist
4885
4877
});
@@ -10434,18 +10426,10 @@ where
10434
10426
) -> Result<(), Bolt12SemanticError> {
10435
10427
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
10436
10428
if !invoice_request.paths().is_empty() {
10437
- reply_paths
10438
- .iter()
10439
- .flat_map(|reply_path| invoice_request.paths().iter().map(move |path| (path, reply_path)))
10440
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
10441
- .for_each(|(path, reply_path)| {
10442
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10443
- destination: Destination::BlindedPath(path.clone()),
10444
- reply_path: reply_path.clone(),
10445
- };
10446
- let message = OffersMessage::InvoiceRequest(invoice_request.clone());
10447
- pending_offers_messages.push((message, instructions));
10448
- });
10429
+ let message = OffersMessage::InvoiceRequest(invoice_request.clone());
10430
+ queue_onion_message_with_reply_paths(
10431
+ message, invoice_request.paths(), reply_paths, &mut pending_offers_messages
10432
+ );
10449
10433
} else if let Some(node_id) = invoice_request.issuer_signing_pubkey() {
10450
10434
for reply_path in reply_paths {
10451
10435
let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
@@ -10543,18 +10527,10 @@ where
10543
10527
pending_offers_messages.push((message, instructions));
10544
10528
}
10545
10529
} else {
10546
- reply_paths
10547
- .iter()
10548
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
10549
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
10550
- .for_each(|(path, reply_path)| {
10551
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10552
- destination: Destination::BlindedPath(path.clone()),
10553
- reply_path: reply_path.clone(),
10554
- };
10555
- let message = OffersMessage::Invoice(invoice.clone());
10556
- pending_offers_messages.push((message, instructions));
10557
- });
10530
+ let message = OffersMessage::Invoice(invoice.clone());
10531
+ queue_onion_message_with_reply_paths(
10532
+ message, refund.paths(), reply_paths, &mut pending_offers_messages
10533
+ );
10558
10534
}
10559
10535
10560
10536
Ok(invoice)
@@ -12689,6 +12665,27 @@ where
12689
12665
}
12690
12666
}
12691
12667
12668
+ fn queue_onion_message_with_reply_paths<T: OnionMessageContents + Clone>(
12669
+ message: T, message_paths: &[BlindedMessagePath], reply_paths: Vec<BlindedMessagePath>,
12670
+ queue: &mut Vec<(T, MessageSendInstructions)>
12671
+ ) {
12672
+ reply_paths
12673
+ .iter()
12674
+ .flat_map(|reply_path|
12675
+ message_paths
12676
+ .iter()
12677
+ .map(move |path| (path.clone(), reply_path))
12678
+ )
12679
+ .take(OFFERS_MESSAGE_REQUEST_LIMIT)
12680
+ .for_each(|(path, reply_path)| {
12681
+ let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
12682
+ destination: Destination::BlindedPath(path.clone()),
12683
+ reply_path: reply_path.clone(),
12684
+ };
12685
+ queue.push((message.clone(), instructions));
12686
+ });
12687
+ }
12688
+
12692
12689
/// Fetches the set of [`NodeFeatures`] flags that are provided by or required by
12693
12690
/// [`ChannelManager`].
12694
12691
pub(crate) fn provided_node_features(config: &UserConfig) -> NodeFeatures {
0 commit comments