mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Merge bitcoin/bitcoin#27577: p2p: give seednodes time before falling back to fixed seeds
30778124b8
net: Give seednodes time before falling back to fixed seeds (Martin Zumsande) Pull request description: `-seednode` is an alternative bootstrap mechanism - when choosing it, we make a `AddrFetch` connection to the specified peer, gather addresses from them, and then disconnect. Presumably, if users specify a seednode they prefer addresses from that node over fixed seeds. However, when disabling dns seeds and specifiying `-seednode`, `CConnman::ProcessAddrFetch()` immediately removes the entry from `m_addr_fetches` (before the seednode could give us addresses) - and once `m_addr_fetches` is empty, `ThreadOpenConnections` will add fixed seeds, resulting in a "race" between the fixed seeds and seednodes filling up AddrMan. This PR suggests to check for any provided `-seednode` arg instead of using the size of `m_addr_fetches`, thus delaying the querying of fixed seeds for 1 minute when specifying any seednode (as we already do for `addnode` peers). That way, we actually give the seednodes a chance for to provide us with addresses before falling back to fixed seeds. This can be tested with `bitcoind -debug=net -dnsseed=0 -seednode=(...)` on a node without `peers.dat` and observing the debug log. ACKs for top commit: ajtowns: utACK30778124b8
achow101: ACK30778124b8
dergoegge: Code review ACK30778124b8
sr-gi: ACK [3077812
](30778124b8
) with a tiny nit, feel free to ignore it Tree-SHA512: 96446eb34c0805f10ee158a00a3001a07029e795ac40ad5638228d426e30e9bb836c64ac05d145f2f9ab23ec5a528f3a416e3d52ecfdfb0b813bd4b1ebab3c01
This commit is contained in:
commit
035ae61c5a
2 changed files with 7 additions and 6 deletions
11
src/net.cpp
11
src/net.cpp
|
@ -1637,6 +1637,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||
auto next_extra_block_relay = GetExponentialRand(start, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
|
||||
const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED);
|
||||
bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS);
|
||||
const bool use_seednodes{gArgs.IsArgSet("-seednode")};
|
||||
|
||||
if (!add_fixed_seeds) {
|
||||
LogPrintf("Fixed seeds are disabled\n");
|
||||
|
@ -1666,12 +1667,12 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||
LogPrintf("Adding fixed seeds as 60 seconds have passed and addrman is empty for at least one reachable network\n");
|
||||
}
|
||||
|
||||
// Checking !dnsseed is cheaper before locking 2 mutexes.
|
||||
if (!add_fixed_seeds_now && !dnsseed) {
|
||||
LOCK2(m_addr_fetches_mutex, m_added_nodes_mutex);
|
||||
if (m_addr_fetches.empty() && m_added_nodes.empty()) {
|
||||
// Perform cheap checks before locking a mutex.
|
||||
else if (!dnsseed && !use_seednodes) {
|
||||
LOCK(m_added_nodes_mutex);
|
||||
if (m_added_nodes.empty()) {
|
||||
add_fixed_seeds_now = true;
|
||||
LogPrintf("Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet), -addnode is not provided and all -seednode(s) attempted\n");
|
||||
LogPrintf("Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet) and neither -addnode nor -seednode are provided\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ class ConfArgsTest(BitcoinTestFramework):
|
|||
with self.nodes[0].assert_debug_log(expected_msgs=[
|
||||
"Loaded 0 addresses from peers.dat",
|
||||
"DNS seeding disabled",
|
||||
"Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet), -addnode is not provided and all -seednode(s) attempted\n",
|
||||
"Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet) and neither -addnode nor -seednode are provided\n",
|
||||
]):
|
||||
self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1'])
|
||||
assert time.time() - start < 60
|
||||
|
|
Loading…
Add table
Reference in a new issue