|
14 | 14 | - [Custom types](#custom-types)
|
15 | 15 | - [Constants](#constants)
|
16 | 16 | - [Execution](#execution)
|
17 |
| -- [Configuration](#configuration) |
18 |
| - - [Merge](#merge) |
19 | 17 | - [Containers](#containers)
|
20 | 18 | - [Extended containers](#extended-containers)
|
21 | 19 | - [`BeaconBlockBody`](#beaconblockbody)
|
|
31 | 29 | - [Misc](#misc)
|
32 | 30 | - [`compute_timestamp_at_slot`](#compute_timestamp_at_slot)
|
33 | 31 | - [Beacon chain state transition function](#beacon-chain-state-transition-function)
|
34 |
| -- [Execution engine](#execution-engine) |
35 |
| - - [`on_payload`](#on_payload) |
| 32 | + - [Execution engine](#execution-engine) |
| 33 | + - [`on_payload`](#on_payload) |
36 | 34 | - [Block processing](#block-processing)
|
37 | 35 | - [Execution payload processing](#execution-payload-processing)
|
38 | 36 | - [`process_execution_payload`](#process_execution_payload)
|
| 37 | +- [Initialize state for pure Merge testnets and test vectors](#initialize-state-for-pure-merge-testnets-and-test-vectors) |
39 | 38 |
|
40 | 39 | <!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
41 | 40 | <!-- /TOC -->
|
@@ -63,17 +62,6 @@ This patch adds transaction execution to the beacon chain as part of the merge.
|
63 | 62 | | `MAX_TRANSACTIONS_PER_PAYLOAD` | `uint64(2**14)` (= 16,384) |
|
64 | 63 | | `BYTES_PER_LOGS_BLOOM` | `uint64(2**8)` (= 256) |
|
65 | 64 |
|
66 |
| -## Configuration |
67 |
| - |
68 |
| -### Merge |
69 |
| - |
70 |
| -*Note*: The configuration value `MERGE_FORK_EPOCH` is not final. |
71 |
| - |
72 |
| -| Name | Value | |
73 |
| -| - | - | |
74 |
| -| `MERGE_FORK_VERSION` | `Version('0x02000000')` | |
75 |
| -| `MERGE_FORK_EPOCH` | `Epoch(18446744073709551615)` | |
76 |
| - |
77 | 65 | ## Containers
|
78 | 66 |
|
79 | 67 | ### Extended containers
|
@@ -234,3 +222,63 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody, executi
|
234 | 222 | transactions_root=hash_tree_root(payload.transactions),
|
235 | 223 | )
|
236 | 224 | ```
|
| 225 | + |
| 226 | +## Initialize state for pure Merge testnets and test vectors |
| 227 | + |
| 228 | +This helper function is only for initializing the state for pure Merge testnets and tests. |
| 229 | + |
| 230 | +*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) adding initial `latest_execution_payload_header`. |
| 231 | + |
| 232 | +```python |
| 233 | +def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, |
| 234 | + eth1_timestamp: uint64, |
| 235 | + deposits: Sequence[Deposit]) -> BeaconState: |
| 236 | + fork = Fork( |
| 237 | + previous_version=GENESIS_FORK_VERSION, |
| 238 | + current_version=MERGE_FORK_VERSION, # [Modified in Merge] |
| 239 | + epoch=GENESIS_EPOCH, |
| 240 | + ) |
| 241 | + state = BeaconState( |
| 242 | + genesis_time=eth1_timestamp + GENESIS_DELAY, |
| 243 | + fork=fork, |
| 244 | + eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), |
| 245 | + latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), |
| 246 | + randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy |
| 247 | + ) |
| 248 | + |
| 249 | + # Process deposits |
| 250 | + leaves = list(map(lambda deposit: deposit.data, deposits)) |
| 251 | + for index, deposit in enumerate(deposits): |
| 252 | + deposit_data_list = List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1]) |
| 253 | + state.eth1_data.deposit_root = hash_tree_root(deposit_data_list) |
| 254 | + process_deposit(state, deposit) |
| 255 | + |
| 256 | + # Process activations |
| 257 | + for index, validator in enumerate(state.validators): |
| 258 | + balance = state.balances[index] |
| 259 | + validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE) |
| 260 | + if validator.effective_balance == MAX_EFFECTIVE_BALANCE: |
| 261 | + validator.activation_eligibility_epoch = GENESIS_EPOCH |
| 262 | + validator.activation_epoch = GENESIS_EPOCH |
| 263 | + |
| 264 | + # Set genesis validators root for domain separation and chain versioning |
| 265 | + state.genesis_validators_root = hash_tree_root(state.validators) |
| 266 | + |
| 267 | + # [New in Merge] Construct execution payload header |
| 268 | + # Note: initialized with zero block height |
| 269 | + state.latest_execution_payload_header = ExecutionPayloadHeader( |
| 270 | + block_hash=eth1_block_hash, |
| 271 | + parent_hash=Hash32(), |
| 272 | + coinbase=Bytes20(), |
| 273 | + state_root=Bytes32(), |
| 274 | + number=uint64(0), |
| 275 | + gas_limit=uint64(0), |
| 276 | + gas_used=uint64(0), |
| 277 | + timestamp=eth1_timestamp, |
| 278 | + receipt_root=Bytes32(), |
| 279 | + logs_bloom=ByteVector[BYTES_PER_LOGS_BLOOM](), |
| 280 | + transactions_root=Root(), |
| 281 | + ) |
| 282 | + |
| 283 | + return state |
| 284 | +``` |
0 commit comments