Skip to content

Commit 3727a75

Browse files
authored
Merge pull request #3585 from ethereum/historical-roots-fork-transition
Add transition test case of non-empty pre-state `historical_roots`
2 parents f6d214d + c9c43e8 commit 3727a75

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

specs/capella/beacon-chain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def is_partially_withdrawable_validator(validator: Validator, balance: Gwei) ->
294294

295295
### Epoch processing
296296

297-
*Note*: The function `process_historical_summaries_update` replaces `process_historical_roots_update` in Bellatrix.
297+
*Note*: The function `process_historical_summaries_update` replaces `process_historical_roots_update` in Capella.
298298

299299
```python
300300
def process_epoch(state: BeaconState) -> None:

tests/core/pyspec/eth2spec/test/altair/transition/test_transition.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,37 @@ def test_transition_with_no_attestations_until_after_fork(state, fork_epoch, spe
418418

419419
yield "blocks", blocks
420420
yield "post", state
421+
422+
423+
@with_fork_metas([ForkMeta(pre_fork_name=pre, post_fork_name=post, fork_epoch=2) for pre, post in ALL_PRE_POST_FORKS])
424+
def test_non_empty_historical_roots(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
425+
"""
426+
Test with non-empty pre-state `state.historical_roots`.
427+
428+
Since Capella froze `historical_roots`, Capella spec doesn't invoke `process_historical_roots_update` anymore.
429+
Therefore, we need to fill in `historical_roots` with non-empty value.
430+
"""
431+
# fill in historical_roots with non-empty values
432+
pre_historical_roots = [b'\x56' * 32]
433+
state.historical_roots = pre_historical_roots
434+
435+
transition_until_fork(spec, state, fork_epoch)
436+
# check pre state
437+
assert spec.get_current_epoch(state) < fork_epoch
438+
assert len(state.historical_roots) > 0
439+
440+
yield "pre", state
441+
442+
# irregular state transition to handle fork:
443+
blocks = []
444+
state, block = do_fork(state, spec, post_spec, fork_epoch)
445+
blocks.append(post_tag(block))
446+
447+
# continue regular state transition with new spec into next epoch
448+
transition_to_next_epoch_and_append_blocks(post_spec, state, post_tag, blocks, only_last_block=True)
449+
450+
yield "blocks", blocks
451+
yield "post", state
452+
453+
assert len(state.historical_roots) > 0
454+
assert state.historical_roots == pre_historical_roots

tests/formats/transition/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Clients should assume forks happen sequentially in the following manner:
99
0. `phase0`
1010
1. `altair`
1111
2. `bellatrix`
12+
3. `capella`
13+
4. `deneb`
1214

1315
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.
1416

0 commit comments

Comments
 (0)