Skip to content

Commit 9343199

Browse files
f no double lookup, nits
1 parent db06573 commit 9343199

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lightning/src/routing/onion_message.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ pub fn find_path<L: Deref, GL: Deref>(
2424
our_node_pubkey: &PublicKey, destination: &PublicKey, network_graph: &NetworkGraph<GL>, first_hops: Option<&[&PublicKey]>, logger: L
2525
) -> Result<Vec<PublicKey>, Error> where L::Target: Logger, GL::Target: Logger
2626
{
27-
log_trace!(logger, "Searching for an onion message path from origin {} to destination {} and {} first hops {}overriding the network graph", our_node_pubkey, destination, first_hops.map(|hops| hops.len()).unwrap_or(0), if first_hops.is_some() { "" } else { "not " });
27+
log_trace!(logger, "Searching for an onion message path from origin {} to destination {} and {} first hops {}overriding the network graph",
28+
our_node_pubkey, destination, first_hops.map(|hops| hops.len()).unwrap_or(0),
29+
if first_hops.is_some() { "" } else { "not " });
2830
let graph_lock = network_graph.read_only();
2931
let network_channels = graph_lock.channels();
3032
let network_nodes = graph_lock.nodes();
@@ -43,10 +45,11 @@ pub fn find_path<L: Deref, GL: Deref>(
4345
}
4446

4547
let mut visited = HashMap::new();
46-
while !frontier.is_empty() {
47-
let PathBuildingHop { cost, node_id, parent_node_id } = frontier.pop().unwrap();
48-
if visited.contains_key(&node_id) { continue; }
49-
visited.insert(node_id, parent_node_id);
48+
while let Some(PathBuildingHop { cost, node_id, parent_node_id }) = frontier.pop() {
49+
match visited.entry(node_id) {
50+
hash_map::Entry::Occupied(_) => continue,
51+
hash_map::Entry::Vacant(e) => e.insert(parent_node_id),
52+
};
5053
if node_id == dest_node_id {
5154
return Ok(reverse_path(visited, our_node_id, dest_node_id, logger)?)
5255
}

0 commit comments

Comments
 (0)