mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-24 18:23:26 -03:00
test: avoid generating non-loopback traffic from p2p_seednode.py
`p2p_seednode.py` would try to connect to `0.0.0.1` and `0.0.0.2` as seed nodes. This sends outbound TCP packets on a non-loopback interface to the default router. Configure an unavailable proxy for all executions of `bitcoind` during this test. Also change `0.0.0.1` and `0.0.0.2` because connecting to them would skip the `-proxy=` setting because for such an address: * `CNetAddr::IsLocal()` is true, thus * `CNetAddr::IsRoutable()` is false, thus * `CNetAddr::GetNetwork()` is `NET_UNROUTABLE`, even though `CNetAddr::m_net` is `NET_IPV4`. This speeds up the execution time of `p2p_seednode.py` from 12.5s to 2.5s.
This commit is contained in:
parent
35bf426e02
commit
6b3f6eae70
2 changed files with 13 additions and 6 deletions
|
@ -9,6 +9,7 @@ Test seednode interaction with the AddrMan
|
|||
import random
|
||||
import time
|
||||
|
||||
from test_framework.netutil import UNREACHABLE_PROXY_ARG
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
|
||||
ADD_NEXT_SEEDNODE = 10
|
||||
|
@ -17,22 +18,24 @@ ADD_NEXT_SEEDNODE = 10
|
|||
class P2PSeedNodes(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
# Specify a non-working proxy to make sure no actual connections to random IPs are attempted.
|
||||
self.extra_args = [[UNREACHABLE_PROXY_ARG]]
|
||||
self.disable_autoconnect = False
|
||||
|
||||
def test_no_seednode(self):
|
||||
self.log.info("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", f"Couldn't connect to peers from addrman after {ADD_NEXT_SEEDNODE} seconds. Adding seednode"], timeout=ADD_NEXT_SEEDNODE):
|
||||
self.restart_node(0)
|
||||
self.restart_node(0, extra_args=self.nodes[0].extra_args)
|
||||
|
||||
def test_seednode_empty_addrman(self):
|
||||
seed_node = "0.0.0.1"
|
||||
seed_node = "25.0.0.1"
|
||||
self.log.info("Check that the seednode is immediately added 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=ADD_NEXT_SEEDNODE):
|
||||
self.restart_node(0, extra_args=[f'-seednode={seed_node}'])
|
||||
self.restart_node(0, extra_args=self.nodes[0].extra_args + [f'-seednode={seed_node}'])
|
||||
|
||||
def test_seednode_non_empty_addrman(self):
|
||||
self.log.info("Check that if addrman is non-empty, seednodes are queried with a delay")
|
||||
seed_node = "0.0.0.2"
|
||||
seed_node = "25.0.0.2"
|
||||
node = self.nodes[0]
|
||||
# Fill the addrman with unreachable nodes
|
||||
for i in range(10):
|
||||
|
@ -40,9 +43,9 @@ class P2PSeedNodes(BitcoinTestFramework):
|
|||
port = 8333 + i
|
||||
node.addpeeraddress(ip, port)
|
||||
|
||||
# Restart the node so seednode is processed again. Specify a non-working proxy to make sure no actual connections to random IPs are attempted.
|
||||
# Restart the node so seednode is processed again.
|
||||
with node.assert_debug_log(expected_msgs=["trying v1 connection"], timeout=ADD_NEXT_SEEDNODE):
|
||||
self.restart_node(0, extra_args=[f'-seednode={seed_node}', '-proxy=127.0.0.1:1'])
|
||||
self.restart_node(0, extra_args=self.nodes[0].extra_args + [f'-seednode={seed_node}'])
|
||||
|
||||
with node.assert_debug_log(expected_msgs=[f"Couldn't connect to peers from addrman after {ADD_NEXT_SEEDNODE} seconds. Adding seednode ({seed_node}) to addrfetch"], unexpected_msgs=["Empty addrman, adding seednode"], timeout=ADD_NEXT_SEEDNODE * 1.5):
|
||||
node.setmocktime(int(time.time()) + ADD_NEXT_SEEDNODE + 1)
|
||||
|
|
|
@ -13,6 +13,10 @@ import struct
|
|||
import array
|
||||
import os
|
||||
|
||||
# Easily unreachable address. Attempts to connect to it will stay within the machine.
|
||||
# Used to avoid non-loopback traffic or DNS queries.
|
||||
UNREACHABLE_PROXY_ARG = '-proxy=127.0.0.1:1'
|
||||
|
||||
# STATE_ESTABLISHED = '01'
|
||||
# STATE_SYN_SENT = '02'
|
||||
# STATE_SYN_RECV = '03'
|
||||
|
|
Loading…
Add table
Reference in a new issue