mirror of
https://github.com/ethereum/consensus-specs.git
synced 2026-02-01 16:14:58 -05:00
More altair fork tests with varied block conditions
This commit is contained in:
@@ -35,6 +35,19 @@ def _skip_slots(*slots):
|
||||
return f
|
||||
|
||||
|
||||
def _no_blocks(_):
|
||||
return False
|
||||
|
||||
|
||||
def _only_at(slot):
|
||||
"""
|
||||
Only produce a block if its slot is `slot`.
|
||||
"""
|
||||
def f(state_at_prior_slot):
|
||||
return state_at_prior_slot.slot + 1 == slot
|
||||
return f
|
||||
|
||||
|
||||
def _state_transition_across_slots(spec, state, slot_count, block_filter=_all_blocks):
|
||||
for _ in range(slot_count):
|
||||
should_make_block = block_filter(state)
|
||||
@@ -186,3 +199,45 @@ def test_transition_missing_fork_block(state, fork_epoch, spec, post_spec, pre_t
|
||||
|
||||
yield "blocks", blocks
|
||||
yield "post", state
|
||||
|
||||
|
||||
@fork_transition_test(PHASE0, ALTAIR, fork_epoch=2)
|
||||
def test_transition_only_blocks_post_fork(state, fork_epoch, spec, post_spec, pre_tag, post_tag):
|
||||
"""
|
||||
Transition from the initial `state` to the epoch after the `fork_epoch`,
|
||||
producing blocks for every slot along the way except for the first block
|
||||
of the new fork.
|
||||
"""
|
||||
yield "pre", state
|
||||
|
||||
assert spec.get_current_epoch(state) < fork_epoch
|
||||
|
||||
# regular state transition until fork:
|
||||
last_slot_of_pre_fork = fork_epoch * spec.SLOTS_PER_EPOCH - 1
|
||||
slot_count = last_slot_of_pre_fork - state.slot
|
||||
blocks = []
|
||||
blocks.extend([
|
||||
pre_tag(block) for block in
|
||||
_state_transition_across_slots(spec, state, slot_count, block_filter=_no_blocks)
|
||||
])
|
||||
|
||||
# irregular state transition to handle fork:
|
||||
state, _ = _do_altair_fork(state, spec, post_spec, fork_epoch, with_block=False)
|
||||
|
||||
# continue regular state transition with new spec into next epoch
|
||||
slot_count = post_spec.SLOTS_PER_EPOCH
|
||||
last_slot = (fork_epoch + 1) * post_spec.SLOTS_PER_EPOCH
|
||||
blocks.extend([
|
||||
post_tag(block) for block in
|
||||
_state_transition_across_slots(post_spec, state, slot_count, block_filter=_only_at(last_slot))
|
||||
])
|
||||
|
||||
assert state.slot % post_spec.SLOTS_PER_EPOCH == 0
|
||||
assert post_spec.compute_epoch_at_slot(state.slot) == fork_epoch + 1
|
||||
|
||||
slots_with_blocks = [block.message.slot for block in blocks]
|
||||
assert len(slots_with_blocks) == 1
|
||||
assert slots_with_blocks[0] == last_slot
|
||||
|
||||
yield "blocks", blocks
|
||||
yield "post", state
|
||||
|
||||
@@ -19,7 +19,7 @@ For example, if a test case has `post_fork` of `altair`, the test consumer shoul
|
||||
post_fork: string -- String name of the spec after the fork.
|
||||
fork_epoch: int -- The epoch at which the fork takes place.
|
||||
fork_block: int -- Optional. The `<index>` of the last block on the initial fork.
|
||||
blocks_count: int -- Optional. The number of blocks processed in this test.
|
||||
blocks_count: int -- The number of blocks processed in this test.
|
||||
```
|
||||
|
||||
*Note*: There may be a fork transition function to run at the `fork_epoch`.
|
||||
@@ -36,8 +36,6 @@ A series of files, with `<index>` in range `[0, blocks_count)`.
|
||||
Blocks must be processed in order, following the main transition function
|
||||
(i.e. process slot and epoch transitions in between blocks as normal).
|
||||
|
||||
*Note*: `blocks_count` will be missing if there are no blocks in this test.
|
||||
|
||||
Blocks are encoded as `SignedBeaconBlock`s from the relevant spec version
|
||||
as indicated by the `post_fork` and `fork_block` data in the `meta.yaml`.
|
||||
|
||||
@@ -61,7 +59,8 @@ testing the fork from Phase 0 to Altair, blocks with indices `0, 1` represent
|
||||
`SignedBeaconBlock`s defined in the Phase 0 spec and blocks with indices `2, 3`
|
||||
represent `SignedBeaconBlock`s defined in the Altair spec.
|
||||
|
||||
*Note*: `fork_block` will be missing if `blocks_count` is also missing.
|
||||
*Note*: If `fork_block` is missing, then all block data should be
|
||||
interpreted as belonging to the post fork.
|
||||
|
||||
### `post.ssz_snappy`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user