From aa9b03a22975b79bdb5cb3993c886dcf3684f574 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 13 Aug 2024 14:36:07 -0400 Subject: [PATCH] Make BlindedPath type private. Users should use the Blinded{Message,Payment}Path types instead. --- lightning/src/blinded_path/message.rs | 2 +- lightning/src/blinded_path/mod.rs | 12 +++--- lightning/src/blinded_path/payment.rs | 2 +- lightning/src/routing/router.rs | 56 +++++++++------------------ lightning/src/routing/scoring.rs | 13 ++----- 5 files changed, 29 insertions(+), 56 deletions(-) diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index 27332f692..c48e5d3cc 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -34,7 +34,7 @@ use crate::util::ser::{FixedLengthReader, LengthReadableArgs, Readable, Writeabl use core::mem; use core::ops::Deref; -/// A [`BlindedPath`] to be used for sending or receiving a message, hiding the identity of the +/// A blinded path to be used for sending or receiving a message, hiding the identity of the /// recipient. #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BlindedMessagePath(pub(super) BlindedPath); diff --git a/lightning/src/blinded_path/mod.rs b/lightning/src/blinded_path/mod.rs index f2b1e805f..08a30f589 100644 --- a/lightning/src/blinded_path/mod.rs +++ b/lightning/src/blinded_path/mod.rs @@ -37,7 +37,7 @@ pub enum NextMessageHop { /// Onion messages and payments can be sent and received to blinded paths, which serve to hide the /// identity of the recipient. #[derive(Clone, Debug, Hash, PartialEq, Eq)] -pub struct BlindedPath { +struct BlindedPath { /// To send to a blinded path, the sender first finds a route to the unblinded /// `introduction_node`, which can unblind its [`encrypted_payload`] to find out the onion /// message or payment's next hop and forward it along. @@ -53,7 +53,7 @@ pub struct BlindedPath { pub blinded_hops: Vec, } -/// The unblinded node in a [`BlindedPath`]. +/// The unblinded node in a blinded path. #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub enum IntroductionNode { /// The node id of the introduction node. @@ -63,8 +63,8 @@ pub enum IntroductionNode { DirectedShortChannelId(Direction, u64), } -/// The side of a channel that is the [`IntroductionNode`] in a [`BlindedPath`]. [BOLT 7] defines -/// which nodes is which in the [`ChannelAnnouncement`] message. +/// The side of a channel that is the [`IntroductionNode`] in a blinded path. [BOLT 7] defines which +/// nodes is which in the [`ChannelAnnouncement`] message. /// /// [BOLT 7]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_announcement-message /// [`ChannelAnnouncement`]: crate::ln::msgs::ChannelAnnouncement @@ -109,9 +109,9 @@ impl Deref for EmptyNodeIdLookUp { /// and thus can be used to hide the identity of the recipient. #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BlindedHop { - /// The blinded node id of this hop in a [`BlindedPath`]. + /// The blinded node id of this hop in a blinded path. pub blinded_node_id: PublicKey, - /// The encrypted payload intended for this hop in a [`BlindedPath`]. + /// The encrypted payload intended for this hop in a blinded path. // The node sending to this blinded path will later encode this payload into the onion packet for // this hop. pub encrypted_payload: Vec, diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 82d3fd3e5..f9615e715 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -34,7 +34,7 @@ use core::ops::Deref; #[allow(unused_imports)] use crate::prelude::*; -/// A [`BlindedPath`] to be used for sending or receiving a payment, hiding the identity of the +/// A blinded path to be used for sending or receiving a payment, hiding the identity of the /// recipient. #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct BlindedPaymentPath(pub(super) BlindedPath); diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index ffc27cb0e..2d7450b91 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -3541,7 +3541,7 @@ fn build_route_from_hops_internal( #[cfg(test)] mod tests { - use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode}; + use crate::blinded_path::BlindedHop; use crate::blinded_path::payment::BlindedPaymentPath; use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, EffectiveCapacity}; use crate::routing::utxo::UtxoResult; @@ -7682,22 +7682,6 @@ mod tests { #[test] fn blinded_route_ser() { - let blinded_path_1 = BlindedPath { - introduction_node: IntroductionNode::NodeId(ln_test_utils::pubkey(42)), - blinding_point: ln_test_utils::pubkey(43), - blinded_hops: vec![ - BlindedHop { blinded_node_id: ln_test_utils::pubkey(44), encrypted_payload: Vec::new() }, - BlindedHop { blinded_node_id: ln_test_utils::pubkey(45), encrypted_payload: Vec::new() } - ], - }; - let blinded_path_2 = BlindedPath { - introduction_node: IntroductionNode::NodeId(ln_test_utils::pubkey(46)), - blinding_point: ln_test_utils::pubkey(47), - blinded_hops: vec![ - BlindedHop { blinded_node_id: ln_test_utils::pubkey(48), encrypted_payload: Vec::new() }, - BlindedHop { blinded_node_id: ln_test_utils::pubkey(49), encrypted_payload: Vec::new() } - ], - }; // (De)serialize a Route with 1 blinded path out of two total paths. let mut route = Route { paths: vec![Path { hops: vec![RouteHop { @@ -7710,8 +7694,11 @@ mod tests { maybe_announced_channel: true, }], blinded_tail: Some(BlindedTail { - hops: blinded_path_1.blinded_hops, - blinding_point: blinded_path_1.blinding_point, + hops: vec![ + BlindedHop { blinded_node_id: ln_test_utils::pubkey(44), encrypted_payload: Vec::new() }, + BlindedHop { blinded_node_id: ln_test_utils::pubkey(45), encrypted_payload: Vec::new() } + ], + blinding_point: ln_test_utils::pubkey(43), excess_final_cltv_expiry_delta: 40, final_value_msat: 100, })}, Path { @@ -7733,8 +7720,11 @@ mod tests { // (De)serialize a Route with two paths, each containing a blinded tail. route.paths[1].blinded_tail = Some(BlindedTail { - hops: blinded_path_2.blinded_hops, - blinding_point: blinded_path_2.blinding_point, + hops: vec![ + BlindedHop { blinded_node_id: ln_test_utils::pubkey(48), encrypted_payload: Vec::new() }, + BlindedHop { blinded_node_id: ln_test_utils::pubkey(49), encrypted_payload: Vec::new() } + ], + blinding_point: ln_test_utils::pubkey(47), excess_final_cltv_expiry_delta: 41, final_value_msat: 101, }); @@ -7749,11 +7739,6 @@ mod tests { // Ensure we'll score the channel that's inbound to a blinded path's introduction node, and // account for the blinded tail's final amount_msat. let mut inflight_htlcs = InFlightHtlcs::new(); - let blinded_path = BlindedPath { - introduction_node: IntroductionNode::NodeId(ln_test_utils::pubkey(43)), - blinding_point: ln_test_utils::pubkey(48), - blinded_hops: vec![BlindedHop { blinded_node_id: ln_test_utils::pubkey(49), encrypted_payload: Vec::new() }], - }; let path = Path { hops: vec![RouteHop { pubkey: ln_test_utils::pubkey(42), @@ -7774,8 +7759,8 @@ mod tests { maybe_announced_channel: false, }], blinded_tail: Some(BlindedTail { - hops: blinded_path.blinded_hops, - blinding_point: blinded_path.blinding_point, + hops: vec![BlindedHop { blinded_node_id: ln_test_utils::pubkey(49), encrypted_payload: Vec::new() }], + blinding_point: ln_test_utils::pubkey(48), excess_final_cltv_expiry_delta: 0, final_value_msat: 200, }), @@ -7788,14 +7773,6 @@ mod tests { #[test] fn blinded_path_cltv_shadow_offset() { // Make sure we add a shadow offset when sending to blinded paths. - let blinded_path = BlindedPath { - introduction_node: IntroductionNode::NodeId(ln_test_utils::pubkey(43)), - blinding_point: ln_test_utils::pubkey(44), - blinded_hops: vec![ - BlindedHop { blinded_node_id: ln_test_utils::pubkey(45), encrypted_payload: Vec::new() }, - BlindedHop { blinded_node_id: ln_test_utils::pubkey(46), encrypted_payload: Vec::new() } - ], - }; let mut route = Route { paths: vec![Path { hops: vec![RouteHop { pubkey: ln_test_utils::pubkey(42), @@ -7817,8 +7794,11 @@ mod tests { } ], blinded_tail: Some(BlindedTail { - hops: blinded_path.blinded_hops, - blinding_point: blinded_path.blinding_point, + hops: vec![ + BlindedHop { blinded_node_id: ln_test_utils::pubkey(45), encrypted_payload: Vec::new() }, + BlindedHop { blinded_node_id: ln_test_utils::pubkey(46), encrypted_payload: Vec::new() } + ], + blinding_point: ln_test_utils::pubkey(44), excess_final_cltv_expiry_delta: 0, final_value_msat: 200, }), diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index a04a18504..7945a5b80 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -2152,7 +2152,7 @@ impl Readable for ChannelLiquidity { #[cfg(test)] mod tests { use super::{ChannelLiquidity, HistoricalBucketRangeTracker, ProbabilisticScoringFeeParameters, ProbabilisticScoringDecayParameters, ProbabilisticScorer}; - use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode}; + use crate::blinded_path::BlindedHop; use crate::util::config::UserConfig; use crate::ln::channelmanager; @@ -3567,16 +3567,9 @@ mod tests { let mut path = payment_path_for_amount(768); let recipient_hop = path.hops.pop().unwrap(); - let blinded_path = BlindedPath { - introduction_node: IntroductionNode::NodeId(path.hops.last().as_ref().unwrap().pubkey), - blinding_point: test_utils::pubkey(42), - blinded_hops: vec![ - BlindedHop { blinded_node_id: test_utils::pubkey(44), encrypted_payload: Vec::new() } - ], - }; path.blinded_tail = Some(BlindedTail { - hops: blinded_path.blinded_hops, - blinding_point: blinded_path.blinding_point, + hops: vec![BlindedHop { blinded_node_id: test_utils::pubkey(44), encrypted_payload: Vec::new() }], + blinding_point: test_utils::pubkey(42), excess_final_cltv_expiry_delta: recipient_hop.cltv_expiry_delta, final_value_msat: recipient_hop.fee_msat, }); -- 2.39.5