@@ -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};
@@ -1733,7 +1734,7 @@ where
17331734/// let default_config = UserConfig::default();
17341735/// let channel_manager = ChannelManager::new(
17351736/// fee_estimator, chain_monitor, tx_broadcaster, router, message_router, logger,
1736- /// entropy_source, node_signer, signer_provider, default_config, params, current_timestamp,
1737+ /// entropy_source, node_signer, signer_provider, default_config.clone() , params, current_timestamp,
17371738/// );
17381739///
17391740/// // Restart from deserialized data
@@ -4954,19 +4955,10 @@ where
49544955 };
49554956
49564957 let mut pending_async_payments_messages = self.pending_async_payments_messages.lock().unwrap();
4957- const HTLC_AVAILABLE_LIMIT: usize = 10;
4958- reply_paths
4959- .iter()
4960- .flat_map(|reply_path| invoice.message_paths().iter().map(move |invoice_path| (invoice_path, reply_path)))
4961- .take(HTLC_AVAILABLE_LIMIT)
4962- .for_each(|(invoice_path, reply_path)| {
4963- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
4964- destination: Destination::BlindedPath(invoice_path.clone()),
4965- reply_path: reply_path.clone(),
4966- };
4967- let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
4968- pending_async_payments_messages.push((message, instructions));
4969- });
4958+ let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
4959+ enqueue_onion_message_with_reply_paths(
4960+ message, invoice.message_paths(), reply_paths, &mut pending_async_payments_messages
4961+ );
49704962
49714963 NotifyOption::DoPersist
49724964 });
@@ -10530,18 +10522,10 @@ where
1053010522 ) -> Result<(), Bolt12SemanticError> {
1053110523 let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
1053210524 if !invoice_request.paths().is_empty() {
10533- reply_paths
10534- .iter()
10535- .flat_map(|reply_path| invoice_request.paths().iter().map(move |path| (path, reply_path)))
10536- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
10537- .for_each(|(path, reply_path)| {
10538- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10539- destination: Destination::BlindedPath(path.clone()),
10540- reply_path: reply_path.clone(),
10541- };
10542- let message = OffersMessage::InvoiceRequest(invoice_request.clone());
10543- pending_offers_messages.push((message, instructions));
10544- });
10525+ let message = OffersMessage::InvoiceRequest(invoice_request.clone());
10526+ enqueue_onion_message_with_reply_paths(
10527+ message, invoice_request.paths(), reply_paths, &mut pending_offers_messages
10528+ );
1054510529 } else if let Some(node_id) = invoice_request.issuer_signing_pubkey() {
1054610530 for reply_path in reply_paths {
1054710531 let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
@@ -10639,18 +10623,10 @@ where
1063910623 pending_offers_messages.push((message, instructions));
1064010624 }
1064110625 } else {
10642- reply_paths
10643- .iter()
10644- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
10645- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
10646- .for_each(|(path, reply_path)| {
10647- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10648- destination: Destination::BlindedPath(path.clone()),
10649- reply_path: reply_path.clone(),
10650- };
10651- let message = OffersMessage::Invoice(invoice.clone());
10652- pending_offers_messages.push((message, instructions));
10653- });
10626+ let message = OffersMessage::Invoice(invoice.clone());
10627+ enqueue_onion_message_with_reply_paths(
10628+ message, refund.paths(), reply_paths, &mut pending_offers_messages
10629+ );
1065410630 }
1065510631
1065610632 Ok(invoice)
@@ -12792,6 +12768,27 @@ where
1279212768 }
1279312769}
1279412770
12771+ fn enqueue_onion_message_with_reply_paths<T: OnionMessageContents + Clone>(
12772+ message: T, message_paths: &[BlindedMessagePath], reply_paths: Vec<BlindedMessagePath>,
12773+ queue: &mut Vec<(T, MessageSendInstructions)>
12774+ ) {
12775+ reply_paths
12776+ .iter()
12777+ .flat_map(|reply_path|
12778+ message_paths
12779+ .iter()
12780+ .map(move |path| (path.clone(), reply_path))
12781+ )
12782+ .take(OFFERS_MESSAGE_REQUEST_LIMIT)
12783+ .for_each(|(path, reply_path)| {
12784+ let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
12785+ destination: Destination::BlindedPath(path.clone()),
12786+ reply_path: reply_path.clone(),
12787+ };
12788+ queue.push((message.clone(), instructions));
12789+ });
12790+ }
12791+
1279512792/// Fetches the set of [`NodeFeatures`] flags that are provided by or required by
1279612793/// [`ChannelManager`].
1279712794pub(crate) fn provided_node_features(config: &UserConfig) -> NodeFeatures {
@@ -16076,7 +16073,7 @@ mod tests {
1607616073 let chanmon_cfg = create_chanmon_cfgs(2);
1607716074 let node_cfg = create_node_cfgs(2, &chanmon_cfg);
1607816075 let mut user_config = test_default_channel_config();
16079- let node_chanmgr = create_node_chanmgrs(2, &node_cfg, &[Some(user_config) , Some(user_config)]);
16076+ let node_chanmgr = create_node_chanmgrs(2, &node_cfg, &[Some(user_config.clone()) , Some(user_config.clone() )]);
1608016077 let nodes = create_network(2, &node_cfg, &node_chanmgr);
1608116078 let _ = create_announced_chan_between_nodes(&nodes, 0, 1);
1608216079 let channel = &nodes[0].node.list_channels()[0];
@@ -16163,7 +16160,7 @@ mod tests {
1616316160 let chanmon_cfg = create_chanmon_cfgs(2);
1616416161 let node_cfg = create_node_cfgs(2, &chanmon_cfg);
1616516162 let user_config = test_default_channel_config();
16166- let node_chanmgr = create_node_chanmgrs(2, &node_cfg, &[Some(user_config), Some(user_config)]);
16163+ let node_chanmgr = create_node_chanmgrs(2, &node_cfg, &[Some(user_config.clone() ), Some(user_config)]);
1616716164 let nodes = create_network(2, &node_cfg, &node_chanmgr);
1616816165 let error_message = "Channel force-closed";
1616916166
0 commit comments