Skip to content

Commit acfc6d9

Browse files
committed
Don't bump the next_node_counter when using a removed counter
If we manage to pull a `node_counter` from `removed_node_counters` for reuse, `add_channel_between_nodes` would `unwrap_or` with the `next_node_counter`-incremented value. This visually looks right, except `unwrap_or` is always called, causing us to always increment `next_node_counter` even if we don't use it. This will result in the `node_counter`s always growing any time we add a new node to our graph, leading to somewhat larger memory usage when routing and a debug assertion failure in `test_node_counter_consistency`. The fix is trivial, this is what `unwrap_or_else` is for.
1 parent 68d27bc commit acfc6d9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lightning/src/routing/gossip.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,9 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
18981898
IndexedMapEntry::Vacant(node_entry) => {
18991899
let mut removed_node_counters = self.removed_node_counters.lock().unwrap();
19001900
**chan_info_node_counter = removed_node_counters.pop()
1901-
.unwrap_or(self.next_node_counter.fetch_add(1, Ordering::Relaxed) as u32);
1901+
.unwrap_or_else(|| {
1902+
self.next_node_counter.fetch_add(1, Ordering::Relaxed) as u32
1903+
});
19021904
node_entry.insert(NodeInfo {
19031905
channels: vec!(short_channel_id),
19041906
announcement_info: None,

0 commit comments

Comments
 (0)