Skip to content

Commit 5d605b2

Browse files
author
MarcoFalke
committed
Merge #14700: qa: Avoid race in p2p_invalid_block by waiting for the block request
fa21568 qa: Avoid race in p2p_invalid_block by waiting for the block request (MarcoFalke) 6c787d3 tests: Make feature_block pass on centos (MarcoFalke) Pull request description: This hopefully fixes #14661, which I believe is caused by a race in `send_blocks_and_test`. By setting `request_block=False` we only effectively check `node.getbestblockhash() != blocks[-1].hash` before returning and checking the debug.log. By setting `request_block=True` (the default) we make sure that we send the block, then sync with a ping before asserting on the debug.log. Even if this patch doesn't fix the issue, it is good cleanup: There is no reason to not wait for the blocks to be requested, since in all these cases the header gives no indication that the block is consensus invalid. So this patch makes the test also a bit stricter and more useful. Unrelated to this, I also include a fix that makes the tests pass on latest CentOS. Tree-SHA512: c7abee3b7dc790a8af6c289159a7751bd962f6fa16c1537e7e21a0a0ef05b9596d1f4eb75319614603c05cb803e021314fa3596508ba443edd03046b25527e0f
2 parents c51e151 + fa21568 commit 5d605b2

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

test/functional/feature_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ def run_test(self):
824824
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0)))
825825
b64a = self.update_block("64a", [tx])
826826
assert_equal(len(b64a.serialize()), MAX_BLOCK_BASE_SIZE + 8)
827-
self.sync_blocks([b64a], success=False, reject_reason='non-canonical ReadCompactSize():')
827+
self.sync_blocks([b64a], success=False, reject_reason='non-canonical ReadCompactSize()')
828828

829829
# bitcoind doesn't disconnect us for sending a bloated block, but if we subsequently
830830
# resend the header message, it won't send us the getdata message again. Just

test/functional/p2p_invalid_block.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def run_test(self):
7777
block2.vtx.append(tx2)
7878
assert_equal(block2.hashMerkleRoot, block2.calc_merkle_root())
7979
assert_equal(orig_hash, block2.rehash())
80-
assert(block2_orig.vtx != block2.vtx)
80+
assert block2_orig.vtx != block2.vtx
8181

82-
node.p2p.send_blocks_and_test([block2], node, success=False, request_block=False, reject_reason='bad-txns-duplicate')
82+
node.p2p.send_blocks_and_test([block2], node, success=False, reject_reason='bad-txns-duplicate')
8383

8484
# Check transactions for duplicate inputs
8585
self.log.info("Test duplicate input block.")
@@ -89,7 +89,7 @@ def run_test(self):
8989
block2_orig.hashMerkleRoot = block2_orig.calc_merkle_root()
9090
block2_orig.rehash()
9191
block2_orig.solve()
92-
node.p2p.send_blocks_and_test([block2_orig], node, success=False, request_block=False, reject_reason='bad-txns-inputs-duplicate')
92+
node.p2p.send_blocks_and_test([block2_orig], node, success=False, reject_reason='bad-txns-inputs-duplicate')
9393

9494
self.log.info("Test very broken block.")
9595

@@ -102,7 +102,8 @@ def run_test(self):
102102
block3.rehash()
103103
block3.solve()
104104

105-
node.p2p.send_blocks_and_test([block3], node, success=False, request_block=False, reject_reason='bad-cb-amount')
105+
node.p2p.send_blocks_and_test([block3], node, success=False, reject_reason='bad-cb-amount')
106+
106107

107108
if __name__ == '__main__':
108109
InvalidBlockRequestTest().main()

0 commit comments

Comments
 (0)