From 4fe36dec58fab9b8652956a15268e7bc5a44af70 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 18 Jan 2024 00:10:45 +0800 Subject: [PATCH 1/2] Add transition test case of non-empty pre-state `historical_roots` --- specs/capella/beacon-chain.md | 2 +- .../test/altair/transition/test_transition.py | 34 +++++++++++++++++++ tests/formats/transition/README.md | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/specs/capella/beacon-chain.md b/specs/capella/beacon-chain.md index 0b5faf19c..b6d0f28f8 100644 --- a/specs/capella/beacon-chain.md +++ b/specs/capella/beacon-chain.md @@ -294,7 +294,7 @@ def is_partially_withdrawable_validator(validator: Validator, balance: Gwei) -> ### Epoch processing -*Note*: The function `process_historical_summaries_update` replaces `process_historical_roots_update` in Bellatrix. +*Note*: The function `process_historical_summaries_update` replaces `process_historical_roots_update` in Capella. ```python def process_epoch(state: BeaconState) -> None: diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py index dcbd8a38b..ef5bc8fbd 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py @@ -418,3 +418,37 @@ def test_transition_with_no_attestations_until_after_fork(state, fork_epoch, spe yield "blocks", blocks yield "post", state + + +@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS]) +def test_non_empty_historical_roots(state, fork_epoch, spec, post_spec, pre_tag, post_tag): + """ + Test with non-empty pre-state `state.historical_roots`. + + Since Capella froze `historical_roots`, Capealla spec doesn't invoke `process_historical_roots_update` anymore. + Therefore, we need to fill in `historical_roots` with non-empty value. + """ + # fill in historical_roots with non-empty values + pre_historical_roots = [b'\x56' * 32 for _ in range(spec.SLOTS_PER_HISTORICAL_ROOT)] + state.historical_roots = pre_historical_roots + + transition_until_fork(spec, state, fork_epoch) + # check pre state + assert spec.get_current_epoch(state) < fork_epoch + assert len(state.historical_roots) > 0 + + yield "pre", state + + # irregular state transition to handle fork: + blocks = [] + state, block = do_fork(state, spec, post_spec, fork_epoch) + blocks.append(post_tag(block)) + + # continue regular state transition with new spec into next epoch + transition_to_next_epoch_and_append_blocks(post_spec, state, post_tag, blocks, only_last_block=True) + + yield "blocks", blocks + yield "post", state + + assert len(state.historical_roots) > 0 + assert state.historical_roots == pre_historical_roots diff --git a/tests/formats/transition/README.md b/tests/formats/transition/README.md index d6efa69e4..7f89bdd61 100644 --- a/tests/formats/transition/README.md +++ b/tests/formats/transition/README.md @@ -9,6 +9,8 @@ Clients should assume forks happen sequentially in the following manner: 0. `phase0` 1. `altair` 2. `bellatrix` +3. `capella` +4. `deneb` For example, if a test case has `post_fork` of `altair`, the test consumer should assume the test begins in `phase0` and use that specification to process the initial state and any blocks up until the fork epoch. After the fork happens, the test consumer should use the specification according to the `altair` fork to process the remaining data. From c9c43e8f661c003cf4e515cf8f9b36979cda8e31 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 18 Jan 2024 13:27:34 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com> --- .../pyspec/eth2spec/test/altair/transition/test_transition.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py b/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py index ef5bc8fbd..b40142de7 100644 --- a/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py +++ b/tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py @@ -425,11 +425,11 @@ def test_non_empty_historical_roots(state, fork_epoch, spec, post_spec, pre_tag, """ Test with non-empty pre-state `state.historical_roots`. - Since Capella froze `historical_roots`, Capealla spec doesn't invoke `process_historical_roots_update` anymore. + Since Capella froze `historical_roots`, Capella spec doesn't invoke `process_historical_roots_update` anymore. Therefore, we need to fill in `historical_roots` with non-empty value. """ # fill in historical_roots with non-empty values - pre_historical_roots = [b'\x56' * 32 for _ in range(spec.SLOTS_PER_HISTORICAL_ROOT)] + pre_historical_roots = [b'\x56' * 32] state.historical_roots = pre_historical_roots transition_until_fork(spec, state, fork_epoch)