Skip to content

Commit 80e7385

Browse files
committed
Cleanup: Remove redundant create_blinded_paths variants
This commit completes the series implementing the principle: **“One `MessageRouter`, one `BlindedPath` type.”** As the final step, it removes now-redundant variations of the blinded path creation functions, streamlining the API and simplifying the blinded path creation process.
1 parent 512e825 commit 80e7385

File tree

4 files changed

+3
-138
lines changed

4 files changed

+3
-138
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,9 +2969,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
29692969
/// short-lived, while anything with a greater expiration is considered long-lived.
29702970
///
29712971
/// Using [`ChannelManager::create_offer_builder`] or [`ChannelManager::create_refund_builder`],
2972-
/// will included a [`BlindedMessagePath`] created using:
2973-
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2974-
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
2972+
/// will include a [`BlindedMessagePath`] created using [`MessageRouter::create_blinded_paths`].
29752973
///
29762974
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
29772975
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to

lightning/src/offers/flow.rs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::prelude::*;
3232

3333
use crate::chain::BestBlock;
3434
use crate::ln::channel_state::ChannelDetails;
35-
use crate::ln::channelmanager::{PaymentId, CLTV_FAR_FAR_AWAY, MAX_SHORT_LIVED_RELATIVE_EXPIRY};
35+
use crate::ln::channelmanager::{PaymentId, CLTV_FAR_FAR_AWAY};
3636
use crate::ln::inbound_payment;
3737
use crate::offers::async_receive_offer_cache::AsyncReceiveOfferCache;
3838
use crate::offers::invoice::{
@@ -193,6 +193,7 @@ where
193193
self.receive_auth_key
194194
}
195195

196+
#[cfg(async_payments)]
196197
fn duration_since_epoch(&self) -> Duration {
197198
#[cfg(not(feature = "std"))]
198199
let now = Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64);
@@ -303,26 +304,6 @@ where
303304
self.create_blinded_paths(peers, context)
304305
}
305306

306-
/// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
307-
/// the path's intended lifetime.
308-
///
309-
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
310-
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
311-
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
312-
fn create_blinded_paths_using_absolute_expiry(
313-
&self, context: OffersContext, absolute_expiry: Option<Duration>,
314-
peers: Vec<MessageForwardNode>,
315-
) -> Result<Vec<BlindedMessagePath>, ()> {
316-
let now = self.duration_since_epoch();
317-
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
318-
319-
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
320-
self.create_compact_blinded_paths(peers, context)
321-
} else {
322-
self.create_blinded_paths(peers, MessageContext::Offers(context))
323-
}
324-
}
325-
326307
/// Creates a collection of blinded paths by delegating to
327308
/// [`MessageRouter::create_blinded_paths`].
328309
///
@@ -339,28 +320,6 @@ where
339320
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
340321
}
341322

342-
/// Creates a collection of blinded paths by delegating to
343-
/// [`MessageRouter::create_compact_blinded_paths`].
344-
///
345-
/// Errors if the `MessageRouter` errors.
346-
fn create_compact_blinded_paths(
347-
&self, peers: Vec<MessageForwardNode>, context: OffersContext,
348-
) -> Result<Vec<BlindedMessagePath>, ()> {
349-
let recipient = self.get_our_node_id();
350-
let receive_key = self.get_receive_auth_key();
351-
let secp_ctx = &self.secp_ctx;
352-
353-
self.message_router
354-
.create_compact_blinded_paths(
355-
recipient,
356-
receive_key,
357-
MessageContext::Offers(context),
358-
peers,
359-
secp_ctx,
360-
)
361-
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
362-
}
363-
364323
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
365324
/// [`Router::create_blinded_payment_paths`].
366325
fn create_blinded_payment_paths<ES: Deref, R: Deref>(

lightning/src/onion_message/messenger.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -510,26 +510,6 @@ pub trait MessageRouter {
510510
&self, recipient: PublicKey, local_node_receive_key: ReceiveAuthKey,
511511
context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
512512
) -> Result<Vec<BlindedMessagePath>, ()>;
513-
514-
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
515-
/// assumed to be direct peers with the `recipient`.
516-
///
517-
/// Compact blinded paths use short channel ids instead of pubkeys for a smaller serialization,
518-
/// which is beneficial when a QR code is used to transport the data. The SCID is passed using
519-
/// a [`MessageForwardNode`] but may be `None` for graceful degradation.
520-
///
521-
/// Implementations using additional intermediate nodes are responsible for using a
522-
/// [`MessageForwardNode`] with `Some` short channel id, if possible. Similarly, implementations
523-
/// should call [`BlindedMessagePath::use_compact_introduction_node`].
524-
///
525-
/// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`],
526-
/// ignoring the short channel ids.
527-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
528-
&self, recipient: PublicKey, local_node_receive_key: ReceiveAuthKey,
529-
context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
530-
) -> Result<Vec<BlindedMessagePath>, ()> {
531-
self.create_blinded_paths(recipient, local_node_receive_key, context, peers, secp_ctx)
532-
}
533513
}
534514

535515
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
@@ -733,22 +713,6 @@ where
733713
true,
734714
)
735715
}
736-
737-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
738-
&self, recipient: PublicKey, local_node_receive_key: ReceiveAuthKey,
739-
context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
740-
) -> Result<Vec<BlindedMessagePath>, ()> {
741-
Self::create_blinded_paths_from_iter(
742-
&self.network_graph,
743-
recipient,
744-
local_node_receive_key,
745-
context,
746-
peers.into_iter(),
747-
&self.entropy_source,
748-
secp_ctx,
749-
true,
750-
)
751-
}
752716
}
753717

754718
/// This message router is similar to [`DefaultMessageRouter`], but it always creates
@@ -809,22 +773,6 @@ where
809773
false,
810774
)
811775
}
812-
813-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
814-
&self, recipient: PublicKey, local_node_receive_key: ReceiveAuthKey,
815-
context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
816-
) -> Result<Vec<BlindedMessagePath>, ()> {
817-
DefaultMessageRouter::create_blinded_paths_from_iter(
818-
&self.network_graph,
819-
recipient,
820-
local_node_receive_key,
821-
context,
822-
peers.into_iter(),
823-
&self.entropy_source,
824-
secp_ctx,
825-
false,
826-
)
827-
}
828776
}
829777

830778
/// A special [`MessageRouter`] that performs no routing and does not create blinded paths.
@@ -858,13 +806,6 @@ impl MessageRouter for NullMessageRouter {
858806
) -> Result<Vec<BlindedMessagePath>, ()> {
859807
Ok(vec![])
860808
}
861-
862-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
863-
&self, _recipient: PublicKey, _local_node_receive_key: ReceiveAuthKey,
864-
_context: MessageContext, _peers: Vec<MessageForwardNode>, _secp_ctx: &Secp256k1<T>,
865-
) -> Result<Vec<BlindedMessagePath>, ()> {
866-
Ok(vec![])
867-
}
868809
}
869810

870811
/// A path for sending an [`OnionMessage`].

lightning/src/util/test_utils.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -410,39 +410,6 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
410410
),
411411
}
412412
}
413-
414-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
415-
&self, recipient: PublicKey, local_node_receive_key: ReceiveAuthKey,
416-
context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
417-
) -> Result<Vec<BlindedMessagePath>, ()> {
418-
let mut peers = peers;
419-
{
420-
let peers_override = self.peers_override.lock().unwrap();
421-
if !peers_override.is_empty() {
422-
peers = peers_override
423-
.clone()
424-
.iter()
425-
.map(|pk| MessageForwardNode { node_id: *pk, short_channel_id: None })
426-
.collect();
427-
}
428-
}
429-
match &self.inner {
430-
TestMessageRouterInternal::Default(inner) => inner.create_compact_blinded_paths(
431-
recipient,
432-
local_node_receive_key,
433-
context,
434-
peers,
435-
secp_ctx,
436-
),
437-
TestMessageRouterInternal::NodeId(inner) => inner.create_compact_blinded_paths(
438-
recipient,
439-
local_node_receive_key,
440-
context,
441-
peers,
442-
secp_ctx,
443-
),
444-
}
445-
}
446413
}
447414

448415
pub struct OnlyReadsKeysInterface {}

0 commit comments

Comments
 (0)