Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-finalize-block.py
Show All 38 Lines | def run_test(self): | ||||
assert_equal(node.getbestblockhash(), tip) | assert_equal(node.getbestblockhash(), tip) | ||||
alt_node = self.nodes[1] | alt_node = self.nodes[1] | ||||
connect_nodes_bi(self.nodes, 0, 1) | connect_nodes_bi(self.nodes, 0, 1) | ||||
sync_blocks(self.nodes[0:2]) | sync_blocks(self.nodes[0:2]) | ||||
alt_node.invalidateblock(tip) | alt_node.invalidateblock(tip) | ||||
# We will use this later to check auto-finalization during a reorg | # We will use this later to check auto-finalization during a reorg | ||||
auto_finalized_tip = alt_node.getbestblockhash() | fork_block = alt_node.getbestblockhash() | ||||
# Node 0 should not accept the whole alt_node's chain due to tip being finalized, | # Node 0 should not accept the whole alt_node's chain due to tip being finalized, | ||||
# even though it is longer. | # even though it is longer. | ||||
# Headers would not be accepted if previousblock is invalid: | # Headers would not be accepted if previousblock is invalid: | ||||
# - First block from alt node has same height than node tip, but is on a minority chain. Its | # - First block from alt node has same height than node tip, but is on a minority chain. Its | ||||
# status is "valid-headers" | # status is "valid-headers" | ||||
# - Second block from alt node has height > node tip height, will be marked as invalid because | # - Second block from alt node has height > node tip height, will be marked as invalid because | ||||
# node tip is finalized | # node tip is finalized | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# On alt_node: | # On alt_node: | ||||
# >(210)->(211)-> // ->(218 tip) | # >(210)->(211)-> // ->(218 tip) | ||||
# / | # / | ||||
# (200)->(201)-> // ->(208 auto-finalized)->(209)->(210 invalid) | # (200)->(201)-> // ->(208 auto-finalized)->(209)->(210 invalid) | ||||
# | # | ||||
# On node: | # On node: | ||||
# >(210 valid-headers)->(211 invalid)->(212 to 218 dropped) | # >(210 valid-headers)->(211 invalid)->(212 to 218 dropped) | ||||
# / | # / | ||||
# (200 finalized)->(201)-> // ->(209)->(210 tip) | # (200)->(201)-> // ->(209 finalized)->(210 tip) | ||||
node.invalidateblock(tip) | node.invalidateblock(tip) | ||||
node.reconsiderblock(tip) | node.reconsiderblock(tip) | ||||
finalized_block = node.getblockhash( | |||||
int(node.getblockheader(tip)['height']) - AUTO_FINALIZATION_DEPTH) | |||||
assert_equal(node.getbestblockhash(), tip) | assert_equal(node.getbestblockhash(), tip) | ||||
assert_equal( | assert_equal(node.getfinalizedblockhash(), fork_block) | ||||
node.getfinalizedblockhash(), | |||||
finalized_block) | assert_equal(alt_node.getfinalizedblockhash(), node.getblockheader( | ||||
node.getfinalizedblockhash())['previousblockhash']) | |||||
# The node will now accept that chain as the finalized block moved back. | # The node will now accept that chain as the finalized block moved back. | ||||
# Generate a new block on alt_node to trigger getheader from node | # Generate a new block on alt_node to trigger getheader from node | ||||
# Previous 212-218 height blocks have been droped because their previous was invalid | # Previous 212-218 height blocks have been droped because their previous was invalid | ||||
# | # | ||||
# Expected state: | # Expected state: | ||||
# | # | ||||
# On alt_node: | # On alt_node: | ||||
# >(210)->(211)-> // ->(218)->(219 tip) | # >(210)->(211)-> // ->(218)->(219 tip) | ||||
# / | # / | ||||
# (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) | # (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) | ||||
# | # | ||||
# On node: | # On node: | ||||
# >(210)->(211)->(212)-> // ->(218)->(219 tip) | # >(210)->(211)->(212)-> // ->(218)->(219 tip) | ||||
# / | # / | ||||
# (200)->(201)-> // ->(209 finalized)->(210) | # (200)->(201)-> // ->(209 finalized)->(210) | ||||
node.reconsiderblock(invalid_block) | node.reconsiderblock(invalid_block) | ||||
alt_node.generate(1) | alt_node.generate(1) | ||||
sync_blocks(self.nodes[0:2]) | sync_blocks(self.nodes[0:2]) | ||||
assert_equal(node.getbestblockhash(), alt_node.getbestblockhash()) | assert_equal(node.getbestblockhash(), alt_node.getbestblockhash()) | ||||
assert_equal(node.getfinalizedblockhash(), auto_finalized_tip) | assert_equal(node.getfinalizedblockhash(), fork_block) | ||||
assert_equal(alt_node.getfinalizedblockhash(), fork_block) | |||||
self.log.info("Trigger reorg via block finalization...") | self.log.info("Trigger reorg via block finalization...") | ||||
# Finalize node tip to reorg | # Finalize node tip to reorg | ||||
# | # | ||||
# Expected state: | # Expected state: | ||||
# | # | ||||
# On alt_node: | # On alt_node: | ||||
# >(210)->(211)-> // ->(218)->(219 tip) | # >(210)->(211)-> // ->(218)->(219 tip) | ||||
# / | # / | ||||
# (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) | # (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) | ||||
# | # | ||||
# On node: | # On node: | ||||
# >(210 invalid)-> // ->(219 invalid) | # >(210 invalid)-> // ->(219 invalid) | ||||
# / | # / | ||||
# (200 finalized)->(201)-> // ->(209)->(210 tip) | # (200)->(201)-> // ->(209)->(210 finalized, tip) | ||||
node.finalizeblock(tip) | node.finalizeblock(tip) | ||||
assert_equal(node.getfinalizedblockhash(), | assert_equal(node.getfinalizedblockhash(), tip) | ||||
finalized_block) | |||||
self.log.info("Try to finalize a block on a competiting fork...") | self.log.info("Try to finalize a block on a competiting fork...") | ||||
assert_raises_rpc_error(-20, RPC_FINALIZE_INVALID_BLOCK_ERROR, | assert_raises_rpc_error(-20, RPC_FINALIZE_INVALID_BLOCK_ERROR, | ||||
node.finalizeblock, alt_node.getbestblockhash()) | node.finalizeblock, alt_node.getbestblockhash()) | ||||
assert node.getfinalizedblockhash() != alt_node.getbestblockhash(), \ | assert node.getfinalizedblockhash() != alt_node.getbestblockhash(), \ | ||||
"Finalized block should not be alt_node's tip!" | "Finalized block should not be alt_node's tip!" | ||||
assert_equal(node.getfinalizedblockhash(), finalized_block) | |||||
deadalnix: Maybe change this into
assert_equal(node.getfinalizedblockhash(), tip)
instead of… | |||||
FabienAuthorUnsubmitted Done Inline ActionsIt has been removed because it is a duplicate, already tested at line 162 (164 in new version) Fabien: It has been removed because it is a duplicate, already tested at line 162 (164 in new version) | |||||
self.log.info( | self.log.info( | ||||
"Make sure reconsidering block move the finalization point...") | "Make sure reconsidering block move the finalization point...") | ||||
# Reconsidering alt_node tip will move finalized block on node | # Reconsidering alt_node tip will move finalized block on node | ||||
# | # | ||||
# Expected state: | # Expected state: | ||||
# | # | ||||
# On alt_node: | # On alt_node: | ||||
# >(210)->(211)-> // ->(218)->(219 tip) | # >(210)->(211)-> // ->(218)->(219 tip) | ||||
# / | # / | ||||
# (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) | # (200)->(201)-> // ->(209 auto-finalized)->(210 invalid) | ||||
# | # | ||||
# On node: | # On node: | ||||
# >(210)-> // ->(219 tip) | # >(210)-> // ->(219 tip) | ||||
# / | # / | ||||
# (200)->(201)-> // ->(209 auto-finalized)->(210) | # (200)->(201)-> // ->(209 finalized)->(210) | ||||
node.reconsiderblock(alt_node.getbestblockhash()) | node.reconsiderblock(alt_node.getbestblockhash()) | ||||
assert_equal(node.getbestblockhash(), alt_node.getbestblockhash()) | assert_equal(node.getbestblockhash(), alt_node.getbestblockhash()) | ||||
assert_equal(node.getfinalizedblockhash(), fork_block) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
FinalizeBlockTest().main() | FinalizeBlockTest().main() |
Maybe change this into
instead of removing it.