Skip to content

Commit 035ae61

Browse files
committed
Merge bitcoin/bitcoin#27577: p2p: give seednodes time before falling back to fixed seeds
3077812 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: utACK 3077812 achow101: ACK 3077812 dergoegge: Code review ACK 3077812 sr-gi: ACK [3077812](bitcoin/bitcoin@3077812) with a tiny nit, feel free to ignore it Tree-SHA512: 96446eb34c0805f10ee158a00a3001a07029e795ac40ad5638228d426e30e9bb836c64ac05d145f2f9ab23ec5a528f3a416e3d52ecfdfb0b813bd4b1ebab3c01
2 parents 8e0cf4f + 3077812 commit 035ae61

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/net.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
16371637
auto next_extra_block_relay = GetExponentialRand(start, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
16381638
const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED);
16391639
bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS);
1640+
const bool use_seednodes{gArgs.IsArgSet("-seednode")};
16401641

16411642
if (!add_fixed_seeds) {
16421643
LogPrintf("Fixed seeds are disabled\n");
@@ -1666,12 +1667,12 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
16661667
LogPrintf("Adding fixed seeds as 60 seconds have passed and addrman is empty for at least one reachable network\n");
16671668
}
16681669

1669-
// Checking !dnsseed is cheaper before locking 2 mutexes.
1670-
if (!add_fixed_seeds_now && !dnsseed) {
1671-
LOCK2(m_addr_fetches_mutex, m_added_nodes_mutex);
1672-
if (m_addr_fetches.empty() && m_added_nodes.empty()) {
1670+
// Perform cheap checks before locking a mutex.
1671+
else if (!dnsseed && !use_seednodes) {
1672+
LOCK(m_added_nodes_mutex);
1673+
if (m_added_nodes.empty()) {
16731674
add_fixed_seeds_now = true;
1674-
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");
1675+
LogPrintf("Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet) and neither -addnode nor -seednode are provided\n");
16751676
}
16761677
}
16771678

test/functional/feature_config_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def test_seed_peers(self):
253253
with self.nodes[0].assert_debug_log(expected_msgs=[
254254
"Loaded 0 addresses from peers.dat",
255255
"DNS seeding disabled",
256-
"Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet), -addnode is not provided and all -seednode(s) attempted\n",
256+
"Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet) and neither -addnode nor -seednode are provided\n",
257257
]):
258258
self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1'])
259259
assert time.time() - start < 60

0 commit comments

Comments
 (0)