-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: Favor peers from addrman over fetching seednodes
The current behavior of seednode fetching is pretty eager: we do it as the first step under `ThreadOpenNetworkConnections` even if some peers may be queryable from our addrman. This poses two potential issues: - First, if permanently set (e.g. running with seednode in a config file) we'd be signaling such seed every time we restart our node - Second, we will be giving the seed node way too much influence over our addrman, populating the latter even with data from the former even when unnecessary This changes the behavior to only add seednodes to `m_addr_fetch` if our addrman is empty, or little by little after we've spent some time trying addresses from our addrman. Also, seednodes are added to `m_addr_fetch` in random order, to avoid signaling the same node in case more than one seed is added and we happen to try them over multiple restarts
- Loading branch information
Showing
4 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2019-2021 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
""" | ||
Test seednode interaction with the AddrMan | ||
""" | ||
import random | ||
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
|
||
|
||
class P2PSeedNodes(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.num_nodes = 1 | ||
self.disable_autoconnect = False | ||
|
||
def test_no_seednode(self): | ||
# Check that if no seednode is provided, the node proceeds as usual (without waiting) | ||
with self.nodes[0].assert_debug_log(expected_msgs=[], unexpected_msgs=["Empty addrman, adding seednode", "Couldn't connect to peers from addrman after 10 seconds. Adding seednode"], timeout=10): | ||
self.restart_node(0) | ||
|
||
def test_seednode_empty_addrman(self): | ||
seed_node = "0.0.0.1" | ||
# Check that the seednode is added to m_addr_fetches on bootstrap on an empty addrman | ||
with self.nodes[0].assert_debug_log(expected_msgs=[f"Empty addrman, adding seednode ({seed_node}) to addrfetch"], timeout=10): | ||
self.restart_node(0, extra_args=[f'-seednode={seed_node}']) | ||
|
||
def test_seednode_addrman_unreachable_peers(self): | ||
seed_node = "0.0.0.2" | ||
# Fill the addrman with unreachable nodes | ||
for i in range(10): | ||
ip = f"{random.randrange(128,169)}.{random.randrange(1,255)}.{random.randrange(1,255)}.{random.randrange(1,255)}" | ||
port = 8333 + i | ||
self.nodes[0].addpeeraddress(ip, port) | ||
|
||
# Restart the node so seednode is processed again | ||
with self.nodes[0].assert_debug_log(expected_msgs=[f"Couldn't connect to peers from addrman after 10 seconds. Adding seednode ({seed_node}) to addrfetch"], unexpected_msgs=["Empty addrman, adding seednode"], timeout=20): | ||
self.restart_node(0, extra_args=[f'-seednode={seed_node}']) | ||
|
||
def run_test(self): | ||
self.test_no_seednode() | ||
self.test_seednode_empty_addrman() | ||
self.test_seednode_addrman_unreachable_peers() | ||
|
||
|
||
if __name__ == '__main__': | ||
P2PSeedNodes().main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters