Skip to content

Commit 0e3bf19

Browse files
committed
Move get_addresses to network_graph and drop now-useless log_trace
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
1 parent 5dc724f commit 0e3bf19

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,6 @@ impl NetGraphMsgHandler {
6767
logger: logger.clone(),
6868
}
6969
}
70-
71-
/// Get network addresses by node id.
72-
/// Returns None if the requested node is completely unknown,
73-
/// or if node announcement for the node was never received.
74-
pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<NetAddress>> {
75-
let network = self.network_graph.read().unwrap();
76-
if let Some(node) = network.get_nodes().get(pubkey) {
77-
if let Some(node_info) = node.announcement_info.as_ref() {
78-
return Some(node_info.addresses.clone())
79-
}
80-
}
81-
None
82-
}
83-
84-
/// Dumps the entire network view of this NetGraphMsgHandler to the logger provided in the constructor at
85-
/// level Trace
86-
pub fn trace_state(&self) {
87-
log_trace!(self, "{}", self.network_graph.read().unwrap());
88-
}
8970
}
9071

9172

@@ -509,6 +490,18 @@ impl NetworkGraph {
509490
/// Returns all known nodes' public keys along with announced node info.
510491
pub fn get_nodes<'a>(&'a self) -> &'a BTreeMap<PublicKey, NodeInfo> { &self.nodes }
511492

493+
/// Get network addresses by node id.
494+
/// Returns None if the requested node is completely unknown,
495+
/// or if node announcement for the node was never received.
496+
pub fn get_addresses<'a>(&'a self, pubkey: &PublicKey) -> Option<&'a Vec<NetAddress>> {
497+
if let Some(node) = self.nodes.get(pubkey) {
498+
if let Some(node_info) = node.announcement_info.as_ref() {
499+
return Some(&node_info.addresses)
500+
}
501+
}
502+
None
503+
}
504+
512505
/// For an already known node (from channel announcements), update its stored properties from a given node announcement
513506
/// Announcement signatures are checked here only if Secp256k1 object is provided.
514507
fn update_node_from_announcement(&mut self, msg: &msgs::NodeAnnouncement, secp_ctx: Option<&Secp256k1<secp256k1::VerifyOnly>>) -> Result<bool, LightningError> {

0 commit comments

Comments
 (0)