Move get_addresses to network_graph and drop now-useless log_trace
authorMatt Corallo <git@bluematt.me>
Tue, 12 May 2020 01:07:02 +0000 (21:07 -0400)
committerMatt Corallo <git@bluematt.me>
Tue, 12 May 2020 18:02:40 +0000 (14:02 -0400)
Because we expose the internals we don't need a method to log
their contents anymore, and get_addresses can now avoid copying as
we expose the RwLock directly

lightning/src/routing/network_graph.rs

index faf2b5ff208ae1789df094e20d45f9e647fe84cd..dd6d7d7ed734aadbd7f89f93308aefd0223a9f79 100644 (file)
@@ -67,25 +67,6 @@ impl NetGraphMsgHandler {
                        logger: logger.clone(),
                }
        }
-
-       /// Get network addresses by node id.
-       /// Returns None if the requested node is completely unknown,
-       /// or if node announcement for the node was never received.
-       pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<NetAddress>> {
-               let network = self.network_graph.read().unwrap();
-               if let Some(node) = network.get_nodes().get(pubkey) {
-                       if let Some(node_info) = node.announcement_info.as_ref() {
-                               return Some(node_info.addresses.clone())
-                       }
-               }
-               None
-       }
-
-       /// Dumps the entire network view of this NetGraphMsgHandler to the logger provided in the constructor at
-       /// level Trace
-       pub fn trace_state(&self) {
-               log_trace!(self, "{}", self.network_graph.read().unwrap());
-       }
 }
 
 
@@ -509,6 +490,18 @@ impl NetworkGraph {
        /// Returns all known nodes' public keys along with announced node info.
        pub fn get_nodes<'a>(&'a self) -> &'a BTreeMap<PublicKey, NodeInfo> { &self.nodes }
 
+       /// Get network addresses by node id.
+       /// Returns None if the requested node is completely unknown,
+       /// or if node announcement for the node was never received.
+       pub fn get_addresses<'a>(&'a self, pubkey: &PublicKey) -> Option<&'a Vec<NetAddress>> {
+               if let Some(node) = self.nodes.get(pubkey) {
+                       if let Some(node_info) = node.announcement_info.as_ref() {
+                               return Some(&node_info.addresses)
+                       }
+               }
+               None
+       }
+
        /// For an already known node (from channel announcements), update its stored properties from a given node announcement
        /// Announcement signatures are checked here only if Secp256k1 object is provided.
        fn update_node_from_announcement(&mut self, msg: &msgs::NodeAnnouncement, secp_ctx: Option<&Secp256k1<secp256k1::VerifyOnly>>) -> Result<bool, LightningError> {