]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move compact blinded path util to message paths only.
authorValentine Wallace <vwallace@protonmail.com>
Fri, 9 Aug 2024 19:50:19 +0000 (12:50 -0700)
committerValentine Wallace <vwallace@protonmail.com>
Thu, 15 Aug 2024 17:04:04 +0000 (13:04 -0400)
It's only used for message paths, so let's move it there to help make the
BlindedPath struct private.

lightning/src/blinded_path/message.rs
lightning/src/blinded_path/mod.rs
lightning/src/onion_message/messenger.rs

index 0b575e842891f3c25988b113ef8f1f506811e3c3..08ef90a84f561698d16f8a8bce8c419e1fc52f71 100644 (file)
@@ -16,7 +16,7 @@ use crate::prelude::*;
 
 use bitcoin::hashes::hmac::Hmac;
 use bitcoin::hashes::sha256::Hash as Sha256;
-use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NextMessageHop, NodeIdLookUp};
+use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode, NextMessageHop, NodeIdLookUp};
 use crate::blinded_path::utils;
 use crate::io;
 use crate::io::Cursor;
@@ -25,8 +25,10 @@ use crate::ln::msgs::DecodeError;
 use crate::ln::{PaymentHash, onion_utils};
 use crate::offers::nonce::Nonce;
 use crate::onion_message::packet::ControlTlvs;
+use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph};
 use crate::sign::{EntropySource, NodeSigner, Recipient};
 use crate::crypto::streams::ChaChaPolyReadAdapter;
+use crate::util::scid_utils;
 use crate::util::ser::{FixedLengthReader, LengthReadableArgs, Readable, Writeable, Writer};
 
 use core::mem;
@@ -81,6 +83,35 @@ impl BlindedMessagePath {
                        ).map_err(|_| ())?,
                }))
        }
+
+       /// Attempts to a use a compact representation for the [`IntroductionNode`] by using a directed
+       /// short channel id from a channel in `network_graph` leading to the introduction node.
+       ///
+       /// While this may result in a smaller encoding, there is a trade off in that the path may
+       /// become invalid if the channel is closed or hasn't been propagated via gossip. Therefore,
+       /// calling this may not be suitable for long-lived blinded paths.
+       pub fn use_compact_introduction_node(&mut self, network_graph: &ReadOnlyNetworkGraph) {
+               if let IntroductionNode::NodeId(pubkey) = &self.0.introduction_node {
+                       let node_id = NodeId::from_pubkey(pubkey);
+                       if let Some(node_info) = network_graph.node(&node_id) {
+                               if let Some((scid, channel_info)) = node_info
+                                       .channels
+                                               .iter()
+                                               .filter_map(|scid| network_graph.channel(*scid).map(|info| (*scid, info)))
+                                               .min_by_key(|(scid, _)| scid_utils::block_from_scid(*scid))
+                               {
+                                       let direction = if node_id == channel_info.node_one {
+                                               Direction::NodeOne
+                                       } else {
+                                               debug_assert_eq!(node_id, channel_info.node_two);
+                                               Direction::NodeTwo
+                                       };
+                                       self.0.introduction_node =
+                                               IntroductionNode::DirectedShortChannelId(direction, scid);
+                               }
+                       }
+               }
+       }
 }
 
 /// An intermediate node, and possibly a short channel id leading to the next node.
index 2ffb0ca9bd0ac08da8712df4412d937f1d33b836..b2cb2c018d839f025d97e89d28b174c4e09fca4a 100644 (file)
@@ -19,7 +19,6 @@ use core::ops::Deref;
 use crate::ln::msgs::DecodeError;
 use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph};
 use crate::util::ser::{Readable, Writeable, Writer};
-use crate::util::scid_utils;
 
 use crate::io;
 use crate::prelude::*;
@@ -139,35 +138,6 @@ impl BlindedPath {
                        },
                }
        }
-
-       /// Attempts to a use a compact representation for the [`IntroductionNode`] by using a directed
-       /// short channel id from a channel in `network_graph` leading to the introduction node.
-       ///
-       /// While this may result in a smaller encoding, there is a trade off in that the path may
-       /// become invalid if the channel is closed or hasn't been propagated via gossip. Therefore,
-       /// calling this may not be suitable for long-lived blinded paths.
-       pub fn use_compact_introduction_node(&mut self, network_graph: &ReadOnlyNetworkGraph) {
-               if let IntroductionNode::NodeId(pubkey) = &self.introduction_node {
-                       let node_id = NodeId::from_pubkey(pubkey);
-                       if let Some(node_info) = network_graph.node(&node_id) {
-                               if let Some((scid, channel_info)) = node_info
-                                       .channels
-                                       .iter()
-                                       .filter_map(|scid| network_graph.channel(*scid).map(|info| (*scid, info)))
-                                       .min_by_key(|(scid, _)| scid_utils::block_from_scid(*scid))
-                               {
-                                       let direction = if node_id == channel_info.node_one {
-                                               Direction::NodeOne
-                                       } else {
-                                               debug_assert_eq!(node_id, channel_info.node_two);
-                                               Direction::NodeTwo
-                                       };
-                                       self.introduction_node =
-                                               IntroductionNode::DirectedShortChannelId(direction, scid);
-                               }
-                       }
-               }
-       }
 }
 
 impl Writeable for BlindedPath {
index 69b87b7a1ea05fed164deb51262f9d6d8139ea9e..2fde66b126c79ccfb45196d51d2b61f1d7b85f70 100644 (file)
@@ -457,7 +457,7 @@ pub trait MessageRouter {
        ///
        /// Implementations using additional intermediate nodes are responsible for using a
        /// [`ForwardNode`] with `Some` short channel id, if possible. Similarly, implementations should
-       /// call [`BlindedPath::use_compact_introduction_node`].
+       /// call [`BlindedMessagePath::use_compact_introduction_node`].
        ///
        /// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`],
        /// ignoring the short channel ids.
@@ -565,7 +565,7 @@ where
 
                if compact_paths {
                        for path in &mut paths {
-                               path.0.use_compact_introduction_node(&network_graph);
+                               path.use_compact_introduction_node(&network_graph);
                        }
                }