Fix race condition in sendheaders.py (#2862)

generate() will push INV messages to all nodes, including our test_node.
The original check_last_announcement() call done here will then
sporadically return Fals when the INV message is received shortly after
clear_last_announcement()

Solution is to check for the INV announcement first and then continue with
the test.
This commit is contained in:
Alexander Block 2019-04-12 13:37:14 +02:00 committed by UdjinM6
parent 0c54e41f22
commit 1d8c7226d0

View File

@ -297,6 +297,11 @@ class SendHeadersTest(BitcoinTestFramework):
tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0]) tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0])
tip_hash = int(tip["hash"], 16) tip_hash = int(tip["hash"], 16)
# TODO this partly fixes the same thing that is fixed by https://github.com/bitcoin/bitcoin/pull/13192
# This will later conflict when backporting the actual fix. Just take everything from the Bitcoin fix as a
# resolution
assert_equal(test_node.check_last_announcement(headers=[], inv=[tip_hash]), True)
self.log.info("Verify getheaders with null locator and valid hashstop returns headers.") self.log.info("Verify getheaders with null locator and valid hashstop returns headers.")
test_node.clear_last_announcement() test_node.clear_last_announcement()
test_node.get_headers(locator=[], hashstop=tip_hash) test_node.get_headers(locator=[], hashstop=tip_hash)