Skip to content

Commit b3745c2

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 bc95f12 commit b3745c2

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
@@ -3023,9 +3023,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
30233023
/// short-lived, while anything with a greater expiration is considered long-lived.
30243024
///
30253025
/// Using [`ChannelManager::create_offer_builder`] or [`ChannelManager::create_refund_builder`],
3026-
/// will included a [`BlindedMessagePath`] created using:
3027-
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
3028-
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
3026+
/// will include a [`BlindedMessagePath`] created using [`MessageRouter::create_blinded_paths`]
30293027
///
30303028
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
30313029
/// 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::async_receive_offer_cache::AsyncReceiveOfferCache;
@@ -187,6 +187,7 @@ where
187187
self.our_network_pubkey
188188
}
189189

190+
#[cfg(async_payments)]
190191
fn duration_since_epoch(&self) -> Duration {
191192
#[cfg(not(feature = "std"))]
192193
let now = Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64);
@@ -250,26 +251,6 @@ impl<MR: Deref> OffersMessageFlow<MR>
250251
where
251252
MR::Target: MessageRouter,
252253
{
253-
/// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
254-
/// the path's intended lifetime.
255-
///
256-
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
257-
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
258-
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
259-
fn create_blinded_paths_using_absolute_expiry(
260-
&self, context: OffersContext, absolute_expiry: Option<Duration>,
261-
peers: Vec<MessageForwardNode>,
262-
) -> Result<Vec<BlindedMessagePath>, ()> {
263-
let now = self.duration_since_epoch();
264-
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
265-
266-
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
267-
self.create_compact_blinded_paths(peers, context)
268-
} else {
269-
self.create_blinded_paths(peers, MessageContext::Offers(context))
270-
}
271-
}
272-
273254
/// Creates a collection of blinded paths by delegating to
274255
/// [`MessageRouter::create_blinded_paths`].
275256
///
@@ -285,26 +266,6 @@ where
285266
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
286267
}
287268

288-
/// Creates a collection of blinded paths by delegating to
289-
/// [`MessageRouter::create_compact_blinded_paths`].
290-
///
291-
/// Errors if the `MessageRouter` errors.
292-
fn create_compact_blinded_paths(
293-
&self, peers: Vec<MessageForwardNode>, context: OffersContext,
294-
) -> Result<Vec<BlindedMessagePath>, ()> {
295-
let recipient = self.get_our_node_id();
296-
let secp_ctx = &self.secp_ctx;
297-
298-
self.message_router
299-
.create_compact_blinded_paths(
300-
recipient,
301-
MessageContext::Offers(context),
302-
peers,
303-
secp_ctx,
304-
)
305-
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
306-
}
307-
308269
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
309270
/// [`Router::create_blinded_payment_paths`].
310271
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
@@ -504,26 +504,6 @@ pub trait MessageRouter {
504504
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
505505
secp_ctx: &Secp256k1<T>,
506506
) -> Result<Vec<BlindedMessagePath>, ()>;
507-
508-
/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
509-
/// assumed to be direct peers with the `recipient`.
510-
///
511-
/// Compact blinded paths use short channel ids instead of pubkeys for a smaller serialization,
512-
/// which is beneficial when a QR code is used to transport the data. The SCID is passed using
513-
/// a [`MessageForwardNode`] but may be `None` for graceful degradation.
514-
///
515-
/// Implementations using additional intermediate nodes are responsible for using a
516-
/// [`MessageForwardNode`] with `Some` short channel id, if possible. Similarly, implementations
517-
/// should call [`BlindedMessagePath::use_compact_introduction_node`].
518-
///
519-
/// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`],
520-
/// ignoring the short channel ids.
521-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
522-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
523-
secp_ctx: &Secp256k1<T>,
524-
) -> Result<Vec<BlindedMessagePath>, ()> {
525-
self.create_blinded_paths(recipient, context, peers, secp_ctx)
526-
}
527507
}
528508

529509
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
@@ -706,21 +686,6 @@ where
706686
true,
707687
)
708688
}
709-
710-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
711-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
712-
secp_ctx: &Secp256k1<T>,
713-
) -> Result<Vec<BlindedMessagePath>, ()> {
714-
Self::create_blinded_paths_from_iter(
715-
&self.network_graph,
716-
recipient,
717-
context,
718-
peers.into_iter(),
719-
&self.entropy_source,
720-
secp_ctx,
721-
true,
722-
)
723-
}
724689
}
725690

726691
/// This message router is similar to [`DefaultMessageRouter`], but it always creates
@@ -780,21 +745,6 @@ where
780745
false,
781746
)
782747
}
783-
784-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
785-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
786-
secp_ctx: &Secp256k1<T>,
787-
) -> Result<Vec<BlindedMessagePath>, ()> {
788-
DefaultMessageRouter::create_blinded_paths_from_iter(
789-
&self.network_graph,
790-
recipient,
791-
context,
792-
peers.into_iter(),
793-
&self.entropy_source,
794-
secp_ctx,
795-
false,
796-
)
797-
}
798748
}
799749

800750
/// A special [`MessageRouter`] that performs no routing and does not create blinded paths.
@@ -828,13 +778,6 @@ impl MessageRouter for NullMessageRouter {
828778
) -> Result<Vec<BlindedMessagePath>, ()> {
829779
Ok(vec![])
830780
}
831-
832-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
833-
&self, _recipient: PublicKey, _context: MessageContext, _peers: Vec<MessageForwardNode>,
834-
_secp_ctx: &Secp256k1<T>,
835-
) -> Result<Vec<BlindedMessagePath>, ()> {
836-
Ok(vec![])
837-
}
838781
}
839782

840783
/// 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
@@ -361,20 +361,6 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
361361
Self::NodeId(inner) => inner.create_blinded_paths(recipient, context, peers, secp_ctx),
362362
}
363363
}
364-
365-
fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
366-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>,
367-
secp_ctx: &Secp256k1<T>,
368-
) -> Result<Vec<BlindedMessagePath>, ()> {
369-
match self {
370-
Self::Default(inner) => {
371-
inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
372-
},
373-
Self::NodeId(inner) => {
374-
inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
375-
},
376-
}
377-
}
378364
}
379365

380366
pub struct OnlyReadsKeysInterface {}

0 commit comments

Comments
 (0)