Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-parkedchain.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2018 The Bitcoin developers | # Copyright (c) 2018 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the parckblock and unparkblock RPC calls.""" | """Test the parckblock and unparkblock RPC calls.""" | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, wait_until | from test_framework.util import assert_equal, connect_nodes_bi, wait_until | ||||
class ParkedChainTest(BitcoinTestFramework): | class ParkedChainTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-noparkdeepreorg"], ["-maxreorgdepth=-1"]] | self.extra_args = [["-noparkdeepreorg"], ["-maxreorgdepth=-1"]] | ||||
# There should only be one chaintip, which is expected_tip | # There should only be one chaintip, which is expected_tip | ||||
Show All 27 Lines | def run_test(self): | ||||
# (probably not needed, but just in case parking can have race | # (probably not needed, but just in case parking can have race | ||||
# condition like invalidateblock below) | # condition like invalidateblock below) | ||||
wait_for_tip(parking_node, parked_tip) | wait_for_tip(parking_node, parked_tip) | ||||
# Let's park the chain. | # Let's park the chain. | ||||
assert parked_tip != tip | assert parked_tip != tip | ||||
assert block_to_park != tip | assert block_to_park != tip | ||||
assert block_to_park != parked_tip | assert block_to_park != parked_tip | ||||
node.parkblock(block_to_park) | node.parkblock(block_to_park) | ||||
markblundeberg: Unfortunately all this stuff we're doing with `node` assumes that automatic unparking never… | |||||
assert_equal(node.getbestblockhash(), tip) | assert_equal(node.getbestblockhash(), tip) | ||||
# When the chain is unparked, the node reorg into its original chain. | # When the chain is unparked, the node reorg into its original chain. | ||||
node.unparkblock(parked_tip) | node.unparkblock(parked_tip) | ||||
assert_equal(node.getbestblockhash(), parked_tip) | assert_equal(node.getbestblockhash(), parked_tip) | ||||
# Parking and then unparking a block should not change its validity, | # Parking and then unparking a block should not change its validity, | ||||
# and invaliding and reconsidering a block should not change its | # and invaliding and reconsidering a block should not change its | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
check_reorg_protection(1, 0) | check_reorg_protection(1, 0) | ||||
check_reorg_protection(2, 0) | check_reorg_protection(2, 0) | ||||
check_reorg_protection(3, 1) | check_reorg_protection(3, 1) | ||||
check_reorg_protection(4, 4) | check_reorg_protection(4, 4) | ||||
check_reorg_protection(5, 5) | check_reorg_protection(5, 5) | ||||
check_reorg_protection(6, 6) | check_reorg_protection(6, 6) | ||||
check_reorg_protection(100, 100) | check_reorg_protection(100, 100) | ||||
self.log.info("Test that unparking works when -parkdeepreorg=0") | |||||
# Set up parking node height = fork + 4, node height = fork + 5 | |||||
node.invalidateblock(node.getbestblockhash()) | |||||
parking_node.generate(3) | |||||
node.generate(5) | |||||
wait_for_parked_block(node.getbestblockhash()) | |||||
# Restart the parking node without parkdeepreorg. | |||||
self.restart_node(1, ["-parkdeepreorg=0"]) | |||||
parking_node = self.nodes[1] | |||||
connect_nodes_bi(node, parking_node) | |||||
# The other chain should still be marked 'parked'. | |||||
wait_for_parked_block(node.getbestblockhash()) | |||||
# Two more blocks is not enough to unpark. Even though PoW is larger | |||||
# we are still following the delayed-unparking rules. | |||||
node.generate(2) | |||||
wait_for_parked_block(node.getbestblockhash()) | |||||
# Final block pushes over the edge, and should unpark. | |||||
node.generate(1) | |||||
wait_until(lambda: parking_node.getbestblockhash() | |||||
== node.getbestblockhash(), timeout=5) | |||||
# Do not append tests after this point without restarting node again. | |||||
# Parking node is no longer parking. | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
ParkedChainTest().main() | ParkedChainTest().main() |
Unfortunately all this stuff we're doing with node assumes that automatic unparking never happens. So the test currently fails here.