From 7c023cc3cfa0a1530d63f5cb7e2b65649dcf5271 Mon Sep 17 00:00:00 2001 From: Roberto Saltini Date: Thu, 15 Jun 2023 11:07:30 +1000 Subject: [PATCH 01/10] Fork choice changes to enable confirmation rule execution via beacon APIs --- specs/phase0/fork-choice.md | 46 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/specs/phase0/fork-choice.md b/specs/phase0/fork-choice.md index be6edca643..ea8b9a57d5 100644 --- a/specs/phase0/fork-choice.md +++ b/specs/phase0/fork-choice.md @@ -16,9 +16,11 @@ - [`get_forkchoice_store`](#get_forkchoice_store) - [`get_slots_since_genesis`](#get_slots_since_genesis) - [`get_current_slot`](#get_current_slot) + - [`get_current_store_epoch`](#get_current_store_epoch) - [`compute_slots_since_epoch_start`](#compute_slots_since_epoch_start) - [`get_ancestor`](#get_ancestor) - [`get_checkpoint_block`](#get_checkpoint_block) + - [`get_proposer_score`](#get_proposer_score) - [`get_weight`](#get_weight) - [`get_voting_source`](#get_voting_source) - [`filter_block_tree`](#filter_block_tree) @@ -124,8 +126,7 @@ class Store(object): ```python def is_previous_epoch_justified(store: Store) -> bool: - current_slot = get_current_slot(store) - current_epoch = compute_epoch_at_slot(current_slot) + current_epoch = get_current_store_epoch(store) return store.justified_checkpoint.epoch + 1 == current_epoch ``` @@ -174,6 +175,13 @@ def get_current_slot(store: Store) -> Slot: return Slot(GENESIS_SLOT + get_slots_since_genesis(store)) ``` +#### `get_current_store_epoch` + +```python +def get_current_store_epoch(store: Store) -> Slot: + return compute_epoch_at_slot(get_current_slot(store)) +``` + #### `compute_slots_since_epoch_start` ```python @@ -202,6 +210,15 @@ def get_checkpoint_block(store: Store, root: Root, epoch: Epoch) -> Root: return get_ancestor(store, root, epoch_first_slot) ``` +#### `get_proposer_score` + +```python +def get_proposer_score(store: Store) -> Gwei: + justified_checkpoint_state = store.checkpoint_states[store.justified_checkpoint] + committee_weight = get_total_active_balance(justified_checkpoint_state) // SLOTS_PER_EPOCH + return (committee_weight * PROPOSER_SCORE_BOOST) // 100 +``` + #### `get_weight` ```python @@ -225,8 +242,7 @@ def get_weight(store: Store, root: Root) -> Gwei: proposer_score = Gwei(0) # Boost is applied if ``root`` is an ancestor of ``proposer_boost_root`` if get_ancestor(store, store.proposer_boost_root, store.blocks[root].slot) == root: - committee_weight = get_total_active_balance(state) // SLOTS_PER_EPOCH - proposer_score = (committee_weight * PROPOSER_SCORE_BOOST) // 100 + proposer_score = get_proposer_score(store) return attestation_score + proposer_score ``` @@ -238,7 +254,7 @@ def get_voting_source(store: Store, block_root: Root) -> Checkpoint: Compute the voting source checkpoint in event that block with root ``block_root`` is the head block """ block = store.blocks[block_root] - current_epoch = compute_epoch_at_slot(get_current_slot(store)) + current_epoch = get_current_store_epoch(store) block_epoch = compute_epoch_at_slot(block.slot) if current_epoch > block_epoch: # The block is from a prior epoch, the voting source will be pulled-up @@ -271,23 +287,17 @@ def filter_block_tree(store: Store, block_root: Root, blocks: Dict[Root, BeaconB return True return False - current_epoch = compute_epoch_at_slot(get_current_slot(store)) + current_epoch = get_current_store_epoch(store) voting_source = get_voting_source(store, block_root) - # The voting source should be at the same height as the store's justified checkpoint + # The voting source should be either at the same height as the store's justified checkpoint or + # not more than two epochs ago correct_justified = ( store.justified_checkpoint.epoch == GENESIS_EPOCH or voting_source.epoch == store.justified_checkpoint.epoch + or voting_source.epoch + 2 >= current_epoch ) - # If the previous epoch is justified, the block should be pulled-up. In this case, check that unrealized - # justification is higher than the store and that the voting source is not more than two epochs ago - if not correct_justified and is_previous_epoch_justified(store): - correct_justified = ( - store.unrealized_justifications[block_root].epoch >= store.justified_checkpoint.epoch and - voting_source.epoch + 2 >= current_epoch - ) - finalized_checkpoint_block = get_checkpoint_block( store, block_root, @@ -391,7 +401,7 @@ def compute_pulled_up_tip(store: Store, block_root: Root) -> None: # If the block is from a prior epoch, apply the realized values block_epoch = compute_epoch_at_slot(store.blocks[block_root].slot) - current_epoch = compute_epoch_at_slot(get_current_slot(store)) + current_epoch = get_current_store_epoch(store) if block_epoch < current_epoch: update_checkpoints(store, state.current_justified_checkpoint, state.finalized_checkpoint) ``` @@ -428,7 +438,7 @@ def validate_target_epoch_against_current_time(store: Store, attestation: Attest target = attestation.data.target # Attestations must be from the current or previous epoch - current_epoch = compute_epoch_at_slot(get_current_slot(store)) + current_epoch = get_current_store_epoch(store) # Use GENESIS_EPOCH for previous when genesis to avoid underflow previous_epoch = current_epoch - 1 if current_epoch > GENESIS_EPOCH else GENESIS_EPOCH # If attestation target is from a future epoch, delay consideration until the epoch arrives @@ -525,7 +535,7 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None: block.parent_root, store.finalized_checkpoint.epoch, ) - assert store.finalized_checkpoint.root == finalized_checkpoint_block + assert store.finalized_checkpoint.root == finalized_checkpoint_block # Check the block is valid and compute the post-state state = pre_state.copy() From ca1e8161d3382c33fc672b3ccd06b31002541088 Mon Sep 17 00:00:00 2001 From: Roberto Saltini Date: Sat, 17 Jun 2023 22:05:49 +1000 Subject: [PATCH 02/10] Try fix tests --- .../core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index afff8d4f46..658f7eb8e8 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -382,9 +382,10 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif # to next epoch next_epoch(spec, state) + next_epoch(spec, state) current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) - assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 5 + assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 6 if enough_ffg: # reorg From 5e3c0107ef2404e5564d00f003fbd1486324a1b7 Mon Sep 17 00:00:00 2001 From: Roberto Saltini <38655434+saltiniroberto@users.noreply.github.com> Date: Sun, 18 Jun 2023 19:07:35 +1000 Subject: [PATCH 03/10] Review change Co-authored-by: Hsiao-Wei Wang --- specs/phase0/fork-choice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/phase0/fork-choice.md b/specs/phase0/fork-choice.md index ea8b9a57d5..b541f7022d 100644 --- a/specs/phase0/fork-choice.md +++ b/specs/phase0/fork-choice.md @@ -178,7 +178,7 @@ def get_current_slot(store: Store) -> Slot: #### `get_current_store_epoch` ```python -def get_current_store_epoch(store: Store) -> Slot: +def get_current_store_epoch(store: Store) -> Epoch: return compute_epoch_at_slot(get_current_slot(store)) ``` From 752f2a0476d4977fb1ec511c4fbdab9667d11371 Mon Sep 17 00:00:00 2001 From: Aditya Asgaonkar Date: Wed, 19 Jul 2023 10:37:15 -0700 Subject: [PATCH 04/10] update test checks --- tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index 658f7eb8e8..6324b5e563 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -382,6 +382,7 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif # to next epoch next_epoch(spec, state) + assert spec.get_head(store) == signed_block_y.message.hash_tree_root() next_epoch(spec, state) current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) From ee32adb5a4885dd49d9ee735c2562e1ab9d42395 Mon Sep 17 00:00:00 2001 From: Aditya Asgaonkar Date: Mon, 24 Jul 2023 12:42:29 -0700 Subject: [PATCH 05/10] add test step --- tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index 6324b5e563..f0312a7ed7 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -382,6 +382,7 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif # to next epoch next_epoch(spec, state) + on_tick_and_append_step(spec, store, current_time, test_steps) assert spec.get_head(store) == signed_block_y.message.hash_tree_root() next_epoch(spec, state) current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time From 956b33c452f1bed31861631e7ca6b55d6cd7d1f1 Mon Sep 17 00:00:00 2001 From: Aditya Asgaonkar Date: Mon, 24 Jul 2023 16:43:16 -0700 Subject: [PATCH 06/10] Update tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py Co-authored-by: Mikhail Kalinin --- .../pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index f0312a7ed7..e13afdcf41 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -383,7 +383,13 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif # to next epoch next_epoch(spec, state) on_tick_and_append_step(spec, store, current_time, test_steps) - assert spec.get_head(store) == signed_block_y.message.hash_tree_root() + current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time + on_tick_and_append_step(spec, store, current_time, test_steps) + if is_justifying_previous_epoch: + assert spec.get_head(store) == signed_block_z.message.hash_tree_root() + else: + assert spec.get_head(store) == signed_block_y.message.hash_tree_root() + next_epoch(spec, state) current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) From 1bfc155e5161733a5bc0c711107bccdd5d6d56b1 Mon Sep 17 00:00:00 2001 From: Aditya Asgaonkar Date: Mon, 24 Jul 2023 16:44:06 -0700 Subject: [PATCH 07/10] update test steps & check --- .../pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index e13afdcf41..28ac05435f 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -382,14 +382,8 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif # to next epoch next_epoch(spec, state) - on_tick_and_append_step(spec, store, current_time, test_steps) current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) - if is_justifying_previous_epoch: - assert spec.get_head(store) == signed_block_z.message.hash_tree_root() - else: - assert spec.get_head(store) == signed_block_y.message.hash_tree_root() - next_epoch(spec, state) current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) From 237098bea6f52f95f849c73b215706829ffabf89 Mon Sep 17 00:00:00 2001 From: Aditya Asgaonkar Date: Tue, 25 Jul 2023 16:28:06 -0700 Subject: [PATCH 08/10] apply @mkalinin review & make asserts verbose --- .../test/phase0/fork_choice/test_reorg.py | 107 ++++++++++++++---- 1 file changed, 88 insertions(+), 19 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index 28ac05435f..4ec29508ff 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -286,34 +286,43 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif for _ in range(2): state, store, _ = yield from apply_next_epoch_with_attestations( spec, state, store, True, True, test_steps=test_steps) + if is_justifying_previous_epoch: + # build chain with head in epoch 3 and justified checkpoint in epoch 2 block_a = build_empty_block_for_next_slot(spec, state) signed_block_a = state_transition_and_sign_block(spec, state, block_a) yield from tick_and_add_block(spec, store, signed_block_a, test_steps) + assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 3 assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 2 else: - # fill one more epoch + # build chain with head in epoch 4 and justified checkpoint in epoch 3 state, store, _ = yield from apply_next_epoch_with_attestations( spec, state, store, True, True, test_steps=test_steps) signed_block_a = state_transition_with_full_block(spec, state, True, True) yield from tick_and_add_block(spec, store, signed_block_a, test_steps) + assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 4 assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 - spec.get_head(store) == signed_block_a.message.hash_tree_root() - state = store.block_states[spec.get_head(store)].copy() + state_a = state.copy() + if is_justifying_previous_epoch: + assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 3 + assert spec.compute_epoch_at_slot(state.slot) == 3 assert state.current_justified_checkpoint.epoch == 2 else: + assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 4 + assert spec.compute_epoch_at_slot(state.slot) == 4 assert state.current_justified_checkpoint.epoch == 3 - state_a = state.copy() if is_justifying_previous_epoch: - # try to find the block that can justify epoch 3 + # try to find the block that can justify epoch 3 by including only previous epoch attesations _, justifying_slot = find_next_justifying_slot(spec, state, False, True) + assert spec.compute_epoch_at_slot(justifying_slot) == 4 else: - # try to find the block that can justify epoch 4 + # try to find the block that can justify epoch 4 by including current epoch attestations _, justifying_slot = find_next_justifying_slot(spec, state, True, True) + assert spec.compute_epoch_at_slot(justifying_slot) == 4 last_slot_of_z = justifying_slot if enough_ffg else justifying_slot - 1 last_slot_of_y = justifying_slot if is_justifying_previous_epoch else last_slot_of_z - 1 @@ -324,15 +333,14 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif # build an empty chain to the slot prior epoch boundary signed_blocks_of_empty_chain = [] states_of_empty_chain = [] - for slot in range(state.slot + 1, last_slot_of_y + 1): block = build_empty_block(spec, state, slot=slot) signed_block = state_transition_and_sign_block(spec, state, block) signed_blocks_of_empty_chain.append(signed_block) states_of_empty_chain.append(state.copy()) signed_blocks_of_y.append(signed_block) - signed_block_y = signed_blocks_of_empty_chain[-1] + assert spec.compute_epoch_at_slot(signed_block_y.message.slot) == 4 # create 2/3 votes for the empty chain attestations_for_y = [] @@ -345,7 +353,6 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif state = state_a.copy() signed_block_z = None - for slot in range(state_a.slot + 1, last_slot_of_z + 1): # apply chain y, the empty chain if slot <= last_slot_of_y and len(signed_blocks_of_y) > 0: @@ -368,12 +375,21 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif if is_ready_to_justify(spec, state): break - assert spec.get_head(store) == signed_block_y.message.hash_tree_root() + assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 4 + assert spec.compute_epoch_at_slot(signed_block_y.message.slot) == 4 + assert spec.compute_epoch_at_slot(signed_block_z.message.slot) == 4 + # y is not filtered out & wins the LMD competition, so y should be the head + y_voting_source_epoch = spec.get_voting_source(store, signed_block_y.message.hash_tree_root()).epoch if is_justifying_previous_epoch: assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 2 + assert y_voting_source_epoch == 2 + assert y_voting_source_epoch == store.justified_checkpoint.epoch else: assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + assert y_voting_source_epoch == 3 + assert y_voting_source_epoch == store.justified_checkpoint.epoch + assert spec.get_head(store) == signed_block_y.message.hash_tree_root() if enough_ffg: assert is_ready_to_justify(spec, state) @@ -384,22 +400,75 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif next_epoch(spec, state) current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) + assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 5 + + y_voting_source_epoch = spec.get_voting_source(store, signed_block_y.message.hash_tree_root()).epoch + if is_justifying_previous_epoch: + # y is filtered out & so z should be the head + assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + assert y_voting_source_epoch == 2 + assert y_voting_source_epoch != store.justified_checkpoint.epoch + assert not(y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) + assert spec.get_head(store) == signed_block_z.message.hash_tree_root() + else: + if enough_ffg: + # y is not filtered out & wins the LMD competition, so y should be the head + assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4 + assert y_voting_source_epoch == 3 + assert y_voting_source_epoch != store.justified_checkpoint.epoch + assert y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store)) + assert spec.get_head(store) == signed_block_y.message.hash_tree_root() + else: + # y is not filtered out & wins the LMD competition, so y should be the head + assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + assert y_voting_source_epoch == 3 + assert y_voting_source_epoch == store.justified_checkpoint.epoch + assert spec.get_head(store) == signed_block_y.message.hash_tree_root() + + # to next epoch next_epoch(spec, state) current_time = state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) assert spec.compute_epoch_at_slot(spec.get_current_slot(store)) == 6 - if enough_ffg: - # reorg + y_voting_source_epoch = spec.get_voting_source(store, signed_block_y.message.hash_tree_root()).epoch + if is_justifying_previous_epoch: + # y is filtered out & so z should be the head + assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + assert y_voting_source_epoch == 2 + assert y_voting_source_epoch != store.justified_checkpoint.epoch + assert not(y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) assert spec.get_head(store) == signed_block_z.message.hash_tree_root() - if is_justifying_previous_epoch: - assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 - else: - assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4 else: - # no reorg - assert spec.get_head(store) == signed_block_y.message.hash_tree_root() - assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + if enough_ffg: + # y is filtered out & so z should be the head + assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4 + assert y_voting_source_epoch == 3 + assert y_voting_source_epoch != store.justified_checkpoint.epoch + assert not(y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) + assert spec.get_head(store) == signed_block_z.message.hash_tree_root() + else: + # y is not filtered out & wins the LMD competition, so y should be the head + assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + assert y_voting_source_epoch == 3 + assert y_voting_source_epoch == store.justified_checkpoint.epoch + assert spec.get_head(store) == signed_block_y.message.hash_tree_root() + + # if enough_ffg: + # if is_justifying_previous_epoch: + # # y is filtered out & so z should be the head + # assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 + # assert y_voting_source_epoch == 2 + # assert y_voting_source_epoch != store.justified_checkpoint.epoch + # assert not(y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) + # assert spec.get_head(store) == signed_block_z.message.hash_tree_root() + # else: + # assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4 + # assert spec.get_head(store) == signed_block_z.message.hash_tree_root() + # else: + # # no reorg + # assert spec.get_head(store) == signed_block_y.message.hash_tree_root() + # assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 yield 'steps', test_steps From 972d69907e3f0e11f11cf18c44c1fab1df62c901 Mon Sep 17 00:00:00 2001 From: Roberto Saltini Date: Wed, 26 Jul 2023 11:08:47 +1000 Subject: [PATCH 09/10] Remove commented out lines --- .../test/phase0/fork_choice/test_reorg.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index 4ec29508ff..879fbab54f 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -454,22 +454,6 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif assert y_voting_source_epoch == store.justified_checkpoint.epoch assert spec.get_head(store) == signed_block_y.message.hash_tree_root() - # if enough_ffg: - # if is_justifying_previous_epoch: - # # y is filtered out & so z should be the head - # assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 - # assert y_voting_source_epoch == 2 - # assert y_voting_source_epoch != store.justified_checkpoint.epoch - # assert not(y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) - # assert spec.get_head(store) == signed_block_z.message.hash_tree_root() - # else: - # assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4 - # assert spec.get_head(store) == signed_block_z.message.hash_tree_root() - # else: - # # no reorg - # assert spec.get_head(store) == signed_block_y.message.hash_tree_root() - # assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 - yield 'steps', test_steps From a4f9ed91ca43bc48d8ed034374cf29396ec0cf94 Mon Sep 17 00:00:00 2001 From: Roberto Saltini Date: Wed, 26 Jul 2023 11:10:18 +1000 Subject: [PATCH 10/10] Make linter happy --- .../pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index 879fbab54f..ca9b483f88 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -408,7 +408,7 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 assert y_voting_source_epoch == 2 assert y_voting_source_epoch != store.justified_checkpoint.epoch - assert not(y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) + assert not (y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) assert spec.get_head(store) == signed_block_z.message.hash_tree_root() else: if enough_ffg: @@ -437,7 +437,7 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 3 assert y_voting_source_epoch == 2 assert y_voting_source_epoch != store.justified_checkpoint.epoch - assert not(y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) + assert not (y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) assert spec.get_head(store) == signed_block_z.message.hash_tree_root() else: if enough_ffg: @@ -445,7 +445,7 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif assert state.current_justified_checkpoint.epoch == store.justified_checkpoint.epoch == 4 assert y_voting_source_epoch == 3 assert y_voting_source_epoch != store.justified_checkpoint.epoch - assert not(y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) + assert not (y_voting_source_epoch + 2 >= spec.compute_epoch_at_slot(spec.get_current_slot(store))) assert spec.get_head(store) == signed_block_z.message.hash_tree_root() else: # y is not filtered out & wins the LMD competition, so y should be the head