From 2e029845919eedcb4c4ff5f951cc85d95da68ad1 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Mon, 11 Dec 2017 12:08:33 -0500 Subject: [PATCH] [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. --- test/functional/node_network_limited.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/functional/node_network_limited.py b/test/functional/node_network_limited.py index 1e7c61b44..6f1c60eec 100755 --- a/test/functional/node_network_limited.py +++ b/test/functional/node_network_limited.py @@ -2,15 +2,15 @@ # Copyright (c) 2017 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -from test_framework.messages import CInv, msg_getdata, msg_verack +from test_framework.messages import CInv, msg_getdata from test_framework.mininode import NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS, NetworkThread, P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal -class BaseNode(P2PInterface): - nServices = 0 - def on_version(self, message): - self.nServices = message.nServices +class P2PIgnoreInv(P2PInterface): + def on_inv(self, message): + # The node will send us invs for other blocks. Ignore them. + pass class NodeNetworkLimitedTest(BitcoinTestFramework): def set_test_params(self): @@ -19,7 +19,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework): self.extra_args = [['-prune=550']] def get_signalled_service_flags(self): - node = self.nodes[0].add_p2p_connection(BaseNode()) + node = self.nodes[0].add_p2p_connection(P2PIgnoreInv()) NetworkThread().start() node.wait_for_verack() services = node.nServices @@ -28,10 +28,9 @@ class NodeNetworkLimitedTest(BitcoinTestFramework): return services def try_get_block_via_getdata(self, blockhash, must_disconnect): - node = self.nodes[0].add_p2p_connection(BaseNode()) + node = self.nodes[0].add_p2p_connection(P2PIgnoreInv()) NetworkThread().start() node.wait_for_verack() - node.send_message(msg_verack()) getdata_request = msg_getdata() getdata_request.inv.append(CInv(2, int(blockhash, 16))) node.send_message(getdata_request)