Skip to content

Commit

Permalink
Clean up. Add execution_payload_header to initialization meta.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Oct 3, 2021
1 parent 789eea0 commit e235aa8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
6 changes: 3 additions & 3 deletions specs/merge/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe

*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Merge testing only.
Modifications include:
1. Use `MERGE_FORK_VERSION` as the current fork version
2. Utilize the Merge `BeaconBlockBody` when constructing the initial `latest_block_header`
1. Use `MERGE_FORK_VERSION` as the current fork version.
2. Utilize the Merge `BeaconBlockBody` when constructing the initial `latest_block_header`.
3. Initialize `latest_execution_payload_header`.
If `execution_payload_header == ExecutionPayloadHeader()`, then the Merge has not yet occurred.
Else, the Merge starts from genesis.
Else, the Merge starts from genesis and the transition is incomplete.

```python
def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from eth2spec.test.context import (
MERGE,
single_phase,
spec_test,
with_presets,
with_phases,
with_merge_and_later,
)
from eth2spec.test.helpers.constants import MINIMAL
Expand All @@ -17,7 +19,7 @@ def eth1_init_data(eth1_block_hash, eth1_timestamp):
}


@with_merge_and_later
@with_phases([MERGE])
@spec_test
@single_phase
@with_presets([MINIMAL], reason="too slow")
Expand All @@ -37,11 +39,11 @@ def test_initialize_pre_transition_no_param(spec):
yield 'deposits', deposits

# initialize beacon_state *without* an execution_payload_header
yield 'execution_payload_header', 'meta', False
state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)

assert not spec.is_merge_comp(state)
assert not spec.is_merge_complete(state)

# yield state
yield 'state', state


Expand All @@ -64,19 +66,20 @@ def test_initialize_pre_transition_empty_payload(spec):
yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits

# initialize beacon_state *without* an execution_payload_header
# initialize beacon_state *with* an *empty* execution_payload_header
yield 'execution_payload_header', 'meta', True
execution_payload_header = spec.ExecutionPayloadHeader()
state = spec.initialize_beacon_state_from_eth1(
eth1_block_hash,
eth1_timestamp,
deposits,
spec.ExecutionPayloadHeader()
execution_payload_header=execution_payload_header,
)

assert not spec.is_merge_complete(state)

yield 'execution_payload_header', spec.ExecutionPayloadHeader()
yield 'execution_payload_header', execution_payload_header

# yield state
yield 'state', state


Expand All @@ -100,6 +103,7 @@ def test_initialize_post_transition(spec):
yield 'deposits', deposits

# initialize beacon_state *with* an execution_payload_header
yield 'execution_payload_header', 'meta', True
genesis_execution_payload_header = spec.ExecutionPayloadHeader(
parent_hash=b'\x30' * 32,
coinbase=b'\x42' * 20,
Expand All @@ -118,12 +122,11 @@ def test_initialize_post_transition(spec):
eth1_block_hash,
eth1_timestamp,
deposits,
genesis_execution_payload_header,
execution_payload_header=genesis_execution_payload_header,
)

yield 'execution_payload_header', genesis_execution_payload_header

assert spec.is_merge_complete(state)

# yield state
yield 'state', state
5 changes: 3 additions & 2 deletions tests/formats/genesis/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ eth1_timestamp: int -- An integer. The timestamp of the block, in seconds.
A yaml file to help read the deposit count:

```yaml
description: string -- Optional. Description of test case, purely for debugging purposes.
deposits_count: int -- Amount of deposits.
description: string -- Optional. Description of test case, purely for debugging purposes.
deposits_count: int -- Amount of deposits.
execution_payload_header: bool -- `execution_payload_header` field is filled or not. If `true`, `execution_payload_header.ssz_snappy` file exists.
```

### `deposits_<index>.ssz_snappy`
Expand Down
7 changes: 6 additions & 1 deletion tests/generators/genesis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
]}
altair_mods = phase_0_mods
# we have new unconditional lines in `initialize_beacon_state_from_eth1` and we want to test it
merge_mods = altair_mods
merge_mods = {
**{key: 'eth2spec.test.merge.genesis.test_' + key for key in [
'initialization',
]},
**altair_mods,
}
all_mods = {
PHASE0: phase_0_mods,
ALTAIR: altair_mods,
Expand Down

0 comments on commit e235aa8

Please sign in to comment.