]> git.bitcoin.ninja Git - rust-lightning/commit
Don't bump the `next_node_counter` when using a removed counter 2024-10-dense-counters
authorMatt Corallo <git@bluematt.me>
Mon, 14 Oct 2024 16:54:56 +0000 (16:54 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 14 Oct 2024 19:37:52 +0000 (19:37 +0000)
commit8913192b6c7e495174cdea57b4ab75cf48f69bc3
tree67bd555dbf65939fe0f7bf2e0db064875d6ed03d
parent46d8a0db79f3257cd5f2a6cdf896b1577ffccd88
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.
lightning/src/routing/gossip.rs