Skip to content

Commit 9cd350a

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 4a188c0 commit 9cd350a

File tree

4 files changed

+3
-115
lines changed

4 files changed

+3
-115
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,9 +3021,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
30213021
/// short-lived, while anything with a greater expiration is considered long-lived.
30223022
///
30233023
/// Using [`ChannelManager::create_offer_builder`] or [`ChannelManager::create_refund_builder`],
3024-
/// will included a [`BlindedMessagePath`] created using:
3025-
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
3026-
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
3024+
/// will included a [`BlindedMessagePath`] created using [`MessageRouter::create_blinded_paths`]
30273025
///
30283026
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
30293027
/// 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 & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::prelude::*;
3333
use crate::chain::BestBlock;
3434
use crate::ln::channel_state::ChannelDetails;
3535
use crate::ln::channelmanager::{
36-
Verification, {PaymentId, CLTV_FAR_FAR_AWAY, MAX_SHORT_LIVED_RELATIVE_EXPIRY},
36+
Verification, {PaymentId, CLTV_FAR_FAR_AWAY},
3737
};
3838
use crate::ln::inbound_payment;
3939
use crate::offers::invoice::{
@@ -141,6 +141,7 @@ where
141141
self.our_network_pubkey
142142
}
143143

144+
#[cfg(async_payments)]
144145
fn duration_since_epoch(&self) -> Duration {
145146
#[cfg(not(feature = "std"))]
146147
let now = Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64);
@@ -199,26 +200,6 @@ impl<MR: Deref> OffersMessageFlow<MR>
199200
where
200201
MR::Target: MessageRouter,
201202
{
202-
/// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
203-
/// the path's intended lifetime.
204-
///
205-
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
206-
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
207-
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
208-
fn create_blinded_paths_using_absolute_expiry(
209-
&self, context: OffersContext, absolute_expiry: Option<Duration>,
210-
peers: Vec<MessageForwardNode>,
211-
) -> Result<Vec<BlindedMessagePath>, ()> {
212-
let now = self.duration_since_epoch();
213-
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
214-
215-
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
216-
self.create_compact_blinded_paths(peers, context)
217-
} else {
218-
self.create_blinded_paths(peers, MessageContext::Offers(context))
219-
}
220-
}
221-
222203
/// Creates a collection of blinded paths by delegating to
223204
/// [`MessageRouter::create_blinded_paths`].
224205
///
@@ -234,26 +215,6 @@ where
234215
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
235216
}
236217

237-
/// Creates a collection of blinded paths by delegating to
238-
/// [`MessageRouter::create_compact_blinded_paths`].
239-
///
240-
/// Errors if the `MessageRouter` errors.
241-
fn create_compact_blinded_paths(
242-
&self, peers: Vec<MessageForwardNode>, context: OffersContext,
243-
) -> Result<Vec<BlindedMessagePath>, ()> {
244-
let recipient = self.get_our_node_id();
245-
let secp_ctx = &self.secp_ctx;
246-
247-
self.message_router
248-
.create_compact_blinded_paths(
249-
recipient,
250-
MessageContext::Offers(context),
251-
peers,
252-
secp_ctx,
253-
)
254-
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
255-
}
256-
257218
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
258219
/// [`Router::create_blinded_payment_paths`].
259220
fn create_blinded_payment_paths<ES: Deref, R: Deref>(

lightning/src/onion_message/messenger.rs

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

523503
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
@@ -689,21 +669,6 @@ where
689669
true,
690670
)
691671
}
692-
693-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
694-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
695-
secp_ctx: &Secp256k1<T>,
696-
) -> Result<Vec<BlindedMessagePath>, ()> {
697-
Self::create_blinded_paths_from_iter(
698-
&self.network_graph,
699-
recipient,
700-
context,
701-
peers.into_iter(),
702-
&self.entropy_source,
703-
secp_ctx,
704-
true,
705-
)
706-
}
707672
}
708673

709674
/// This message router is similar to [`DefaultMessageRouter`], but it always creates
@@ -763,21 +728,6 @@ where
763728
false,
764729
)
765730
}
766-
767-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
768-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
769-
secp_ctx: &Secp256k1<T>,
770-
) -> Result<Vec<BlindedMessagePath>, ()> {
771-
DefaultMessageRouter::create_blinded_paths_from_iter(
772-
&self.network_graph,
773-
recipient,
774-
context,
775-
peers.into_iter(),
776-
&self.entropy_source,
777-
secp_ctx,
778-
false,
779-
)
780-
}
781731
}
782732

783733
/// A special [`MessageRouter`] implementation that performs no routing.
@@ -805,13 +755,6 @@ impl MessageRouter for NullMessageRouter {
805755
) -> Result<Vec<BlindedMessagePath>, ()> {
806756
Ok(vec![])
807757
}
808-
809-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
810-
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>,
811-
_secp_ctx: &Secp256k1<T>,
812-
) -> Result<Vec<BlindedMessagePath>, ()> {
813-
Ok(vec![])
814-
}
815758
}
816759

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

lightning/src/util/test_utils.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,20 +366,6 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
366366
},
367367
}
368368
}
369-
370-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
371-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
372-
secp_ctx: &Secp256k1<T>,
373-
) -> Result<Vec<BlindedMessagePath>, ()> {
374-
match self {
375-
Self::Default { inner } => {
376-
inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
377-
},
378-
Self::NodeId { inner } => {
379-
inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
380-
},
381-
}
382-
}
383369
}
384370

385371
pub struct OnlyReadsKeysInterface {}

0 commit comments

Comments
 (0)