@@ -2625,9 +2625,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
26252625/// short-lived, while anything with a greater expiration is considered long-lived.
26262626///
26272627/// Using [`ChannelManager::create_offer_builder`] or [`ChannelManager::create_refund_builder`],
2628- /// will included a [`BlindedMessagePath`] created using:
2629- /// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2630- /// - [`MessageRouter::create_blinded_paths`] when long-lived.
2628+ /// will included a [`BlindedMessagePath`] created using [`MessageRouter::create_blinded_paths`].
26312629///
26322630/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
26332631/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
@@ -4453,7 +4451,7 @@ where
44534451 let reply_paths = match self.create_blinded_paths(
44544452 MessageContext::AsyncPayments(
44554453 AsyncPaymentsContext::OutboundPayment { payment_id, nonce, hmac }
4456- )
4454+ ), BlindedPathType::Full
44574455 ) {
44584456 Ok(paths) => paths,
44594457 Err(()) => {
@@ -9123,23 +9121,13 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
91239121 let secp_ctx = &$self.secp_ctx;
91249122
91259123 let nonce = Nonce::from_entropy_source(entropy);
9126- let context = OffersContext::InvoiceRequest { nonce };
9124+ let context = MessageContext::Offers (
9125+ OffersContext::InvoiceRequest { nonce }
9126+ );
91279127 let builder = match blinded_path {
9128- Some(BlindedPathType::Compact) => {
9129- let path = $self
9130- .create_compact_blinded_paths(context)
9131- .and_then(|paths| paths.into_iter().next().ok_or(()))
9132- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9133-
9134- OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
9135- .chain_hash($self.chain_hash)
9136- .path(path)
9137- }
9138-
9139- Some(BlindedPathType::Full) => {
9140- let context = MessageContext::Offers(context);
9128+ Some(blinded_path) => {
91419129 let path = $self
9142- .create_blinded_paths(context)
9130+ .create_blinded_paths(context, blinded_path )
91439131 .and_then(|paths| paths.into_iter().next().ok_or(()))
91449132 .map_err(|_| Bolt12SemanticError::MissingPaths)?;
91459133
@@ -9212,28 +9200,14 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
92129200 let secp_ctx = &$self.secp_ctx;
92139201
92149202 let nonce = Nonce::from_entropy_source(entropy);
9215- let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
9203+ let context = MessageContext::Offers (
9204+ OffersContext::OutboundPayment { payment_id, nonce, hmac: None }
9205+ );
92169206
92179207 let builder = match blinded_path {
9218- Some(BlindedPathType::Compact ) => {
9208+ Some(blinded_path ) => {
92199209 let path = $self
9220- .create_compact_blinded_paths(context)
9221- .and_then(|paths| paths.into_iter().next().ok_or(()))
9222- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9223-
9224- RefundBuilder::deriving_signing_pubkey(
9225- node_id, expanded_key, nonce, secp_ctx,
9226- amount_msats, payment_id,
9227- )?
9228- .chain_hash($self.chain_hash)
9229- .absolute_expiry(absolute_expiry)
9230- .path(path)
9231- }
9232-
9233- Some(BlindedPathType::Full) => {
9234- let context = MessageContext::Offers(context);
9235- let path = $self
9236- .create_blinded_paths(context)
9210+ .create_blinded_paths(context, blinded_path)
92379211 .and_then(|paths| paths.into_iter().next().ok_or(()))
92389212 .map_err(|_| Bolt12SemanticError::MissingPaths)?;
92399213
@@ -9383,7 +9357,7 @@ where
93839357 let context = MessageContext::Offers(
93849358 OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
93859359 );
9386- let reply_paths = self.create_blinded_paths(context)
9360+ let reply_paths = self.create_blinded_paths(context, BlindedPathType::Full )
93879361 .map_err(|_| Bolt12SemanticError::MissingPaths)?;
93889362
93899363 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
@@ -9505,7 +9479,7 @@ where
95059479 let context = MessageContext::Offers(OffersContext::InboundPayment {
95069480 payment_hash: invoice.payment_hash(), nonce, hmac
95079481 });
9508- let reply_paths = self.create_blinded_paths(context)
9482+ let reply_paths = self.create_blinded_paths(context, BlindedPathType::Full )
95099483 .map_err(|_| Bolt12SemanticError::MissingPaths)?;
95109484
95119485 let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
@@ -9655,7 +9629,7 @@ where
96559629 /// [`MessageRouter::create_blinded_paths`].
96569630 ///
96579631 /// Errors if the `MessageRouter` errors.
9658- fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()> {
9632+ fn create_blinded_paths(&self, context: MessageContext, blinded_path: BlindedPathType ) -> Result<Vec<BlindedMessagePath>, ()> {
96599633 let recipient = self.get_our_node_id();
96609634 let secp_ctx = &self.secp_ctx;
96619635
@@ -9664,44 +9638,30 @@ where
96649638 .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
96659639 .filter(|(_, peer)| peer.is_connected)
96669640 .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9667- .map(|(node_id, _)| {
9668- MessageForwardNode {
9669- node_id: *node_id,
9670- short_channel_id: None,
9641+ .map(|(node_id, peer)| {
9642+ match blinded_path {
9643+ BlindedPathType::Full => {
9644+ MessageForwardNode {
9645+ node_id: *node_id,
9646+ short_channel_id: None,
9647+ }
9648+ }
9649+ BlindedPathType::Compact => {
9650+ MessageForwardNode {
9651+ node_id: *node_id,
9652+ short_channel_id: peer.channel_by_id
9653+ .iter()
9654+ .filter(|(_, channel)| channel.context().is_usable())
9655+ .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9656+ .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9657+ }
9658+ }
96719659 }
96729660 })
96739661 .collect::<Vec<_>>();
96749662
96759663 self.message_router
9676- .create_blinded_paths(recipient, context, peers, secp_ctx)
9677- .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9678- }
9679-
9680- /// Creates a collection of blinded paths by delegating to
9681- /// [`MessageRouter::create_compact_blinded_paths`].
9682- ///
9683- /// Errors if the `MessageRouter` errors.
9684- fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9685- let recipient = self.get_our_node_id();
9686- let secp_ctx = &self.secp_ctx;
9687-
9688- let peers = self.per_peer_state.read().unwrap()
9689- .iter()
9690- .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9691- .filter(|(_, peer)| peer.is_connected)
9692- .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9693- .map(|(node_id, peer)| MessageForwardNode {
9694- node_id: *node_id,
9695- short_channel_id: peer.channel_by_id
9696- .iter()
9697- .filter(|(_, channel)| channel.context().is_usable())
9698- .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9699- .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9700- })
9701- .collect::<Vec<_>>();
9702-
9703- self.message_router
9704- .create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9664+ .create_blinded_paths(recipient, context, blinded_path, peers, secp_ctx)
97059665 .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
97069666 }
97079667
@@ -11088,7 +11048,7 @@ where
1108811048 nonce,
1108911049 hmac: Some(hmac)
1109011050 });
11091- match self.create_blinded_paths(context) {
11051+ match self.create_blinded_paths(context, BlindedPathType::Full ) {
1109211052 Ok(reply_paths) => match self.enqueue_invoice_request(invoice_request, reply_paths) {
1109311053 Ok(_) => {}
1109411054 Err(_) => {
0 commit comments