From 3d853b0ec9f641470c8bbbde48d8d9f9da884e58 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 16 Nov 2023 17:25:54 +0300 Subject: [PATCH] Add `assert time >= store.time` to `on_tick` --- specs/phase0/fork-choice.md | 3 +++ tests/core/pyspec/eth2spec/test/helpers/fork_choice.py | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/specs/phase0/fork-choice.md b/specs/phase0/fork-choice.md index 6a5437115..78d3eca02 100644 --- a/specs/phase0/fork-choice.md +++ b/specs/phase0/fork-choice.md @@ -623,6 +623,9 @@ def update_latest_messages(store: Store, attesting_indices: Sequence[ValidatorIn ```python def on_tick(store: Store, time: uint64) -> None: + # Precondition + assert time >= store.time + # If the ``store.time`` falls behind, while loop catches up slot by slot # to ensure that every previous slot is processed with ``on_tick_per_slot`` tick_slot = (time - store.genesis_time) // SECONDS_PER_SLOT diff --git a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py index ef80a3ab6..bc40c1f6d 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py +++ b/tests/core/pyspec/eth2spec/test/helpers/fork_choice.py @@ -144,9 +144,10 @@ def get_blobs_file_name(blobs=None, blobs_root=None): def on_tick_and_append_step(spec, store, time, test_steps): - spec.on_tick(store, time) - test_steps.append({'tick': int(time)}) - output_store_checks(spec, store, test_steps) + if store.time < time: + spec.on_tick(store, time) + test_steps.append({'tick': int(time)}) + output_store_checks(spec, store, test_steps) def run_on_block(spec, store, signed_block, valid=True):