test_on_block_outside_safe_slots_and_multiple_better_justified and test_on_block_outside_safe_slots_but_finality in test/phase0/unittests/fork_choice/test_on_block.py force the processing of inconsistent blocks.
Problem:
Context:
# Mock justified block in store
just_block = build_empty_block_for_next_slot(spec, state)
# Slot is same as justified checkpoint so does not trigger an override in the store
just_block.slot = spec.compute_start_slot_at_epoch(store.justified_checkpoint.epoch)
store.blocks[just_block.hash_tree_root()] = just_block
The inconsistency is caused when just_block.slot is being set - the new slot is earlier than just_block's parent block.
Here[1, 2] is an illustration of the problem:
just_block_parent = store.blocks[just_block.parent_root]
assert just_block_parent.slot < just_block.slot, f"just_block_parent.slot: {just_block_parent.slot}, just_block.slot: {just_block.slot}"
Both unit tests now fail with this output:
AssertionError: just_block_parent.slot: 16, just_block.slot: 0
This is fine in the current spec, because only the block's slot value matters for these unit tests. However, it causes a problem for a planned fork choice upgrade where constructing the block tree becomes relevant for this unit test.
Suggested Fix:
Create consistent block hierarchy for just_block.
test_on_block_outside_safe_slots_and_multiple_better_justifiedandtest_on_block_outside_safe_slots_but_finalityintest/phase0/unittests/fork_choice/test_on_block.pyforce the processing of inconsistent blocks.Problem:
Context:
The inconsistency is caused when
just_block.slotis being set - the new slot is earlier thanjust_block's parent block.Here[1, 2] is an illustration of the problem:
Both unit tests now fail with this output:
This is fine in the current spec, because only the block's slot value matters for these unit tests. However, it causes a problem for a planned fork choice upgrade where constructing the block tree becomes relevant for this unit test.
Suggested Fix:
Create consistent block hierarchy for
just_block.