Skip to content

Commit aa3c727

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 ba56f3c commit aa3c727

File tree

4 files changed

+134
-39
lines changed

4 files changed

+134
-39
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl_writeable!(BlindedHop, {
306306

307307
impl Direction {
308308
/// Returns the [`NodeId`] from the inputs corresponding to the direction.
309-
pub fn select_node_id<'a>(&self, node_a: &'a NodeId, node_b: &'a NodeId) -> &'a NodeId {
309+
pub fn select_node_id(&self, node_a: NodeId, node_b: NodeId) -> NodeId {
310310
match self {
311311
Direction::NodeOne => core::cmp::min(node_a, node_b),
312312
Direction::NodeTwo => core::cmp::max(node_a, node_b),

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)