From: Valentine Wallace Date: Fri, 9 Aug 2024 19:55:33 +0000 (-0700) Subject: Move public_intro_node util into Blinded{Message,Payment}Path X-Git-Tag: v0.0.124-beta~10^2~7 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=10449b96de0c77886edb338d64a4573553d92764;p=rust-lightning Move public_intro_node util into Blinded{Message,Payment}Path Helps move towards making the BlindedPath struct private. --- diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index 08ef90a84..b2199d514 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -112,6 +112,14 @@ impl BlindedMessagePath { } } } + + /// Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e., + /// it is found in the network graph). + pub fn public_introduction_node_id<'a>( + &self, network_graph: &'a ReadOnlyNetworkGraph + ) -> Option<&'a NodeId> { + self.0.public_introduction_node_id(network_graph) + } } /// An intermediate node, and possibly a short channel id leading to the next node. diff --git a/lightning/src/blinded_path/mod.rs b/lightning/src/blinded_path/mod.rs index b2cb2c018..f2b1e805f 100644 --- a/lightning/src/blinded_path/mod.rs +++ b/lightning/src/blinded_path/mod.rs @@ -118,9 +118,7 @@ pub struct BlindedHop { } impl BlindedPath { - /// Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e., - /// it is found in the network graph). - pub fn public_introduction_node_id<'a>( + pub(super) fn public_introduction_node_id<'a>( &self, network_graph: &'a ReadOnlyNetworkGraph ) -> Option<&'a NodeId> { match &self.introduction_node { diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 27033c058..0d40ecf61 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -24,6 +24,7 @@ use crate::ln::onion_utils; use crate::offers::invoice::BlindedPayInfo; use crate::offers::invoice_request::InvoiceRequestFields; use crate::offers::offer::OfferId; +use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph}; use crate::sign::{EntropySource, NodeSigner, Recipient}; use crate::util::ser::{FixedLengthReader, LengthReadableArgs, HighZeroBytesDroppedBigSize, Readable, Writeable, Writer}; @@ -94,6 +95,14 @@ impl BlindedPaymentPath { ).map_err(|_| ())?, }))) } + + /// Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e., + /// it is found in the network graph). + pub fn public_introduction_node_id<'a>( + &self, network_graph: &'a ReadOnlyNetworkGraph + ) -> Option<&'a NodeId> { + self.0.public_introduction_node_id(network_graph) + } } /// An intermediate node, its outbound channel, and relay parameters. diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index b4134d493..221919d16 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -141,7 +141,7 @@ fn announce_node_address<'a, 'b, 'c>( } fn resolve_introduction_node<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &BlindedMessagePath) -> PublicKey { - path.0.public_introduction_node_id(&node.network_graph.read_only()) + path.public_introduction_node_id(&node.network_graph.read_only()) .and_then(|node_id| node_id.as_pubkey().ok()) .unwrap() } diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 2fde66b12..f64e2e739 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -699,7 +699,6 @@ impl Destination { if let Destination::BlindedPath(path) = self { if let IntroductionNode::DirectedShortChannelId(..) = path.0.introduction_node { if let Some(pubkey) = path - .0 .public_introduction_node_id(network_graph) .and_then(|node_id| node_id.as_pubkey().ok()) { diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 99a9e0086..2a603c75d 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1646,7 +1646,7 @@ where L::Target: Logger { node_counters.node_counter_from_id(&NodeId::from_pubkey(&pubkey)) }, IntroductionNode::DirectedShortChannelId(direction, scid) => { - path.0.public_introduction_node_id(network_graph) + path.public_introduction_node_id(network_graph) .map(|node_id_ref| *node_id_ref) .or_else(|| { first_hop_targets.iter().find(|(_, (channels, _))| @@ -5671,7 +5671,7 @@ mod tests { NodeId::from_pubkey(&path.hops.last().unwrap().pubkey), payment_params.payee.blinded_route_hints().iter() .find(|(p, _)| p.htlc_maximum_msat == path.final_value_msat()) - .and_then(|(_, p)| p.0.public_introduction_node_id(&network_graph)) + .and_then(|(_, p)| p.public_introduction_node_id(&network_graph)) .copied() .unwrap() ); @@ -7878,7 +7878,7 @@ mod tests { let final_hop = route.paths[0].hops.last().unwrap(); assert_eq!( NodeId::from_pubkey(&final_hop.pubkey), - *blinded_path.0.public_introduction_node_id(&network_graph).unwrap() + *blinded_path.public_introduction_node_id(&network_graph).unwrap() ); if tail.hops.len() > 1 { assert_eq!(final_hop.fee_msat,