2021-03-11 12:52:31 +00:00
# Ethereum 2.0 The Merge
2021-03-11 12:33:36 +00:00
2021-03-24 10:30:29 +00:00
**Warning:** This document is currently based on [Phase 0 ](../phase0/validator.md ) but will be rebased to [Altair ](../altair/validator.md ) once the latter is shipped.
2021-03-17 16:39:35 +00:00
2021-03-11 12:33:36 +00:00
**Notice**: This document is a work-in-progress for researchers and implementers.
## Table of contents
<!-- TOC -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE - RUN doctoc TO UPDATE -->
- [Introduction ](#introduction )
- [Prerequisites ](#prerequisites )
2021-05-10 13:48:37 +00:00
- [Protocols ](#protocols )
- [`ExecutionEngine` ](#executionengine )
- [`assemble_block` ](#assemble_block )
2021-03-11 12:33:36 +00:00
- [Beacon chain responsibilities ](#beacon-chain-responsibilities )
- [Block proposal ](#block-proposal )
- [Constructing the `BeaconBlockBody` ](#constructing-the-beaconblockbody )
2021-04-08 08:29:05 +00:00
- [Execution Payload ](#execution-payload )
2021-03-20 13:21:11 +00:00
- [`get_pow_chain_head` ](#get_pow_chain_head )
2021-04-08 08:29:05 +00:00
- [`produce_execution_payload` ](#produce_execution_payload )
2021-03-11 12:33:36 +00:00
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->
## Introduction
This document represents the changes to be made in the code of an "honest validator" to implement executable beacon chain proposal.
## Prerequisites
This document is an extension of the [Phase 0 -- Validator ](../phase0/validator.md ). All behaviors and definitions defined in the Phase 0 doc carry over unless explicitly noted or overridden.
All terminology, constants, functions, and protocol mechanics defined in the updated Beacon Chain doc of [The Merge ](./beacon-chain.md ) are requisite for this document and used throughout. Please see related Beacon Chain doc before continuing and use them as a reference throughout.
2021-05-10 13:48:37 +00:00
## Protocols
### `ExecutionEngine`
The following methods are added to the `ExecutionEngine` protocol for use as a validator:
#### `assemble_block`
2021-05-13 23:07:22 +00:00
Produces a new instance of an execution payload, with the specified `timestamp` ,
on top of the execution payload chain tip identified by `block_hash` .
2021-05-10 13:48:37 +00:00
The body of this function is implementation dependent.
The Consensus API may be used to implement this with an external execution engine.
```python
def assemble_block(self: ExecutionEngine, block_hash: Hash32, timestamp: uint64) -> ExecutionPayload:
...
```
2021-03-11 12:33:36 +00:00
## Beacon chain responsibilities
2021-04-08 08:29:05 +00:00
All validator responsibilities remain unchanged other than those noted below. Namely, the transition block handling and the addition of `ExecutionPayload` .
2021-03-11 12:33:36 +00:00
### Block proposal
#### Constructing the `BeaconBlockBody`
2021-04-08 08:29:05 +00:00
##### Execution Payload
2021-03-11 12:33:36 +00:00
2021-03-20 13:21:11 +00:00
###### `get_pow_chain_head`
2021-03-11 12:33:36 +00:00
2021-03-20 13:21:11 +00:00
Let `get_pow_chain_head() -> PowBlock` be the function that returns the head of the PoW chain. The body of the function is implementation specific.
2021-03-11 12:33:36 +00:00
2021-04-08 08:29:05 +00:00
###### `produce_execution_payload`
2021-03-11 12:33:36 +00:00
2021-04-08 09:26:32 +00:00
Let `produce_execution_payload(parent_hash: Hash32, timestamp: uint64) -> ExecutionPayload` be the function that produces new instance of execution payload.
2021-05-10 13:48:37 +00:00
The `ExecutionEngine` protocol is used for the implementation specific part of execution payload proposals.
2021-03-11 12:33:36 +00:00
2021-04-08 08:29:05 +00:00
* Set `block.body.execution_payload = get_execution_payload(state)` where:
2021-03-11 12:33:36 +00:00
```python
2021-05-10 13:48:37 +00:00
def get_execution_payload(state: BeaconState, execution_engine: ExecutionEngine) -> ExecutionPayload:
2021-03-24 10:30:29 +00:00
if not is_transition_completed(state):
2021-03-25 11:49:13 +00:00
pow_block = get_pow_chain_head()
2021-03-31 09:35:55 +00:00
if not is_valid_transition_block(pow_block):
2021-03-25 11:49:13 +00:00
# Pre-merge, empty payload
2021-04-08 08:29:05 +00:00
return ExecutionPayload()
2021-03-25 11:49:13 +00:00
else:
2021-03-31 09:35:55 +00:00
# Signify merge via producing on top of the last PoW block
2021-04-09 16:50:37 +00:00
timestamp = compute_time_at_slot(state, state.slot)
2021-05-10 13:48:37 +00:00
return execution_engine.assemble_block(pow_block.block_hash, timestamp)
2021-03-24 10:30:29 +00:00
# Post-merge, normal payload
2021-04-08 08:29:05 +00:00
execution_parent_hash = state.latest_execution_payload_header.block_hash
2021-04-08 09:26:32 +00:00
timestamp = compute_time_at_slot(state, state.slot)
2021-05-12 00:40:23 +00:00
return execution_engine.assemble_block(execution_parent_hash, timestamp)
2021-03-11 12:33:36 +00:00
```