Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-parkedchain.py
Show First 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
def check_reorg_protection(depth, extra_blocks): | def check_reorg_protection(depth, extra_blocks): | ||||
self.log.info( | self.log.info( | ||||
"Test deep reorg parking, {} block deep".format(depth)) | "Test deep reorg parking, {} block deep".format(depth)) | ||||
# Invalidate the tip on node 0, so it doesn't follow node 1. | # Invalidate the tip on node 0, so it doesn't follow node 1. | ||||
node.invalidateblock(node.getbestblockhash()) | node.invalidateblock(node.getbestblockhash()) | ||||
# Mine block to create a fork of proper depth | # Mine block to create a fork of proper depth | ||||
parking_node.generate(depth - 1) | parking_node.generatetoaddress( | ||||
node.generate(depth) | nblocks=depth - 1, | ||||
address=parking_node.getnewaddress(label='coinbase')) | |||||
node.generatetoaddress( | |||||
nblocks=depth, | |||||
address=node.getnewaddress(label='coinbase')) | |||||
# extra block should now find themselves parked | # extra block should now find themselves parked | ||||
for i in range(extra_blocks): | for i in range(extra_blocks): | ||||
node.generate(1) | node.generate(1) | ||||
wait_for_parked_block(node.getbestblockhash()) | wait_for_parked_block(node.getbestblockhash()) | ||||
# If we mine one more block, the node reorgs. | # If we mine one more block, the node reorgs. | ||||
node.generate(1) | node.generate(1) | ||||
wait_until(lambda: parking_node.getbestblockhash() | wait_until(lambda: parking_node.getbestblockhash() | ||||
Show All 13 Lines | def run_test(self): | ||||
self.log.info( | self.log.info( | ||||
"Accepting many blocks at once (possibly out of order) should not park if there is no reorg.") | "Accepting many blocks at once (possibly out of order) should not park if there is no reorg.") | ||||
# rewind one block to make a reorg that is shallow. | # rewind one block to make a reorg that is shallow. | ||||
node.invalidateblock(parking_node.getbestblockhash()) | node.invalidateblock(parking_node.getbestblockhash()) | ||||
# generate a ton of blocks at once. | # generate a ton of blocks at once. | ||||
try: | try: | ||||
with parking_node.assert_debug_log(["Park block"]): | with parking_node.assert_debug_log(["Park block"]): | ||||
node.generate(20) | node.generatetoaddress( | ||||
nblocks=20, | |||||
address=node.getnewaddress(label='coinbase')) | |||||
wait_until(lambda: parking_node.getbestblockhash() == | wait_until(lambda: parking_node.getbestblockhash() == | ||||
node.getbestblockhash()) | node.getbestblockhash()) | ||||
except AssertionError as exc: | except AssertionError as exc: | ||||
# good, we want an absence of "Park block" messages | # good, we want an absence of "Park block" messages | ||||
assert "does not partially match log" in exc.args[0] | assert "does not partially match log" in exc.args[0] | ||||
else: | else: | ||||
raise AssertionError("Parked block when there was no deep reorg") | raise AssertionError("Parked block when there was no deep reorg") | ||||
self.log.info("Test that unparking works when -parkdeepreorg=0") | self.log.info("Test that unparking works when -parkdeepreorg=0") | ||||
# Set up parking node height = fork + 4, node height = fork + 5 | # Set up parking node height = fork + 4, node height = fork + 5 | ||||
node.invalidateblock(node.getbestblockhash()) | node.invalidateblock(node.getbestblockhash()) | ||||
parking_node.generate(3) | parking_node.generate(3) | ||||
node.generate(5) | node.generatetoaddress( | ||||
nblocks=5, | |||||
address=node.getnewaddress(label='coinbase')) | |||||
wait_for_parked_block(node.getbestblockhash()) | wait_for_parked_block(node.getbestblockhash()) | ||||
# Restart the parking node without parkdeepreorg. | # Restart the parking node without parkdeepreorg. | ||||
self.restart_node(1, ["-parkdeepreorg=0"]) | self.restart_node(1, ["-parkdeepreorg=0"]) | ||||
parking_node = self.nodes[1] | parking_node = self.nodes[1] | ||||
connect_nodes_bi(node, parking_node) | connect_nodes_bi(node, parking_node) | ||||
# The other chain should still be marked 'parked'. | # The other chain should still be marked 'parked'. | ||||
wait_for_parked_block(node.getbestblockhash()) | wait_for_parked_block(node.getbestblockhash()) | ||||
# Three more blocks is not enough to unpark. Even though its PoW is | # Three more blocks is not enough to unpark. Even though its PoW is | ||||
Show All 14 Lines |