Merge pull request #2322 from mkalinin/merge-cleanup

Merge cleanups and improvements
This commit is contained in:
Danny Ryan 2021-04-15 07:17:55 -05:00 committed by GitHub
commit 2baeee463d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 32 deletions

View File

@ -313,11 +313,11 @@ def get_pow_chain_head() -> PowBlock:
pass
def execution_state_transition(execution_state: ExecutionState, execution_payload: ExecutionPayload) -> None:
pass
def verify_execution_state_transition(execution_payload: ExecutionPayload) -> bool:
return True
def produce_execution_payload(parent_hash: Bytes32) -> ExecutionPayload:
def produce_execution_payload(parent_hash: Hash32, timestamp: uint64) -> ExecutionPayload:
pass"""

View File

@ -26,10 +26,10 @@
- [Misc](#misc)
- [`is_transition_completed`](#is_transition_completed)
- [`is_transition_block`](#is_transition_block)
- [`compute_time_at_slot`](#compute_time_at_slot)
- [Block processing](#block-processing)
- [Execution payload processing](#execution-payload-processing)
- [`get_execution_state`](#get_execution_state)
- [`execution_state_transition`](#execution_state_transition)
- [`verify_execution_state_transition`](#verify_execution_state_transition)
- [`process_execution_payload`](#process_execution_payload)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@ -98,13 +98,14 @@ The execution payload included in a `BeaconBlockBody`.
```python
class ExecutionPayload(Container):
block_hash: Bytes32 # Hash of execution block
parent_hash: Bytes32
block_hash: Hash32 # Hash of execution block
parent_hash: Hash32
coinbase: Bytes20
state_root: Bytes32
number: uint64
gas_limit: uint64
gas_used: uint64
timestamp: uint64
receipt_root: Bytes32
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
transactions: List[OpaqueTransaction, MAX_APPLICATION_TRANSACTIONS]
@ -118,13 +119,14 @@ The execution payload header included in a `BeaconState`.
```python
class ExecutionPayloadHeader(Container):
block_hash: Bytes32 # Hash of execution block
parent_hash: Bytes32
block_hash: Hash32 # Hash of execution block
parent_hash: Hash32
coinbase: Bytes20
state_root: Bytes32
number: uint64
gas_limit: uint64
gas_used: uint64
timestamp: uint64
receipt_root: Bytes32
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
transactions_root: Root
@ -137,17 +139,27 @@ class ExecutionPayloadHeader(Container):
#### `is_transition_completed`
```python
def is_transition_completed(state: BeaconState) -> boolean:
def is_transition_completed(state: BeaconState) -> bool:
return state.latest_execution_payload_header != ExecutionPayloadHeader()
```
#### `is_transition_block`
```python
def is_transition_block(state: BeaconState, block_body: BeaconBlockBody) -> boolean:
def is_transition_block(state: BeaconState, block_body: BeaconBlockBody) -> bool:
return not is_transition_completed(state) and block_body.execution_payload != ExecutionPayload()
```
#### `compute_time_at_slot`
*Note*: This function is unsafe with respect to overflows and underflows.
```python
def compute_time_at_slot(state: BeaconState, slot: Slot) -> uint64:
slots_since_genesis = slot - GENESIS_SLOT
return uint64(state.genesis_time + slots_since_genesis * SECONDS_PER_SLOT)
```
### Block processing
```python
@ -161,20 +173,11 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None:
#### Execution payload processing
##### `get_execution_state`
##### `verify_execution_state_transition`
*Note*: `ExecutionState` class is an abstract class representing Ethereum execution state.
Let `get_execution_state(execution_state_root: Bytes32) -> ExecutionState` be the function that given the root hash returns a copy of Ethereum execution state.
Let `verify_execution_state_transition(execution_payload: ExecutionPayload) -> bool` be the function that verifies given `ExecutionPayload` with respect to execution state transition.
The body of the function is implementation dependent.
##### `execution_state_transition`
Let `execution_state_transition(execution_state: ExecutionState, execution_payload: ExecutionPayload) -> None` be the transition function of Ethereum execution state.
The body of the function is implementation dependent.
*Note*: `execution_state_transition` must throw `AssertionError` if either the transition itself or one of the pre or post conditions has failed.
##### `process_execution_payload`
```python
@ -192,8 +195,9 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody) -> None
assert execution_payload.parent_hash == state.latest_execution_payload_header.block_hash
assert execution_payload.number == state.latest_execution_payload_header.number + 1
execution_state = get_execution_state(state.latest_execution_payload_header.state_root)
execution_state_transition(execution_state, execution_payload)
assert execution_payload.timestamp == compute_time_at_slot(state, state.slot)
assert verify_execution_state_transition(execution_payload)
state.latest_execution_payload_header = ExecutionPayloadHeader(
block_hash=execution_payload.block_hash,
@ -203,6 +207,7 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody) -> None
number=execution_payload.number,
gas_limit=execution_payload.gas_limit,
gas_used=execution_payload.gas_used,
timestamp=execution_payload.timestamp,
receipt_root=execution_payload.receipt_root,
logs_bloom=execution_payload.logs_bloom,
transactions_root=hash_tree_root(execution_payload.transactions),

View File

@ -30,7 +30,7 @@ This is the modification of the fork choice according to the executable beacon c
```python
class PowBlock(Container):
block_hash: Bytes32
block_hash: Hash32
is_processed: boolean
is_valid: boolean
total_difficulty: uint256
@ -38,7 +38,7 @@ class PowBlock(Container):
#### `get_pow_block`
Let `get_pow_block(hash: Bytes32) -> PowBlock` be the function that given the hash of the PoW block returns its data.
Let `get_pow_block(block_hash: Hash32) -> PowBlock` be the function that given the hash of the PoW block returns its data.
*Note*: The `eth_getBlockByHash` JSON-RPC method does not distinguish invalid blocks from blocks that haven't been processed yet. Either extending this existing method or implementing a new one is required.
@ -47,7 +47,7 @@ Let `get_pow_block(hash: Bytes32) -> PowBlock` be the function that given the ha
Used by fork-choice handler, `on_block`.
```python
def is_valid_transition_block(block: PowBlock) -> boolean:
def is_valid_transition_block(block: PowBlock) -> bool:
is_total_difficulty_reached = block.total_difficulty >= TRANSITION_TOTAL_DIFFICULTY
return block.is_valid and is_total_difficulty_reached
```
@ -113,4 +113,3 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
if ancestor_at_finalized_slot != store.finalized_checkpoint.root:
store.justified_checkpoint = state.current_justified_checkpoint
```

View File

@ -48,7 +48,7 @@ Let `get_pow_chain_head() -> PowBlock` be the function that returns the head of
###### `produce_execution_payload`
Let `produce_execution_payload(parent_hash: Bytes32) -> ExecutionPayload` be the function that produces new instance of execution payload.
Let `produce_execution_payload(parent_hash: Hash32, timestamp: uint64) -> ExecutionPayload` be the function that produces new instance of execution payload.
The body of this function is implementation dependent.
* Set `block.body.execution_payload = get_execution_payload(state)` where:
@ -62,9 +62,11 @@ def get_execution_payload(state: BeaconState) -> ExecutionPayload:
return ExecutionPayload()
else:
# Signify merge via producing on top of the last PoW block
return produce_execution_payload(pow_block.block_hash)
timestamp = compute_time_at_slot(state, state.slot)
return produce_execution_payload(pow_block.block_hash, timestamp)
# Post-merge, normal payload
execution_parent_hash = state.latest_execution_payload_header.block_hash
return produce_execution_payload(execution_parent_hash)
timestamp = compute_time_at_slot(state, state.slot)
return produce_execution_payload(execution_parent_hash, timestamp)
```

View File

@ -157,6 +157,7 @@ We define the following Python custom types for type hinting and readability:
| `ValidatorIndex` | `uint64` | a validator registry index |
| `Gwei` | `uint64` | an amount in Gwei |
| `Root` | `Bytes32` | a Merkle root |
| `Hash32` | `Bytes32` | a 256-bit hash |
| `Version` | `Bytes4` | a fork version number |
| `DomainType` | `Bytes4` | a domain type |
| `ForkDigest` | `Bytes4` | a digest of the current fork data |
@ -164,6 +165,7 @@ We define the following Python custom types for type hinting and readability:
| `BLSPubkey` | `Bytes48` | a BLS12-381 public key |
| `BLSSignature` | `Bytes96` | a BLS12-381 signature |
## Constants
The following values are (non-configurable) constants used throughout the specification.
@ -374,7 +376,7 @@ class PendingAttestation(Container):
class Eth1Data(Container):
deposit_root: Root
deposit_count: uint64
block_hash: Bytes32
block_hash: Hash32
```
#### `HistoricalBatch`