make initialize_beacon_state_from_eth1 work for pre-transition merge

This commit is contained in:
Danny Ryan 2021-10-03 15:12:59 +03:00
parent 296f9bab81
commit af262bec07
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
1 changed files with 10 additions and 9 deletions

View File

@ -354,13 +354,18 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe
## Testing ## Testing
*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Merge testing only. *Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Merge testing only.
Modifications include:
*Note*: The function `initialize_beacon_state_from_eth1` is modified: (1) using `MERGE_FORK_VERSION` as the current fork version, (2) utilizing the Merge `BeaconBlockBody` when constructing the initial `latest_block_header`, and (3) initialize `latest_execution_payload_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.
```python ```python
def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32,
eth1_timestamp: uint64, eth1_timestamp: uint64,
deposits: Sequence[Deposit]) -> BeaconState: deposits: Sequence[Deposit],
execution_payload_header: ExecutionPayloadHeader) -> BeaconState:
fork = Fork( fork = Fork(
previous_version=MERGE_FORK_VERSION, # [Modified in Merge] for testing only previous_version=MERGE_FORK_VERSION, # [Modified in Merge] for testing only
current_version=MERGE_FORK_VERSION, # [Modified in Merge] current_version=MERGE_FORK_VERSION, # [Modified in Merge]
@ -397,12 +402,8 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32,
state.current_sync_committee = get_next_sync_committee(state) state.current_sync_committee = get_next_sync_committee(state)
state.next_sync_committee = get_next_sync_committee(state) state.next_sync_committee = get_next_sync_committee(state)
# [New in Merge] Initialize the execution payload header (with block number set to 0) # [New in Merge] Initialize the execution payload header
state.latest_execution_payload_header.block_hash = eth1_block_hash state.latest_execution_payload_header = execution_payload_header
state.latest_execution_payload_header.timestamp = eth1_timestamp
state.latest_execution_payload_header.random = eth1_block_hash
state.latest_execution_payload_header.gas_limit = GENESIS_GAS_LIMIT
state.latest_execution_payload_header.base_fee_per_gas = GENESIS_BASE_FEE_PER_GAS
return state return state
``` ```