]> git.bitcoin.ninja Git - rust-lightning/commit
Don't bump the `next_node_counter` when using a removed counter
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 16:54:56 +0000 (16:54 +0000)
commitacfc6d9364519706d7636ab95b908d120c27bd2a
tree25b41bc2cf1c1b46c5f1ca4394ec20262157ad17
parent68d27bc7f3b08c176ba8548d8d1c1a21c7f3ec4e
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