Skip to content

Finding peers to connect to after -onlynet changes may be problematic #26035

@vasild

Description

@vasild

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:

  1. Fixed seeds should be used if we have 0 reachable peers in addrman. I guess this condition should be relaxed, like discussed in p2p: skip querying dns seeds if -onlynet disables IPv4 and IPv6 #25678 (comment)

if (add_fixed_seeds && addrman.size() == 0) {

  1. 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):
select random address
if 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions