[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.
This commit is contained in:
parent
dbfe294805
commit
2e02984591
1 changed files with 7 additions and 8 deletions
|
@ -2,15 +2,15 @@
|
||||||
# Copyright (c) 2017 The Bitcoin Core developers
|
# Copyright (c) 2017 The Bitcoin Core developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# 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.mininode import NODE_BLOOM, NODE_NETWORK_LIMITED, NODE_WITNESS, NetworkThread, P2PInterface
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal
|
from test_framework.util import assert_equal
|
||||||
|
|
||||||
class BaseNode(P2PInterface):
|
class P2PIgnoreInv(P2PInterface):
|
||||||
nServices = 0
|
def on_inv(self, message):
|
||||||
def on_version(self, message):
|
# The node will send us invs for other blocks. Ignore them.
|
||||||
self.nServices = message.nServices
|
pass
|
||||||
|
|
||||||
class NodeNetworkLimitedTest(BitcoinTestFramework):
|
class NodeNetworkLimitedTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
|
@ -19,7 +19,7 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
|
||||||
self.extra_args = [['-prune=550']]
|
self.extra_args = [['-prune=550']]
|
||||||
|
|
||||||
def get_signalled_service_flags(self):
|
def get_signalled_service_flags(self):
|
||||||
node = self.nodes[0].add_p2p_connection(BaseNode())
|
node = self.nodes[0].add_p2p_connection(P2PIgnoreInv())
|
||||||
NetworkThread().start()
|
NetworkThread().start()
|
||||||
node.wait_for_verack()
|
node.wait_for_verack()
|
||||||
services = node.nServices
|
services = node.nServices
|
||||||
|
@ -28,10 +28,9 @@ class NodeNetworkLimitedTest(BitcoinTestFramework):
|
||||||
return services
|
return services
|
||||||
|
|
||||||
def try_get_block_via_getdata(self, blockhash, must_disconnect):
|
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()
|
NetworkThread().start()
|
||||||
node.wait_for_verack()
|
node.wait_for_verack()
|
||||||
node.send_message(msg_verack())
|
|
||||||
getdata_request = msg_getdata()
|
getdata_request = msg_getdata()
|
||||||
getdata_request.inv.append(CInv(2, int(blockhash, 16)))
|
getdata_request.inv.append(CInv(2, int(blockhash, 16)))
|
||||||
node.send_message(getdata_request)
|
node.send_message(getdata_request)
|
||||||
|
|
Loading…
Reference in a new issue