Expected behavior
Bitcoin Core, ideally, should always have peers to try to connect to just like when started for the very first time (empty peers.dat
). It should not be more difficult to find possible peers if it was ran before with a different -onlynet=
setting.
Actual behavior
If addrman has some entries, even to only unreachable networks, due to previous runs and changes in -onlynet
, then the fixed seeds will not be used.
To reproduce
Run with -onlynet=ipv4
, change to -onlynet=i2p
.
To fix
This problem is two-fold:
- Fixed seeds should be used if we have 0 reachable peers in addrman. I guess this condition should be relaxed, like discussed in #25678 (comment)
https://github.com/bitcoin/bitcoin/blob/fc44d1796e4df5824423d7d13de3082fe204db7d/src/net.cpp#L1628
- Even if there are a few reachable peers in addrman, e.g. 0.1% it will take a long time before they are tried. The address selection logic can be improved. It is, simplified, like this (see lines 1797 and 1810):
0select random address
1if not reachable then try another random address
Can be improved to “select random address, but only from reachable networks”.
This problem is amplified by the fact that we do not save non-reachable addresses in addrman during p2p gossip (and also see #25678). Maybe we should reconsider that as a 3rd fixup, in addition to the above 2 - save even unreachable addresses in addrman during p2p gossip and fixed seeds loadup? What is the worst that can happen? We will have some wasted space in addrman if onlynet
is never altered?