Skip to content

Commit 6fa28be

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 27ca6ca commit 6fa28be

File tree

7 files changed

+39
-131
lines changed

7 files changed

+39
-131
lines changed

fuzz/src/chanmon_consistency.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ use lightning::ln::script::ShutdownScript;
5959
use lightning::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
6060
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
6161
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
62-
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
62+
use lightning::onion_message::messenger::{
63+
BlindedPathParams, Destination, MessageRouter, OnionMessagePath,
64+
};
6365
use lightning::routing::router::{InFlightHtlcs, Path, Route, RouteHop, RouteParameters, Router};
6466
use lightning::sign::{
6567
EntropySource, InMemorySigner, KeyMaterial, NodeSigner, Recipient, SignerProvider,
@@ -140,8 +142,8 @@ impl MessageRouter for FuzzRouter {
140142
}
141143

142144
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
143-
&self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>,
144-
_secp_ctx: &Secp256k1<T>,
145+
&self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext,
146+
_peers: Vec<ForwardNode>, _secp_ctx: &Secp256k1<T>,
145147
) -> Result<Vec<BlindedPath>, ()> {
146148
unreachable!()
147149
}

fuzz/src/full_stack.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ use lightning::ln::script::ShutdownScript;
5252
use lightning::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
5353
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
5454
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
55-
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
55+
use lightning::onion_message::messenger::{
56+
BlindedPathParams, Destination, MessageRouter, OnionMessagePath,
57+
};
5658
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
5759
use lightning::routing::router::{
5860
InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router,
@@ -177,8 +179,8 @@ impl MessageRouter for FuzzRouter {
177179
}
178180

179181
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
180-
&self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>,
181-
_secp_ctx: &Secp256k1<T>,
182+
&self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext,
183+
_peers: Vec<ForwardNode>, _secp_ctx: &Secp256k1<T>,
182184
) -> Result<Vec<BlindedPath>, ()> {
183185
unreachable!()
184186
}

fuzz/src/onion_message.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use lightning::onion_message::messenger::{
1919
CustomOnionMessageHandler, Destination, MessageRouter, OnionMessagePath, OnionMessenger,
2020
PendingOnionMessage, Responder, ResponseInstruction,
2121
};
22-
use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler};
22+
use lightning::onion_message::offers::{BlindedPathParams, OffersMessage, OffersMessageHandler};
2323
use lightning::onion_message::packet::OnionMessageContents;
2424
use lightning::sign::{EntropySource, KeyMaterial, NodeSigner, Recipient, SignerProvider};
2525
use lightning::util::logger::Logger;
@@ -96,8 +96,8 @@ impl MessageRouter for TestMessageRouter {
9696
}
9797

9898
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
99-
&self, _params: BlindedPathParams _recipient: PublicKey, _context: MessageContext, _peers: Vec<PublicKey>,
100-
_secp_ctx: &Secp256k1<T>,
99+
&self, _params: BlindedPathParams, _recipient: PublicKey, _context: MessageContext,
100+
_peers: Vec<ForwardNode>, _secp_ctx: &Secp256k1<T>,
101101
) -> Result<Vec<BlindedPath>, ()> {
102102
unreachable!()
103103
}

lightning/src/ln/channelmanager.rs

+18-33
Original file line numberDiff line numberDiff line change
@@ -2481,9 +2481,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
24812481
/// short-lived, while anything with a greater expiration is considered long-lived.
24822482
///
24832483
/// Using [`ChannelManager::create_offer_builder`] or [`ChannelManager::create_refund_builder`],
2484-
/// will included a [`BlindedPath`] created using:
2485-
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2486-
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
2484+
/// will included a [`BlindedPath`] created using [`MessageRouter::create_blinded_paths`].
24872485
///
24882486
/// Using compact [`BlindedPath`]s may provide better privacy as the [`MessageRouter`] could select
24892487
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
@@ -9312,40 +9310,27 @@ where
93129310
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
93139311
.filter(|(_, peer)| peer.is_connected)
93149312
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9315-
.map(|(node_id, _)| *node_id)
9316-
.collect::<Vec<_>>();
9317-
9318-
self.router
9319-
.create_blinded_paths(params, recipient, MessageContext::Offers(context), peers, secp_ctx)
9320-
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9321-
}
9322-
9323-
/// Creates a collection of blinded paths by delegating to
9324-
/// [`MessageRouter::create_compact_blinded_paths`].
9325-
///
9326-
/// Errors if the `MessageRouter` errors.
9327-
#[allow(unused)]
9328-
fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedPath>, ()> {
9329-
let recipient = self.get_our_node_id();
9330-
let secp_ctx = &self.secp_ctx;
9331-
9332-
let peers = self.per_peer_state.read().unwrap()
9333-
.iter()
9334-
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9335-
.filter(|(_, peer)| peer.is_connected)
9336-
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9337-
.map(|(node_id, peer)| ForwardNode {
9338-
node_id: *node_id,
9339-
short_channel_id: peer.channel_by_id
9340-
.iter()
9341-
.filter(|(_, channel)| channel.context().is_usable())
9342-
.min_by_key(|(_, channel)| channel.context().channel_creation_height)
9343-
.and_then(|(_, channel)| channel.context().get_short_channel_id()),
9313+
.map(|(node_id, peer)| {
9314+
if params.is_compact {
9315+
ForwardNode {
9316+
node_id: *node_id,
9317+
short_channel_id: peer.channel_by_id
9318+
.iter()
9319+
.filter(|(_, channel)| channel.context().is_usable())
9320+
.min_by_key(|(_, channel)| channel.context().channel_creation_height)
9321+
.and_then(|(_, channel)| channel.context().get_short_channel_id()),
9322+
}
9323+
} else {
9324+
ForwardNode {
9325+
node_id: *node_id,
9326+
short_channel_id: None,
9327+
}
9328+
}
93449329
})
93459330
.collect::<Vec<_>>();
93469331

93479332
self.router
9348-
.create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9333+
.create_blinded_paths(params, recipient, MessageContext::Offers(context), peers, secp_ctx)
93499334
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
93509335
}
93519336

lightning/src/onion_message/messenger.rs

+4-61
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<ForwardNode>, _secp_ctx: &Secp256k1<T>
179179
/// # ) -> Result<Vec<BlindedPath>, ()> {
180180
/// # unreachable!()
181181
/// # }
@@ -461,40 +461,8 @@ pub trait MessageRouter {
461461
fn create_blinded_paths<
462462
T: secp256k1::Signing + secp256k1::Verification
463463
>(
464-
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
464+
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
465465
) -> Result<Vec<BlindedPath>, ()>;
466-
467-
/// Creates compact [`BlindedPath`]s to the `recipient` node. The nodes in `peers` are assumed
468-
/// to be direct peers with the `recipient`.
469-
///
470-
/// Compact blinded paths use short channel ids instead of pubkeys for a smaller serialization,
471-
/// which is beneficial when a QR code is used to transport the data. The SCID is passed using a
472-
/// [`ForwardNode`] but may be `None` for graceful degradation.
473-
///
474-
/// Implementations using additional intermediate nodes are responsible for using a
475-
/// [`ForwardNode`] with `Some` short channel id, if possible. Similarly, implementations should
476-
/// call [`BlindedPath::use_compact_introduction_node`].
477-
///
478-
/// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`],
479-
/// ignoring the short channel ids.
480-
fn create_compact_blinded_paths<
481-
T: secp256k1::Signing + secp256k1::Verification
482-
>(
483-
&self, recipient: PublicKey, context: MessageContext,
484-
peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
485-
) -> Result<Vec<BlindedPath>, ()> {
486-
let peers = peers
487-
.into_iter()
488-
.map(|ForwardNode { node_id, short_channel_id: _ }| node_id)
489-
.collect();
490-
491-
// This parameter is a placeholder. This function is removed in the subsequent commits.
492-
let params = BlindedPathParams {
493-
paths: PATHS_PLACEHOLDER,
494-
is_compact: true,
495-
};
496-
self.create_blinded_paths(params, recipient, context, peers, secp_ctx)
497-
}
498466
}
499467

500468
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
@@ -628,24 +596,8 @@ where
628596
T: secp256k1::Signing + secp256k1::Verification
629597
>(
630598
params: BlindedPathParams, network_graph: &G, recipient: PublicKey, context: MessageContext,
631-
peers: Vec<PublicKey>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
632-
) -> Result<Vec<BlindedPath>, ()> {
633-
let peers = peers
634-
.into_iter()
635-
.map(|node_id| ForwardNode { node_id, short_channel_id: None });
636-
Self::create_blinded_paths_from_iter(params, network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx)
637-
}
638-
639-
pub(crate) fn create_compact_blinded_paths<
640-
T: secp256k1::Signing + secp256k1::Verification
641-
>(
642-
network_graph: &G, recipient: PublicKey, context: MessageContext,
643599
peers: Vec<ForwardNode>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
644600
) -> Result<Vec<BlindedPath>, ()> {
645-
let params = BlindedPathParams {
646-
paths: PATHS_PLACEHOLDER,
647-
is_compact: true,
648-
};
649601
Self::create_blinded_paths_from_iter(params, network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx)
650602
}
651603
}
@@ -664,19 +616,10 @@ where
664616
fn create_blinded_paths<
665617
T: secp256k1::Signing + secp256k1::Verification
666618
>(
667-
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
619+
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
668620
) -> Result<Vec<BlindedPath>, ()> {
669621
Self::create_blinded_paths(params, &self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
670622
}
671-
672-
fn create_compact_blinded_paths<
673-
T: secp256k1::Signing + secp256k1::Verification
674-
>(
675-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
676-
) -> Result<Vec<BlindedPath>, ()> {
677-
Self::create_compact_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
678-
}
679-
680623
}
681624

682625
/// A path for sending an [`OnionMessage`].
@@ -1251,7 +1194,7 @@ where
12511194
let peers = self.message_recipients.lock().unwrap()
12521195
.iter()
12531196
.filter(|(_, peer)| matches!(peer, OnionMessageRecipient::ConnectedPeer(_)))
1254-
.map(|(node_id, _ )| *node_id)
1197+
.map(|(node_id, _)| ForwardNode { node_id: *node_id, short_channel_id: None })
12551198
.collect::<Vec<_>>();
12561199

12571200
self.message_router

lightning/src/routing/router.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
1313

1414
use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode};
15-
use crate::blinded_path::message::{self, MessageContext};
15+
use crate::blinded_path::message::{ForwardNode, MessageContext};
1616
use crate::blinded_path::payment::{ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs, self};
1717
use crate::ln::{PaymentHash, PaymentPreimage};
1818
use crate::ln::channel_state::ChannelDetails;
@@ -195,18 +195,10 @@ impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Siz
195195
fn create_blinded_paths<
196196
T: secp256k1::Signing + secp256k1::Verification
197197
> (
198-
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
198+
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
199199
) -> Result<Vec<BlindedPath>, ()> {
200200
DefaultMessageRouter::create_blinded_paths(params, &self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
201201
}
202-
203-
fn create_compact_blinded_paths<
204-
T: secp256k1::Signing + secp256k1::Verification
205-
> (
206-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<message::ForwardNode>, secp_ctx: &Secp256k1<T>,
207-
) -> Result<Vec<BlindedPath>, ()> {
208-
DefaultMessageRouter::create_compact_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
209-
}
210202
}
211203

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

lightning/src/util/test_utils.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,9 @@ impl<'a> MessageRouter for TestRouter<'a> {
271271
T: secp256k1::Signing + secp256k1::Verification
272272
>(
273273
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext,
274-
peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
275-
) -> Result<Vec<BlindedPath>, ()> {
276-
self.router.create_blinded_paths(params, recipient, context, peers, secp_ctx)
277-
}
278-
279-
fn create_compact_blinded_paths<
280-
T: secp256k1::Signing + secp256k1::Verification
281-
>(
282-
&self, recipient: PublicKey, context: MessageContext,
283274
peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
284275
) -> Result<Vec<BlindedPath>, ()> {
285-
self.router.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
276+
self.router.create_blinded_paths(params, recipient, context, peers, secp_ctx)
286277
}
287278
}
288279

@@ -316,16 +307,9 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
316307

317308
fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
318309
&self, params: BlindedPathParams, recipient: PublicKey, context: MessageContext,
319-
peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
320-
) -> Result<Vec<BlindedPath>, ()> {
321-
self.inner.create_blinded_paths(params, recipient, context, peers, secp_ctx)
322-
}
323-
324-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
325-
&self, recipient: PublicKey, context: MessageContext,
326310
peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
327311
) -> Result<Vec<BlindedPath>, ()> {
328-
self.inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
312+
self.inner.create_blinded_paths(params, recipient, context, peers, secp_ctx)
329313
}
330314
}
331315

0 commit comments

Comments
 (0)