Skip to content

Commit 46bf9bc

Browse files
committed
Remove create_compact_blinded_paths
1. The `params` parameter now allows specifying the type of blinded path to be created, enabling a single function to handle the processing for both compact and full-length blinded paths. 2. This change renders the `create_compact_blinded_paths` function redundant, leading to its removal. 3. With this commit, the blinded path creation process is streamlined to a single function capable of creating any type of blinded path.
1 parent 47077a6 commit 46bf9bc

File tree

7 files changed

+33
-127
lines changed

7 files changed

+33
-127
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
3333
use bitcoin::hashes::Hash as TraitImport;
3434
use bitcoin::WPubkeyHash;
3535

36-
use lightning::blinded_path::message::{BlindedMessagePath, MessageContext};
36+
use lightning::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext};
3737
use lightning::blinded_path::payment::{BlindedPaymentPath, ReceiveTlvs};
3838
use lightning::chain;
3939
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
@@ -142,7 +142,7 @@ impl MessageRouter for FuzzRouter {
142142

143143
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
144144
&self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext,
145-
_peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
145+
_peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>,
146146
) -> Result<Vec<BlindedMessagePath>, ()> {
147147
unreachable!()
148148
}

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use bitcoin::hashes::Hash as _;
3030
use bitcoin::hex::FromHex;
3131
use bitcoin::WPubkeyHash;
3232

33-
use lightning::blinded_path::message::{BlindedMessagePath, MessageContext};
33+
use lightning::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext};
3434
use lightning::blinded_path::payment::{BlindedPaymentPath, ReceiveTlvs};
3535
use lightning::chain;
3636
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
@@ -179,7 +179,7 @@ impl MessageRouter for FuzzRouter {
179179

180180
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
181181
&self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext,
182-
_peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
182+
_peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>,
183183
) -> Result<Vec<BlindedMessagePath>, ()> {
184184
unreachable!()
185185
}

fuzz/src/onion_message.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use bitcoin::secp256k1::ecdsa::RecoverableSignature;
55
use bitcoin::secp256k1::schnorr;
66
use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
77

8-
use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, OffersContext};
8+
use lightning::blinded_path::message::{
9+
BlindedMessagePath, MessageForwardNode, MessageContext, OffersContext,
10+
};
911
use lightning::blinded_path::EmptyNodeIdLookUp;
1012
use lightning::ln::features::InitFeatures;
1113
use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler};
@@ -97,7 +99,7 @@ impl MessageRouter for TestMessageRouter {
9799

98100
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
99101
&self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext,
100-
_peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
102+
_peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>,
101103
) -> Result<Vec<BlindedMessagePath>, ()> {
102104
unreachable!()
103105
}

lightning/src/ln/channelmanager.rs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,9 +2505,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
25052505
/// short-lived, while anything with a greater expiration is considered long-lived.
25062506
///
25072507
/// Using [`ChannelManager::create_offer_builder`] or [`ChannelManager::create_refund_builder`],
2508-
/// will included a [`BlindedMessagePath`] created using:
2509-
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2510-
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
2508+
/// will included a [`BlindedMessagePath`] created using [`MessageRouter::create_blinded_paths`].
25112509
///
25122510
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
25132511
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
@@ -9376,40 +9374,27 @@ where
93769374
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
93779375
.filter(|(_, peer)| peer.is_connected)
93789376
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9379-
.map(|(node_id, _)| *node_id)
9380-
.collect::<Vec<_>>();
9381-
9382-
self.router
9383-
.create_blinded_paths(params, recipient, MessageContext::Offers(context), peers, secp_ctx)
9384-
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9385-
}
9386-
9387-
/// Creates a collection of blinded paths by delegating to
9388-
/// [`MessageRouter::create_compact_blinded_paths`].
9389-
///
9390-
/// Errors if the `MessageRouter` errors.
9391-
#[allow(unused)]
9392-
fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9393-
let recipient = self.get_our_node_id();
9394-
let secp_ctx = &self.secp_ctx;
9395-
9396-
let peers = self.per_peer_state.read().unwrap()
9397-
.iter()
9398-
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9399-
.filter(|(_, peer)| peer.is_connected)
9400-
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9401-
.map(|(node_id, peer)| MessageForwardNode {
9402-
node_id: *node_id,
9403-
short_channel_id: peer.channel_by_id
9404-
.iter()
9405-
.filter(|(_, channel)| channel.context().is_usable())
9406-
.min_by_key(|(_, channel)| channel.context().channel_creation_height)
9407-
.and_then(|(_, channel)| channel.context().get_short_channel_id()),
9377+
.map(|(node_id, peer)| {
9378+
if params.is_compact {
9379+
MessageForwardNode {
9380+
node_id: *node_id,
9381+
short_channel_id: peer.channel_by_id
9382+
.iter()
9383+
.filter(|(_, channel)| channel.context().is_usable())
9384+
.min_by_key(|(_, channel)| channel.context().channel_creation_height)
9385+
.and_then(|(_, channel)| channel.context().get_short_channel_id()),
9386+
}
9387+
} else {
9388+
MessageForwardNode {
9389+
node_id: *node_id,
9390+
short_channel_id: None,
9391+
}
9392+
}
94089393
})
94099394
.collect::<Vec<_>>();
94109395

94119396
self.router
9412-
.create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9397+
.create_blinded_paths(params, recipient, MessageContext::Offers(context), peers, secp_ctx)
94139398
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
94149399
}
94159400

lightning/src/onion_message/messenger.rs

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
175175
/// # })
176176
/// # }
177177
/// # fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
178-
/// # &self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
178+
/// # &self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>
179179
/// # ) -> Result<Vec<BlindedMessagePath>, ()> {
180180
/// # unreachable!()
181181
/// # }
@@ -460,40 +460,8 @@ pub trait MessageRouter {
460460
fn create_blinded_paths<
461461
T: secp256k1::Signing + secp256k1::Verification
462462
>(
463-
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
463+
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
464464
) -> Result<Vec<BlindedMessagePath>, ()>;
465-
466-
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
467-
/// assumed to be direct peers with the `recipient`.
468-
///
469-
/// Compact blinded paths use short channel ids instead of pubkeys for a smaller serialization,
470-
/// which is beneficial when a QR code is used to transport the data. The SCID is passed using
471-
/// a [`MessageForwardNode`] but may be `None` for graceful degradation.
472-
///
473-
/// Implementations using additional intermediate nodes are responsible for using a
474-
/// [`MessageForwardNode`] with `Some` short channel id, if possible. Similarly, implementations
475-
/// should call [`BlindedMessagePath::use_compact_introduction_node`].
476-
///
477-
/// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`],
478-
/// ignoring the short channel ids.
479-
fn create_compact_blinded_paths<
480-
T: secp256k1::Signing + secp256k1::Verification
481-
>(
482-
&self, recipient: PublicKey, context: MessageContext,
483-
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
484-
) -> Result<Vec<BlindedMessagePath>, ()> {
485-
let peers = peers
486-
.into_iter()
487-
.map(|MessageForwardNode { node_id, short_channel_id: _ }| node_id)
488-
.collect();
489-
490-
// This parameter is a placeholder. This function is removed in the subsequent commits.
491-
let params = BlindedPathParams {
492-
paths: PATHS_PLACEHOLDER,
493-
is_compact: true,
494-
};
495-
self.create_blinded_paths(params, recipient, context, peers, secp_ctx)
496-
}
497465
}
498466

499467
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
@@ -627,24 +595,8 @@ where
627595
T: secp256k1::Signing + secp256k1::Verification
628596
>(
629597
params: BlindedPathParams, network_graph: &G, recipient: PublicKey, context: MessageContext,
630-
peers: Vec<PublicKey>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
631-
) -> Result<Vec<BlindedMessagePath>, ()> {
632-
let peers = peers
633-
.into_iter()
634-
.map(|node_id| MessageForwardNode { node_id, short_channel_id: None });
635-
Self::create_blinded_paths_from_iter(params, network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx)
636-
}
637-
638-
pub(crate) fn create_compact_blinded_paths<
639-
T: secp256k1::Signing + secp256k1::Verification
640-
>(
641-
network_graph: &G, recipient: PublicKey, context: MessageContext,
642598
peers: Vec<MessageForwardNode>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
643599
) -> Result<Vec<BlindedMessagePath>, ()> {
644-
let params = BlindedPathParams {
645-
paths: PATHS_PLACEHOLDER,
646-
is_compact: true,
647-
};
648600
Self::create_blinded_paths_from_iter(params, network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx)
649601
}
650602
}
@@ -663,19 +615,10 @@ where
663615
fn create_blinded_paths<
664616
T: secp256k1::Signing + secp256k1::Verification
665617
>(
666-
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
618+
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
667619
) -> Result<Vec<BlindedMessagePath>, ()> {
668620
Self::create_blinded_paths(params, &self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
669621
}
670-
671-
fn create_compact_blinded_paths<
672-
T: secp256k1::Signing + secp256k1::Verification
673-
>(
674-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
675-
) -> Result<Vec<BlindedMessagePath>, ()> {
676-
Self::create_compact_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
677-
}
678-
679622
}
680623

681624
/// A path for sending an [`OnionMessage`].
@@ -1270,7 +1213,7 @@ where
12701213
let peers = self.message_recipients.lock().unwrap()
12711214
.iter()
12721215
.filter(|(_, peer)| matches!(peer, OnionMessageRecipient::ConnectedPeer(_)))
1273-
.map(|(node_id, _ )| *node_id)
1216+
.map(|(node_id, _)| MessageForwardNode { node_id: *node_id, short_channel_id: None })
12741217
.collect::<Vec<_>>();
12751218

12761219
self.message_router

lightning/src/routing/router.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,10 @@ impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Siz
197197
fn create_blinded_paths<
198198
T: secp256k1::Signing + secp256k1::Verification
199199
> (
200-
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
200+
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
201201
) -> Result<Vec<BlindedMessagePath>, ()> {
202202
DefaultMessageRouter::create_blinded_paths(params, &self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
203203
}
204-
205-
fn create_compact_blinded_paths<
206-
T: secp256k1::Signing + secp256k1::Verification
207-
> (
208-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
209-
) -> Result<Vec<BlindedMessagePath>, ()> {
210-
DefaultMessageRouter::create_compact_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
211-
}
212204
}
213205

214206
/// A trait defining behavior for routing a payment.

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,9 @@ impl<'a> MessageRouter for TestRouter<'a> {
277277
T: secp256k1::Signing + secp256k1::Verification
278278
>(
279279
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext,
280-
peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
281-
) -> Result<Vec<BlindedMessagePath>, ()> {
282-
self.router.create_blinded_paths(params, recipient, context, peers, secp_ctx)
283-
}
284-
285-
fn create_compact_blinded_paths<
286-
T: secp256k1::Signing + secp256k1::Verification
287-
>(
288-
&self, recipient: PublicKey, context: MessageContext,
289280
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
290281
) -> Result<Vec<BlindedMessagePath>, ()> {
291-
self.router.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
282+
self.router.create_blinded_paths(params, recipient, context, peers, secp_ctx)
292283
}
293284
}
294285

@@ -320,16 +311,9 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
320311

321312
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
322313
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext,
323-
peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
324-
) -> Result<Vec<BlindedMessagePath>, ()> {
325-
self.inner.create_blinded_paths(params, recipient, context, peers, secp_ctx)
326-
}
327-
328-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
329-
&self, recipient: PublicKey, context: MessageContext,
330314
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
331315
) -> Result<Vec<BlindedMessagePath>, ()> {
332-
self.inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
316+
self.inner.create_blinded_paths(params, recipient, context, peers, secp_ctx)
333317
}
334318
}
335319

0 commit comments

Comments
 (0)