Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New application payload fields #2295

Merged
merged 4 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions specs/merge/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [`BeaconState`](#beaconstate)
- [New containers](#new-containers)
- [`ApplicationPayload`](#applicationpayload)
- [`ApplicationBlockHeader`](#applicationblockheader)
- [Helper functions](#helper-functions)
- [Misc](#misc)
- [`is_transition_completed`](#is_transition_completed)
Expand Down Expand Up @@ -81,14 +82,12 @@ class BeaconBlockBody(phase0.BeaconBlockBody):

#### `BeaconState`

*Note*: `BeaconState` fields remain unchanged other than addition of application payload fields.
*Note*: `BeaconState` fields remain unchanged other than addition of `latest_application_block_header`.

```python
class BeaconState(phase0.BeaconState):
# Application-layer
application_state_root: Bytes32 # [New in Merge]
application_block_hash: Bytes32 # [New in Merge]
application_block_number: uint64 # [New in Merge]
latest_application_block_header: ApplicationBlockHeader # [New in Merge]
```

### New containers
Expand All @@ -111,6 +110,25 @@ class ApplicationPayload(Container):
transactions: List[OpaqueTransaction, MAX_APPLICATION_TRANSACTIONS]
```

#### `ApplicationBlockHeader`

The application block header included in a `BeaconState`.

*Note:* Holds application payload data without transaction list.

```python
class ApplicationBlockHeader(Container):
block_hash: Bytes32 # Hash of application block
parent_hash: Bytes32
coinbase: Bytes20
state_root: Bytes32
number: uint64
gas_limit: uint64
gas_used: uint64
receipt_root: Bytes32
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we add transactions_root so that this merklizes to the same root of ApplicationPayload

We can then rename this to ApplicationPayloadHeader or rename the payload to ApplicationBlock.

(side note, we mgiht be renaming these all to use Execution prefix but thats a separate PR

```

## Helper functions

### Misc
Expand All @@ -119,14 +137,14 @@ class ApplicationPayload(Container):

```python
def is_transition_completed(state: BeaconState) -> boolean:
return state.application_block_hash != Bytes32()
return state.latest_application_block_header.block_hash != Bytes32()
```

#### `is_transition_block`

```python
def is_transition_block(state: BeaconState, block_body: BeaconBlockBody) -> boolean:
return state.application_block_hash == Bytes32() and block_body.application_payload.block_hash != Bytes32()
return state.latest_application_block_header.block_hash == Bytes32() and block_body.application_payload.block_hash != Bytes32()
```

### Block processing
Expand Down Expand Up @@ -169,13 +187,21 @@ def process_application_payload(state: BeaconState, body: BeaconBlockBody) -> No
return

if not is_transition_block(state, body):
assert body.application_payload.parent_hash == state.application_block_hash
assert body.application_payload.number == state.application_block_number + 1
assert body.application_payload.parent_hash == state.latest_application_block_header.block_hash
assert body.application_payload.number == state.latest_application_block_header.number + 1

application_state = get_application_state(state.application_state_root)
application_state = get_application_state(state.latest_application_block_header.state_root)
application_state_transition(application_state, body.application_payload)

state.application_state_root = body.application_payload.state_root
state.application_block_hash = body.application_payload.block_hash
state.application_block_number = body.application_payload.number
state.latest_application_block_header = ApplicationBlockHeader(
block_hash=application_payload.block_hash,
parent_hash=application_payload.parent_hash,
coinbase=application_payload.coinbase,
state_root=application_payload.state_root,
number=application_payload.number,
gas_limit=application_payload.gas_limit,
gas_used=application_payload.gas_used,
receipt_root=application_payload.receipt_root,
logs_bloom=application_payload.logs_bloom,
)
```
2 changes: 1 addition & 1 deletion specs/merge/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def get_application_payload(state: BeaconState) -> ApplicationPayload:
return produce_application_payload(pow_block.block_hash)

# Post-merge, normal payload
application_parent_hash = state.application_block_hash
application_parent_hash = state.latest_application_block_header.block_hash
return produce_application_payload(application_parent_hash)
```