An address is placed in a [bucket,position]
in the addrman table (new table or tried table) using the addpeeraddress
RPC. This [bucket,position]
is calculated using nKey
(and other metrics) for the addrman which is chosen randomly during every run.
Supposing there are 2 addresses to be placed in an addrman table. During every test run, a different [bucket,position]
would be calculated for each address.These calculated [bucket,position]
could even be the same for the 2 addresses in some test runs and result in collisions in the addrman. We wouldn’t be able to predict when the collisions are going to happen because we can’t predict the nKey
value which is chosen at random. This can cause flaky tests.
Because of these non deterministic collisions, we are limited in what we can do to test addrman functionality. Currently in our tests don’t add a second address to prevent these collisions from happening - we only keep 1 address in the new table and 1 address in the tried table. See #26988 (review), #23084, #22831(comment).
This PR lets us create a deterministic addrman with fixed nKey
so that we can know the [bucket,position]
collisions beforehand, safely add more addresses in an addrman table and write more extensive tests.