From cd3d2ce69219b80d92eec0dde8d3dec7b1be6a3c Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Fri, 12 Nov 2021 12:36:02 -0700 Subject: [PATCH] working through test issues --- specs/phase0/fork-choice.md | 14 +------------- .../pyspec/eth2spec/test/helpers/fork_choice.py | 2 ++ .../test/phase0/fork_choice/test_on_block.py | 7 +++++++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/specs/phase0/fork-choice.md b/specs/phase0/fork-choice.md index 276aa8029..e8f6eacf1 100644 --- a/specs/phase0/fork-choice.md +++ b/specs/phase0/fork-choice.md @@ -372,19 +372,7 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None: # Update finalized checkpoint if state.finalized_checkpoint.epoch > store.finalized_checkpoint.epoch: store.finalized_checkpoint = state.finalized_checkpoint - - # Potentially update justified if different from store - if store.justified_checkpoint != state.current_justified_checkpoint: - # Update justified if new justified is later than store justified - if state.current_justified_checkpoint.epoch > store.justified_checkpoint.epoch: - store.justified_checkpoint = state.current_justified_checkpoint - return - - # Update justified if store justified is not in chain with finalized checkpoint - finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) - ancestor_at_finalized_slot = get_ancestor(store, store.justified_checkpoint.root, finalized_slot) - if ancestor_at_finalized_slot != store.finalized_checkpoint.root: - store.justified_checkpoint = state.current_justified_checkpoint + store.justified_checkpoint = state.current_justified_checkpoint ``` #### `on_attestation` diff --git a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py index 7c6ac89a5..ae088fccd 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py +++ b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py @@ -166,6 +166,7 @@ def add_block(spec, raise block_root = signed_block.message.hash_tree_root() + print(encode_hex(block_root)) assert store.blocks[block_root] == signed_block.message assert store.block_states[block_root].hash_tree_root() == signed_block.message.state_root test_steps.append({ @@ -186,6 +187,7 @@ def add_block(spec, }, } }) + print(test_steps[-1]) return store.block_states[signed_block.message.hash_tree_root()] diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py index 79bf353b1..f90d1acbc 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_on_block.py @@ -658,6 +658,7 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state): """ test_steps = [] # Initialization + print("INIT") store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) yield 'anchor_state', state yield 'anchor_block', anchor_block @@ -679,12 +680,14 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state): state, store, _ = yield from apply_next_epoch_with_attestations( spec, state, store, False, True, test_steps=test_steps) + print("INIT FIN") assert state.finalized_checkpoint.epoch == store.finalized_checkpoint.epoch == 2 assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4 assert store.justified_checkpoint == state.current_justified_checkpoint # Create another chain # Forking from epoch 3 + print("FORK") all_blocks = [] slot = spec.compute_start_slot_at_epoch(3) block_root = spec.get_block_root_at_slot(state, slot) @@ -696,6 +699,7 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state): assert another_state.finalized_checkpoint.epoch == 3 assert another_state.current_justified_checkpoint.epoch == 4 + print("APPLY FORK TO FORK CHOICE") pre_store_justified_checkpoint_root = store.justified_checkpoint.root for block in all_blocks: # FIXME: Once `on_block` and `on_attestation` logic is fixed, @@ -707,6 +711,9 @@ def test_new_finalized_slot_is_justified_checkpoint_ancestor(spec, state): assert ancestor_at_finalized_slot == store.finalized_checkpoint.root assert store.finalized_checkpoint == another_state.finalized_checkpoint + # Thus should fail with the fix. Once show fail, swap to == assert store.justified_checkpoint != another_state.current_justified_checkpoint + print(store.finalized_checkpoint) + print(store.justified_checkpoint) yield 'steps', test_steps