Skip to content

Commit

Permalink
test: remove assert_blockchain_height
Browse files Browse the repository at this point in the history
Summary:
> This simplifies the code and solves intermittent timeouts caused by commit rABC0c0123b0aa87

Note: I have not yet seen an intermittent timeout happen, but the conditions for this to happen exist after D10896

This is a backport of [[bitcoin/bitcoin#21117 | core#21117]]

Test Plan: `ninja check-functional`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10950
  • Loading branch information
MarcoFalke authored and PiRK committed Feb 1, 2022
1 parent 5c70b37 commit 23e2e06
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions test/functional/feature_assumevalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
block 200. node2 will reject block 102 since it's assumed valid, but it
isn't buried by at least two weeks' work.
"""
import time

from test_framework.blocktools import create_block, create_coinbase
from test_framework.key import ECKey
Expand Down Expand Up @@ -81,25 +80,6 @@ def send_blocks_until_disconnected(self, p2p_conn):
assert not p2p_conn.is_connected
break

def assert_blockchain_height(self, node, height):
"""Wait until the blockchain is no longer advancing and verify it's reached the expected height."""
last_height = node.getblock(node.getbestblockhash())['height']
timeout = 10
while True:
time.sleep(0.25)
current_height = node.getblock(node.getbestblockhash())['height']
if current_height != last_height:
last_height = current_height
if timeout < 0:
assert False, "blockchain too short after timeout: {}".format(
current_height)
timeout -= 0.25
continue
elif current_height > height:
assert False, "blockchain too long: {}".format(current_height)
elif current_height == height:
break

def run_test(self):
p2p0 = self.nodes[0].add_p2p_connection(BaseNode())

Expand Down Expand Up @@ -189,7 +169,8 @@ def run_test(self):

# Send blocks to node0. Block 102 will be rejected.
self.send_blocks_until_disconnected(p2p0)
self.assert_blockchain_height(self.nodes[0], 101)
self.wait_until(lambda: self.nodes[0].getblockcount() >= 101)
assert_equal(self.nodes[0].getblockcount(), 101)

# Send all blocks to node1. All blocks will be accepted.
for i in range(2202):
Expand All @@ -202,7 +183,8 @@ def run_test(self):

# Send blocks to node2. Block 102 will be rejected.
self.send_blocks_until_disconnected(p2p2)
self.assert_blockchain_height(self.nodes[2], 101)
self.wait_until(lambda: self.nodes[2].getblockcount() >= 101)
assert_equal(self.nodes[2].getblockcount(), 101)


if __name__ == '__main__':
Expand Down

0 comments on commit 23e2e06

Please sign in to comment.