diff --git a/test/functional/abc-invalid-chains.py b/test/functional/abc-invalid-chains.py --- a/test/functional/abc-invalid-chains.py +++ b/test/functional/abc-invalid-chains.py @@ -80,11 +80,11 @@ # Mining on top of blocks 1 or 2 is rejected tip(1) node.p2p.send_blocks_and_test( - [block(11)], node, success=False, reject_reason='bad-prevblk', request_block=False) + [block(11)], node, success=False, force_send=True, reject_reason='bad-prevblk') tip(2) node.p2p.send_blocks_and_test( - [block(21)], node, success=False, reject_reason='bad-prevblk', request_block=False) + [block(21)], node, success=False, force_send=True, reject_reason='bad-prevblk') # Reconsider block 2 to remove invalid status from *both* 1 and 2 # The goal is to test that block 1 is not retaining any internal state @@ -118,7 +118,7 @@ # Mining on the block 2 chain should be rejected tip(24) node.p2p.send_blocks_and_test( - [block(25)], node, success=False, reject_reason='bad-prevblk', request_block=False) + [block(25)], node, success=False, force_send=True, reject_reason='bad-prevblk') # Continued mining on the block 1 chain is still ok tip(13) @@ -128,7 +128,7 @@ # which is now invalid, should also be rejected. tip(221) node.p2p.send_blocks_and_test( - [block(222)], node, success=False, reject_reason='bad-prevblk', request_block=False) + [block(222)], node, success=False, force_send=True, reject_reason='bad-prevblk') self.log.info( "Make sure that reconsidering a block behaves correctly when cousin chains (neither ancestors nor descendants) become available as a result") diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -446,14 +446,19 @@ while b47.sha256 < target: b47.nNonce += 1 b47.rehash() - self.send_blocks([b47], False, request_block=False) + self.send_blocks( + [b47], + False, + force_send=True, + reject_reason='high-hash') self.log.info("Reject a block with a timestamp >2 hours in the future") self.move_tip(44) b48 = self.next_block(48, solve=False) b48.nTime = int(time.time()) + 60 * 60 * 3 b48.solve() - self.send_blocks([b48], False, request_block=False) + self.send_blocks([b48], False, force_send=True, + reject_reason='time-too-new') self.log.info("Reject a block with invalid merkle hash") self.move_tip(44) @@ -468,7 +473,12 @@ b50 = self.next_block(50) b50.nBits = b50.nBits - 1 b50.solve() - self.send_blocks([b50], False, request_block=False, reconnect=True) + self.send_blocks( + [b50], + False, + force_send=True, + reject_reason='bad-diffbits', + reconnect=True) self.log.info("Reject a block with two coinbase transactions") self.move_tip(44) @@ -498,7 +508,8 @@ b54 = self.next_block(54, spend=out[15]) b54.nTime = b35.nTime - 1 b54.solve() - self.send_blocks([b54], False, request_block=False) + self.send_blocks([b54], False, force_send=True, + reject_reason='time-too-old') # valid timestamp self.move_tip(53) @@ -718,7 +729,7 @@ # bitcoind doesn't disconnect us for sending a bloated block, but if we subsequently # resend the header message, it won't send us the getdata message again. Just - # disconnect and reconnect and then call sync_blocks. + # disconnect and reconnect and then call send_blocks. # TODO: improve this test to be less dependent on P2P DOS behaviour. node.disconnect_p2ps() self.reconnect_p2p() @@ -898,12 +909,12 @@ self.move_tip(77) b80 = self.next_block(80, spend=out[25]) - self.send_blocks([b80], False, request_block=False) + self.send_blocks([b80], False, force_send=True) self.save_spendable_output() b81 = self.next_block(81, spend=out[26]) # other chain is same length - self.send_blocks([b81], False, request_block=False) + self.send_blocks([b81], False, force_send=True) self.save_spendable_output() b82 = self.next_block(82, spend=out[27]) @@ -1017,7 +1028,7 @@ blocks2 = [] for i in range(89, LARGE_REORG_SIZE + 89): blocks2.append(self.next_block("alt" + str(i))) - self.send_blocks(blocks2, False, request_block=False) + self.send_blocks(blocks2, False, force_send=True) # extend alt chain to trigger re-org block = self.next_block("alt" + str(chain1_tip + 1)) @@ -1026,7 +1037,7 @@ # ... and re-org back to the first chain self.move_tip(chain1_tip) block = self.next_block(chain1_tip + 1) - self.send_blocks([block], False, request_block=False) + self.send_blocks([block], False, force_send=True) block = self.next_block(chain1_tip + 2) self.send_blocks([block], True, timeout=960) @@ -1149,12 +1160,12 @@ self.bootstrap_p2p() def send_blocks(self, blocks, success=True, reject_reason=None, - request_block=True, reconnect=False, timeout=60): + force_send=False, reconnect=False, timeout=60): """Sends blocks to test node. Syncs and verifies that tip has advanced to most recent block. Call with success = False if the tip shouldn't advance to the most recent block.""" self.nodes[0].p2p.send_blocks_and_test(blocks, self.nodes[0], success=success, - reject_reason=reject_reason, request_block=request_block, timeout=timeout, expect_disconnect=reconnect) + reject_reason=reject_reason, force_send=force_send, timeout=timeout, expect_disconnect=reconnect) if reconnect: self.reconnect_p2p() diff --git a/test/functional/test_framework/mininode.py b/test/functional/test_framework/mininode.py --- a/test/functional/test_framework/mininode.py +++ b/test/functional/test_framework/mininode.py @@ -587,15 +587,14 @@ if response is not None: self.send_message(response) - def send_blocks_and_test(self, blocks, node, *, success=True, request_block=True, - reject_reason=None, expect_disconnect=False, timeout=60): + def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False, reject_reason=None, expect_disconnect=False, timeout=60): """Send blocks to test node and test whether the tip advances. - add all blocks to our block_store - send a headers message for the final block - the on_getheaders handler will ensure that any getheaders are responded to - - if request_block is True: wait for getdata for each of the blocks. The on_getdata handler will - ensure that any getdata messages are responded to + - if force_send is False: wait for getdata for each of the blocks. The on_getdata handler will + ensure that any getdata messages are responded to. Otherwise send the full block unsolicited. - if success is True: assert that the node's tip advances to the most recent block - if success is False: assert that the node's tip doesn't advance - if reject_reason is set: assert that the correct reject message is logged""" @@ -606,9 +605,12 @@ self.last_block_hash = block.sha256 def test(): - self.send_message(msg_headers([CBlockHeader(blocks[-1])])) + if force_send: + for b in blocks: + self.send_message(msg_block(block=b)) - if request_block: + else: + self.send_message(msg_headers([CBlockHeader(blocks[-1])])) wait_until( lambda: blocks[-1].sha256 in self.getdata_requests, timeout=timeout, lock=mininode_lock)