Skip to content

Commit 2e02984

Browse files
committed
[tests] node_network_limited - remove race condition
node_network_limited had a race condition, since wait_for_block() doesn't do what you might expect. It only checks the most recent block received over the P2P interface (perhaps we should rename the method wait_for_most_recent_block() to avoid future confusion). The test can fail if the node sends us invs for other blocks, we respond with a getdata, and the node sends us one of those blocks in the 0.05 second wait_until loop window. Fix this by not responding to inv messages with getdata messages.
1 parent dbfe294 commit 2e02984

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

test/functional/node_network_limited.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# Copyright (c) 2017 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
from test_framework.messages import CInv, msg_getdata, msg_verack
5+
from test_framework.messages import CInv, msg_getdata
66
from test_framework.mininode import NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS, NetworkThread, P2PInterface
77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import assert_equal
99

10-
class BaseNode(P2PInterface):
11-
nServices = 0
12-
def on_version(self, message):
13-
self.nServices = message.nServices
10+
class P2PIgnoreInv(P2PInterface):
11+
def on_inv(self, message):
12+
# The node will send us invs for other blocks. Ignore them.
13+
pass
1414

1515
class NodeNetworkLimitedTest(BitcoinTestFramework):
1616
def set_test_params(self):
@@ -19,7 +19,7 @@ def set_test_params(self):
1919
self.extra_args = [['-prune=550']]
2020

2121
def get_signalled_service_flags(self):
22-
node = self.nodes[0].add_p2p_connection(BaseNode())
22+
node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
2323
NetworkThread().start()
2424
node.wait_for_verack()
2525
services = node.nServices
@@ -28,10 +28,9 @@ def get_signalled_service_flags(self):
2828
return services
2929

3030
def try_get_block_via_getdata(self, blockhash, must_disconnect):
31-
node = self.nodes[0].add_p2p_connection(BaseNode())
31+
node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
3232
NetworkThread().start()
3333
node.wait_for_verack()
34-
node.send_message(msg_verack())
3534
getdata_request = msg_getdata()
3635
getdata_request.inv.append(CInv(2, int(blockhash, 16)))
3736
node.send_message(getdata_request)

0 commit comments

Comments
 (0)