Skip to content

Commit cf6f7e8

Browse files
committed
Cleanup: Remove redundant create_blinded_paths variants
With the recent updates to `create_blinded_paths` supporting flexible routing through `MessageRouter`, the specialized variants—`create_compact_blinded_paths` and `create_blinded_paths_using_absolute_expiry`—have become unnecessary. This commit removes those now-redundant functions to simplify the codebase and reduce maintenance overhead.
1 parent 4d1b8ff commit cf6f7e8

File tree

3 files changed

+11
-102
lines changed

3 files changed

+11
-102
lines changed

lightning/src/ln/channelmanager.rs

+11-38
Original file line numberDiff line numberDiff line change
@@ -2868,18 +2868,24 @@ const MAX_PEER_STORAGE_SIZE: usize = 1024;
28682868
/// many peers we reject new (inbound) connections.
28692869
const MAX_NO_CHANNEL_PEERS: usize = 250;
28702870

2871+
#[cfg(test)]
28712872
/// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
28722873
/// short-lived, while anything with a greater expiration is considered long-lived.
28732874
///
28742875
/// Using [`ChannelManager::create_offer_builder`] or [`ChannelManager::create_refund_builder`],
2875-
/// will included a [`BlindedMessagePath`] created using:
2876-
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2877-
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
2876+
/// will included a [`BlindedMessagePath`] created using [`MessageRouter::create_blinded_paths`].
2877+
///
2878+
/// To generate compact [`BlindedMessagePath`]s:
2879+
/// 1. Parameterize [`ChannelManager`] with a [`MessageRouter`] implementation that always creates
2880+
/// compact paths via [`MessageRouter::create_blinded_paths`].
2881+
/// 2. Use [`ChannelManager::create_offer_builder_using_router`] or
2882+
/// [`ChannelManager::create_refund_builder_using_router`] to provide a custom router that
2883+
/// generates compact paths.
28782884
///
28792885
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
28802886
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
28812887
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2882-
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2888+
pub(super) const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
28832889

28842890
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
28852891
/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
@@ -10970,25 +10976,7 @@ where
1097010976
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
1097110977
}
1097210978

10973-
/// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
10974-
/// the path's intended lifetime.
10975-
///
10976-
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
10977-
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
10978-
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
10979-
fn create_blinded_paths_using_absolute_expiry(
10980-
&self, context: OffersContext, absolute_expiry: Option<Duration>,
10981-
) -> Result<Vec<BlindedMessagePath>, ()> {
10982-
let now = self.duration_since_epoch();
10983-
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
10984-
10985-
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
10986-
self.create_compact_blinded_paths(context)
10987-
} else {
10988-
self.create_blinded_paths(MessageContext::Offers(context))
10989-
}
10990-
}
10991-
10979+
#[cfg(any(test, async_payments))]
1099210980
pub(super) fn duration_since_epoch(&self) -> Duration {
1099310981
#[cfg(not(feature = "std"))]
1099410982
let now = Duration::from_secs(
@@ -11034,21 +11022,6 @@ where
1103411022
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
1103511023
}
1103611024

11037-
/// Creates a collection of blinded paths by delegating to
11038-
/// [`MessageRouter::create_compact_blinded_paths`].
11039-
///
11040-
/// Errors if the `MessageRouter` errors.
11041-
fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
11042-
let recipient = self.get_our_node_id();
11043-
let secp_ctx = &self.secp_ctx;
11044-
11045-
let peers = self.get_peers_for_blinded_path();
11046-
11047-
self.message_router
11048-
.create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
11049-
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
11050-
}
11051-
1105211025
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
1105311026
/// [`Router::create_blinded_payment_paths`].
1105411027
fn create_blinded_payment_paths(

lightning/src/onion_message/messenger.rs

-57
Original file line numberDiff line numberDiff line change
@@ -496,26 +496,6 @@ pub trait MessageRouter {
496496
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
497497
secp_ctx: &Secp256k1<T>,
498498
) -> Result<Vec<BlindedMessagePath>, ()>;
499-
500-
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
501-
/// assumed to be direct peers with the `recipient`.
502-
///
503-
/// Compact blinded paths use short channel ids instead of pubkeys for a smaller serialization,
504-
/// which is beneficial when a QR code is used to transport the data. The SCID is passed using
505-
/// a [`MessageForwardNode`] but may be `None` for graceful degradation.
506-
///
507-
/// Implementations using additional intermediate nodes are responsible for using a
508-
/// [`MessageForwardNode`] with `Some` short channel id, if possible. Similarly, implementations
509-
/// should call [`BlindedMessagePath::use_compact_introduction_node`].
510-
///
511-
/// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`],
512-
/// ignoring the short channel ids.
513-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
514-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
515-
secp_ctx: &Secp256k1<T>,
516-
) -> Result<Vec<BlindedMessagePath>, ()> {
517-
self.create_blinded_paths(recipient, context, peers, secp_ctx)
518-
}
519499
}
520500

521501
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
@@ -687,21 +667,6 @@ where
687667
false,
688668
)
689669
}
690-
691-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
692-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
693-
secp_ctx: &Secp256k1<T>,
694-
) -> Result<Vec<BlindedMessagePath>, ()> {
695-
Self::create_blinded_paths_from_iter(
696-
&self.network_graph,
697-
recipient,
698-
context,
699-
peers.into_iter(),
700-
&self.entropy_source,
701-
secp_ctx,
702-
true,
703-
)
704-
}
705670
}
706671

707672
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`],
@@ -759,21 +724,6 @@ where
759724
true,
760725
)
761726
}
762-
763-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
764-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
765-
secp_ctx: &Secp256k1<T>,
766-
) -> Result<Vec<BlindedMessagePath>, ()> {
767-
DefaultMessageRouter::create_blinded_paths_from_iter(
768-
&self.network_graph,
769-
recipient,
770-
context,
771-
peers.into_iter(),
772-
&self.entropy_source,
773-
secp_ctx,
774-
true,
775-
)
776-
}
777727
}
778728

779729
/// A special [`MessageRouter`] that can doesn't route.
@@ -792,13 +742,6 @@ impl MessageRouter for NullMessageRouter {
792742
) -> Result<Vec<BlindedMessagePath>, ()> {
793743
Ok(vec![])
794744
}
795-
796-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
797-
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>,
798-
_secp_ctx: &Secp256k1<T>,
799-
) -> Result<Vec<BlindedMessagePath>, ()> {
800-
Ok(vec![])
801-
}
802745
}
803746

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

lightning/src/util/test_utils.rs

-7
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,6 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
340340
) -> Result<Vec<BlindedMessagePath>, ()> {
341341
self.inner.create_blinded_paths(recipient, context, peers, secp_ctx)
342342
}
343-
344-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
345-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
346-
secp_ctx: &Secp256k1<T>,
347-
) -> Result<Vec<BlindedMessagePath>, ()> {
348-
self.inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
349-
}
350343
}
351344

352345
pub struct OnlyReadsKeysInterface {}

0 commit comments

Comments
 (0)