mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
net: Give seednodes time before falling back to fixed seeds
Before, we'd remove a seednode from the list right after connecting to it, leading to a race with loading the fixed seed and connecting to them.
This commit is contained in:
parent
6c7ebcc14b
commit
30778124b8
2 changed files with 7 additions and 6 deletions
11
src/net.cpp
11
src/net.cpp
|
@ -1641,6 +1641,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||||
auto next_extra_block_relay = GetExponentialRand(start, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
|
auto next_extra_block_relay = GetExponentialRand(start, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
|
||||||
const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED);
|
const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED);
|
||||||
bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS);
|
bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS);
|
||||||
|
const bool use_seednodes{gArgs.IsArgSet("-seednode")};
|
||||||
|
|
||||||
if (!add_fixed_seeds) {
|
if (!add_fixed_seeds) {
|
||||||
LogPrintf("Fixed seeds are disabled\n");
|
LogPrintf("Fixed seeds are disabled\n");
|
||||||
|
@ -1670,12 +1671,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");
|
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.
|
// Perform cheap checks before locking a mutex.
|
||||||
if (!add_fixed_seeds_now && !dnsseed) {
|
else if (!dnsseed && !use_seednodes) {
|
||||||
LOCK2(m_addr_fetches_mutex, m_added_nodes_mutex);
|
LOCK(m_added_nodes_mutex);
|
||||||
if (m_addr_fetches.empty() && m_added_nodes.empty()) {
|
if (m_added_nodes.empty()) {
|
||||||
add_fixed_seeds_now = true;
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
with self.nodes[0].assert_debug_log(expected_msgs=[
|
with self.nodes[0].assert_debug_log(expected_msgs=[
|
||||||
"Loaded 0 addresses from peers.dat",
|
"Loaded 0 addresses from peers.dat",
|
||||||
"DNS seeding disabled",
|
"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'])
|
self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1'])
|
||||||
assert time.time() - start < 60
|
assert time.time() - start < 60
|
||||||
|
|
Loading…
Add table
Reference in a new issue