@@ -1575,6 +1575,19 @@ int CConnman::GetExtraBlockRelayCount() const
1575
1575
return std::max (block_relay_peers - m_max_outbound_block_relay, 0 );
1576
1576
}
1577
1577
1578
+ std::unordered_set<Network> CConnman::GetReachableEmptyNetworks () const
1579
+ {
1580
+ std::unordered_set<Network> networks{};
1581
+ for (int n = 0 ; n < NET_MAX; n++) {
1582
+ enum Network net = (enum Network)n;
1583
+ if (net == NET_UNROUTABLE || net == NET_INTERNAL) continue ;
1584
+ if (IsReachable (net) && addrman.Size (net, std::nullopt) == 0 ) {
1585
+ networks.insert (net);
1586
+ }
1587
+ }
1588
+ return networks;
1589
+ }
1590
+
1578
1591
void CConnman::ThreadOpenConnections (const std::vector<std::string> connect)
1579
1592
{
1580
1593
SetSyscallSandboxPolicy (SyscallSandboxPolicy::NET_OPEN_CONNECTION);
@@ -1624,7 +1637,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1624
1637
if (interruptNet)
1625
1638
return ;
1626
1639
1627
- if (add_fixed_seeds && addrman.size () == 0 ) {
1640
+ const std::unordered_set<Network> fixed_seed_networks{GetReachableEmptyNetworks ()};
1641
+ if (add_fixed_seeds && !fixed_seed_networks.empty ()) {
1628
1642
// When the node starts with an empty peers.dat, there are a few other sources of peers before
1629
1643
// we fallback on to fixed seeds: -dnsseed, -seednode, -addnode
1630
1644
// If none of those are available, we fallback on to fixed seeds immediately, else we allow
@@ -1633,7 +1647,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1633
1647
// It is cheapest to check if enough time has passed first.
1634
1648
if (GetTime<std::chrono::seconds>() > start + std::chrono::minutes{1 }) {
1635
1649
add_fixed_seeds_now = true ;
1636
- LogPrintf (" Adding fixed seeds as 60 seconds have passed and addrman is empty\n " );
1650
+ LogPrintf (" Adding fixed seeds as 60 seconds have passed and addrman is empty for at least one reachable network \n " );
1637
1651
}
1638
1652
1639
1653
// Checking !dnsseed is cheaper before locking 2 mutexes.
@@ -1650,14 +1664,12 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1650
1664
// We will not make outgoing connections to peers that are unreachable
1651
1665
// (e.g. because of -onlynet configuration).
1652
1666
// Therefore, we do not add them to addrman in the first place.
1653
- // Note that if you change -onlynet setting from one network to another,
1654
- // peers.dat will contain only peers of unreachable networks and
1655
- // manual intervention will be needed (either delete peers.dat after
1656
- // configuration change or manually add some reachable peer using addnode),
1657
- // see <https://github.com/bitcoin/bitcoin/issues/26035> for details.
1667
+ // In case previously unreachable networks become reachable
1668
+ // (e.g. in case of -onlynet changes by the user), fixed seeds will
1669
+ // be loaded only for networks for which we have no addressses.
1658
1670
seed_addrs.erase (std::remove_if (seed_addrs.begin (), seed_addrs.end (),
1659
- [ ](const CAddress& addr) { return ! IsReachable (addr) ; }),
1660
- seed_addrs.end ());
1671
+ [&fixed_seed_networks ](const CAddress& addr) { return fixed_seed_networks. count (addr. GetNetwork ()) == 0 ; }),
1672
+ seed_addrs.end ());
1661
1673
CNetAddr local;
1662
1674
local.SetInternal (" fixedseeds" );
1663
1675
addrman.Add (seed_addrs, local);
0 commit comments