Skip to content

Commit eedbc37

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 019fb85 commit eedbc37

File tree

3 files changed

+133
-38
lines changed

3 files changed

+133
-38
lines changed

lightning/src/routing/gossip.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,14 @@ impl<'a> DirectedChannelInfo<'a> {
10671067
/// Refers to the `node_id` receiving the payment from the previous hop.
10681068
#[inline]
10691069
pub fn target(&self) -> &'a NodeId { if self.from_node_one { &self.channel.node_two } else { &self.channel.node_one } }
1070+
1071+
/// Returns the source node's counter
1072+
#[inline]
1073+
pub(super) fn source_counter(&self) -> u32 { if self.from_node_one { self.channel.node_one_counter } else { self.channel.node_two_counter } }
1074+
1075+
/// Returns the target node's counter
1076+
#[inline]
1077+
pub(super) fn target_counter(&self) -> u32 { if self.from_node_one { self.channel.node_two_counter } else { self.channel.node_one_counter } }
10701078
}
10711079

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

0 commit comments

Comments
 (0)