Skip to content

Commit

Permalink
Remove Redundant Variants of create_blinded_paths
Browse files Browse the repository at this point in the history
Following the updates in previous commits, the other
variants of `create_blinded_paths`—namely
`create_compact_blinded_paths` and
`create_blinded_paths_using_absolute_expiry`—are
now redundant. This commit removes these variants
as they are no longer necessary.
  • Loading branch information
shaavan committed Dec 13, 2024
1 parent 5af4cb3 commit cf3884f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 91 deletions.
46 changes: 2 additions & 44 deletions lightning/src/offers/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,7 @@ where
/// short-lived, while anything with a greater expiration is considered long-lived.
///
/// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow::create_refund_builder`],
/// will included a [`BlindedMessagePath`] created using:
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
/// will included a [`BlindedMessagePath`] created using: [`MessageRouter::create_blinded_paths`]
///
/// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
/// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
Expand Down Expand Up @@ -654,25 +652,7 @@ where
MR::Target: MessageRouter,
L::Target: Logger,
{
/// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
/// the path's intended lifetime.
///
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
pub fn create_blinded_paths_using_absolute_expiry(
&self, context: OffersContext, absolute_expiry: Option<Duration>,
) -> Result<Vec<BlindedMessagePath>, ()> {
let now = self.duration_since_epoch();
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);

if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
self.create_compact_blinded_paths(context)
} else {
self.create_blinded_paths(MessageContext::Offers(context))
}
}

#[cfg(test)]
pub(crate) fn duration_since_epoch(&self) -> Duration {
#[cfg(not(feature = "std"))]
let now = self.commons.get_highest_seen_timestamp();
Expand Down Expand Up @@ -703,28 +683,6 @@ where
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
}

/// Creates a collection of blinded paths by delegating to
/// [`MessageRouter::create_compact_blinded_paths`].
///
/// Errors if the `MessageRouter` errors.
fn create_compact_blinded_paths(
&self, context: OffersContext,
) -> Result<Vec<BlindedMessagePath>, ()> {
let recipient = self.get_our_node_id();
let secp_ctx = &self.secp_ctx;

let peers = self.commons.get_peer_for_blinded_path();

self.message_router
.create_compact_blinded_paths(
recipient,
MessageContext::Offers(context),
peers,
secp_ctx,
)
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
}

fn enqueue_invoice_request(
&self, invoice_request: InvoiceRequest, reply_paths: Vec<BlindedMessagePath>,
) -> Result<(), Bolt12SemanticError> {
Expand Down
40 changes: 0 additions & 40 deletions lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,28 +461,6 @@ pub trait MessageRouter {
>(
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()>;

/// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are
/// assumed to be direct peers with the `recipient`.
///
/// Compact blinded paths use short channel ids instead of pubkeys for a smaller serialization,
/// which is beneficial when a QR code is used to transport the data. The SCID is passed using
/// a [`MessageForwardNode`] but may be `None` for graceful degradation.
///
/// Implementations using additional intermediate nodes are responsible for using a
/// [`MessageForwardNode`] with `Some` short channel id, if possible. Similarly, implementations
/// should call [`BlindedMessagePath::use_compact_introduction_node`].
///
/// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`],
/// ignoring the short channel ids.
fn create_compact_blinded_paths<
T: secp256k1::Signing + secp256k1::Verification
>(
&self, recipient: PublicKey, context: MessageContext,
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()> {
self.create_blinded_paths(recipient, context, peers, secp_ctx)
}
}

/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
Expand Down Expand Up @@ -666,15 +644,6 @@ where
}
}
}

pub(crate) fn create_compact_blinded_paths<
T: secp256k1::Signing + secp256k1::Verification
>(
network_graph: &G, recipient: PublicKey, context: MessageContext,
peers: Vec<MessageForwardNode>, entropy_source: &ES, secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()> {
Self::create_blinded_paths_from_iter(network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx, true)
}
}

impl<G: Deref<Target=NetworkGraph<L>>, L: Deref, ES: Deref> MessageRouter for DefaultMessageRouter<G, L, ES>
Expand All @@ -695,15 +664,6 @@ where
) -> Result<Vec<BlindedMessagePath>, ()> {
self.create_blinded_paths_internal(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
}

fn create_compact_blinded_paths<
T: secp256k1::Signing + secp256k1::Verification
>(
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()> {
Self::create_compact_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
}

}

/// A generic implementation for [`MessageRouter`]
Expand Down
7 changes: 0 additions & 7 deletions lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,6 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
) -> Result<Vec<BlindedMessagePath>, ()> {
self.inner.create_blinded_paths(recipient, context, peers, secp_ctx)
}

fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
&self, recipient: PublicKey, context: MessageContext,
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
) -> Result<Vec<BlindedMessagePath>, ()> {
self.inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
}
}

pub struct OnlyReadsKeysInterface {}
Expand Down

0 comments on commit cf3884f

Please sign in to comment.