Skip to content

Commit 402fcf8

Browse files
committed
Drop the dist HashMap in routing, replacing it with a Vec.
Now that we have unique, dense, 32-bit identifiers for all the nodes in our network graph, we can store the per-node information when routing in a simple `Vec` rather than a `HashMap`. This avoids the overhead of hashing and table scanning entirely, for a nice "simple" optimization win.
1 parent fceb2cb commit 402fcf8

File tree

3 files changed

+134
-39
lines changed

3 files changed

+134
-39
lines changed

lightning/src/routing/gossip.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,14 @@ impl<'a> DirectedChannelInfo<'a> {
11021102
/// Refers to the `node_id` receiving the payment from the previous hop.
11031103
#[inline]
11041104
pub fn target(&self) -> &'a NodeId { if self.from_node_one { &self.channel.node_two } else { &self.channel.node_one } }
1105+
1106+
/// Returns the source node's counter
1107+
#[inline]
1108+
pub(super) fn source_counter(&self) -> u32 { if self.from_node_one { self.channel.node_one_counter } else { self.channel.node_two_counter } }
1109+
1110+
/// Returns the target node's counter
1111+
#[inline]
1112+
pub(super) fn target_counter(&self) -> u32 { if self.from_node_one { self.channel.node_two_counter } else { self.channel.node_one_counter } }
11051113
}
11061114

11071115
impl<'a> fmt::Debug for DirectedChannelInfo<'a> {

0 commit comments

Comments
 (0)