@@ -77,6 +77,7 @@ use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailab
7777use crate::onion_message::dns_resolution::HumanReadableName;
7878use crate::onion_message::messenger::{Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions};
7979use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
80+ use crate::onion_message::packet::OnionMessageContents;
8081use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
8182use crate::sign::ecdsa::EcdsaChannelSigner;
8283use crate::util::config::{ChannelConfig, ChannelConfigUpdate, ChannelConfigOverrides, UserConfig};
@@ -4967,19 +4968,10 @@ where
49674968 };
49684969
49694970 let mut pending_async_payments_messages = self.pending_async_payments_messages.lock().unwrap();
4970- const HTLC_AVAILABLE_LIMIT: usize = 10;
4971- reply_paths
4972- .iter()
4973- .flat_map(|reply_path| invoice.message_paths().iter().map(move |invoice_path| (invoice_path, reply_path)))
4974- .take(HTLC_AVAILABLE_LIMIT)
4975- .for_each(|(invoice_path, reply_path)| {
4976- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
4977- destination: Destination::BlindedPath(invoice_path.clone()),
4978- reply_path: reply_path.clone(),
4979- };
4980- let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
4981- pending_async_payments_messages.push((message, instructions));
4982- });
4971+ let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
4972+ queue_onion_message_with_reply_paths(
4973+ message, invoice.message_paths(), reply_paths, &mut pending_async_payments_messages
4974+ );
49834975
49844976 NotifyOption::DoPersist
49854977 });
@@ -10544,18 +10536,10 @@ where
1054410536 ) -> Result<(), Bolt12SemanticError> {
1054510537 let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
1054610538 if !invoice_request.paths().is_empty() {
10547- reply_paths
10548- .iter()
10549- .flat_map(|reply_path| invoice_request.paths().iter().map(move |path| (path, reply_path)))
10550- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
10551- .for_each(|(path, reply_path)| {
10552- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10553- destination: Destination::BlindedPath(path.clone()),
10554- reply_path: reply_path.clone(),
10555- };
10556- let message = OffersMessage::InvoiceRequest(invoice_request.clone());
10557- pending_offers_messages.push((message, instructions));
10558- });
10539+ let message = OffersMessage::InvoiceRequest(invoice_request.clone());
10540+ queue_onion_message_with_reply_paths(
10541+ message, invoice_request.paths(), reply_paths, &mut pending_offers_messages
10542+ );
1055910543 } else if let Some(node_id) = invoice_request.issuer_signing_pubkey() {
1056010544 for reply_path in reply_paths {
1056110545 let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
@@ -10653,18 +10637,10 @@ where
1065310637 pending_offers_messages.push((message, instructions));
1065410638 }
1065510639 } else {
10656- reply_paths
10657- .iter()
10658- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
10659- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
10660- .for_each(|(path, reply_path)| {
10661- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10662- destination: Destination::BlindedPath(path.clone()),
10663- reply_path: reply_path.clone(),
10664- };
10665- let message = OffersMessage::Invoice(invoice.clone());
10666- pending_offers_messages.push((message, instructions));
10667- });
10640+ let message = OffersMessage::Invoice(invoice.clone());
10641+ queue_onion_message_with_reply_paths(
10642+ message, refund.paths(), reply_paths, &mut pending_offers_messages
10643+ );
1066810644 }
1066910645
1067010646 Ok(invoice)
@@ -12806,6 +12782,27 @@ where
1280612782 }
1280712783}
1280812784
12785+ fn queue_onion_message_with_reply_paths<T: OnionMessageContents + Clone>(
12786+ message: T, message_paths: &[BlindedMessagePath], reply_paths: Vec<BlindedMessagePath>,
12787+ queue: &mut Vec<(T, MessageSendInstructions)>
12788+ ) {
12789+ reply_paths
12790+ .iter()
12791+ .flat_map(|reply_path|
12792+ message_paths
12793+ .iter()
12794+ .map(move |path| (path.clone(), reply_path))
12795+ )
12796+ .take(OFFERS_MESSAGE_REQUEST_LIMIT)
12797+ .for_each(|(path, reply_path)| {
12798+ let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
12799+ destination: Destination::BlindedPath(path.clone()),
12800+ reply_path: reply_path.clone(),
12801+ };
12802+ queue.push((message.clone(), instructions));
12803+ });
12804+ }
12805+
1280912806/// Fetches the set of [`NodeFeatures`] flags that are provided by or required by
1281012807/// [`ChannelManager`].
1281112808pub(crate) fn provided_node_features(config: &UserConfig) -> NodeFeatures {
0 commit comments