Merge pull request #2322 from mkalinin/merge-cleanup
Merge cleanups and improvements
This commit is contained in:
commit
2baeee463d
6
setup.py
6
setup.py
|
@ -313,11 +313,11 @@ def get_pow_chain_head() -> PowBlock:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def execution_state_transition(execution_state: ExecutionState, execution_payload: ExecutionPayload) -> None:
|
def verify_execution_state_transition(execution_payload: ExecutionPayload) -> bool:
|
||||||
pass
|
return True
|
||||||
|
|
||||||
|
|
||||||
def produce_execution_payload(parent_hash: Bytes32) -> ExecutionPayload:
|
def produce_execution_payload(parent_hash: Hash32, timestamp: uint64) -> ExecutionPayload:
|
||||||
pass"""
|
pass"""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@
|
||||||
- [Misc](#misc)
|
- [Misc](#misc)
|
||||||
- [`is_transition_completed`](#is_transition_completed)
|
- [`is_transition_completed`](#is_transition_completed)
|
||||||
- [`is_transition_block`](#is_transition_block)
|
- [`is_transition_block`](#is_transition_block)
|
||||||
|
- [`compute_time_at_slot`](#compute_time_at_slot)
|
||||||
- [Block processing](#block-processing)
|
- [Block processing](#block-processing)
|
||||||
- [Execution payload processing](#execution-payload-processing)
|
- [Execution payload processing](#execution-payload-processing)
|
||||||
- [`get_execution_state`](#get_execution_state)
|
- [`verify_execution_state_transition`](#verify_execution_state_transition)
|
||||||
- [`execution_state_transition`](#execution_state_transition)
|
|
||||||
- [`process_execution_payload`](#process_execution_payload)
|
- [`process_execution_payload`](#process_execution_payload)
|
||||||
|
|
||||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
@ -98,13 +98,14 @@ The execution payload included in a `BeaconBlockBody`.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class ExecutionPayload(Container):
|
class ExecutionPayload(Container):
|
||||||
block_hash: Bytes32 # Hash of execution block
|
block_hash: Hash32 # Hash of execution block
|
||||||
parent_hash: Bytes32
|
parent_hash: Hash32
|
||||||
coinbase: Bytes20
|
coinbase: Bytes20
|
||||||
state_root: Bytes32
|
state_root: Bytes32
|
||||||
number: uint64
|
number: uint64
|
||||||
gas_limit: uint64
|
gas_limit: uint64
|
||||||
gas_used: uint64
|
gas_used: uint64
|
||||||
|
timestamp: uint64
|
||||||
receipt_root: Bytes32
|
receipt_root: Bytes32
|
||||||
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
|
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
|
||||||
transactions: List[OpaqueTransaction, MAX_APPLICATION_TRANSACTIONS]
|
transactions: List[OpaqueTransaction, MAX_APPLICATION_TRANSACTIONS]
|
||||||
|
@ -118,13 +119,14 @@ The execution payload header included in a `BeaconState`.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class ExecutionPayloadHeader(Container):
|
class ExecutionPayloadHeader(Container):
|
||||||
block_hash: Bytes32 # Hash of execution block
|
block_hash: Hash32 # Hash of execution block
|
||||||
parent_hash: Bytes32
|
parent_hash: Hash32
|
||||||
coinbase: Bytes20
|
coinbase: Bytes20
|
||||||
state_root: Bytes32
|
state_root: Bytes32
|
||||||
number: uint64
|
number: uint64
|
||||||
gas_limit: uint64
|
gas_limit: uint64
|
||||||
gas_used: uint64
|
gas_used: uint64
|
||||||
|
timestamp: uint64
|
||||||
receipt_root: Bytes32
|
receipt_root: Bytes32
|
||||||
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
|
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
|
||||||
transactions_root: Root
|
transactions_root: Root
|
||||||
|
@ -137,17 +139,27 @@ class ExecutionPayloadHeader(Container):
|
||||||
#### `is_transition_completed`
|
#### `is_transition_completed`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def is_transition_completed(state: BeaconState) -> boolean:
|
def is_transition_completed(state: BeaconState) -> bool:
|
||||||
return state.latest_execution_payload_header != ExecutionPayloadHeader()
|
return state.latest_execution_payload_header != ExecutionPayloadHeader()
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `is_transition_block`
|
#### `is_transition_block`
|
||||||
|
|
||||||
```python
|
```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()
|
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
|
### Block processing
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -161,20 +173,11 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None:
|
||||||
|
|
||||||
#### Execution payload processing
|
#### Execution payload processing
|
||||||
|
|
||||||
##### `get_execution_state`
|
##### `verify_execution_state_transition`
|
||||||
|
|
||||||
*Note*: `ExecutionState` class is an abstract class representing 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.
|
||||||
|
|
||||||
Let `get_execution_state(execution_state_root: Bytes32) -> ExecutionState` be the function that given the root hash returns a copy of Ethereum execution state.
|
|
||||||
The body of the function is implementation dependent.
|
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`
|
##### `process_execution_payload`
|
||||||
|
|
||||||
```python
|
```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.parent_hash == state.latest_execution_payload_header.block_hash
|
||||||
assert execution_payload.number == state.latest_execution_payload_header.number + 1
|
assert execution_payload.number == state.latest_execution_payload_header.number + 1
|
||||||
|
|
||||||
execution_state = get_execution_state(state.latest_execution_payload_header.state_root)
|
assert execution_payload.timestamp == compute_time_at_slot(state, state.slot)
|
||||||
execution_state_transition(execution_state, execution_payload)
|
|
||||||
|
assert verify_execution_state_transition(execution_payload)
|
||||||
|
|
||||||
state.latest_execution_payload_header = ExecutionPayloadHeader(
|
state.latest_execution_payload_header = ExecutionPayloadHeader(
|
||||||
block_hash=execution_payload.block_hash,
|
block_hash=execution_payload.block_hash,
|
||||||
|
@ -203,6 +207,7 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody) -> None
|
||||||
number=execution_payload.number,
|
number=execution_payload.number,
|
||||||
gas_limit=execution_payload.gas_limit,
|
gas_limit=execution_payload.gas_limit,
|
||||||
gas_used=execution_payload.gas_used,
|
gas_used=execution_payload.gas_used,
|
||||||
|
timestamp=execution_payload.timestamp,
|
||||||
receipt_root=execution_payload.receipt_root,
|
receipt_root=execution_payload.receipt_root,
|
||||||
logs_bloom=execution_payload.logs_bloom,
|
logs_bloom=execution_payload.logs_bloom,
|
||||||
transactions_root=hash_tree_root(execution_payload.transactions),
|
transactions_root=hash_tree_root(execution_payload.transactions),
|
||||||
|
|
|
@ -30,7 +30,7 @@ This is the modification of the fork choice according to the executable beacon c
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class PowBlock(Container):
|
class PowBlock(Container):
|
||||||
block_hash: Bytes32
|
block_hash: Hash32
|
||||||
is_processed: boolean
|
is_processed: boolean
|
||||||
is_valid: boolean
|
is_valid: boolean
|
||||||
total_difficulty: uint256
|
total_difficulty: uint256
|
||||||
|
@ -38,7 +38,7 @@ class PowBlock(Container):
|
||||||
|
|
||||||
#### `get_pow_block`
|
#### `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.
|
*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`.
|
Used by fork-choice handler, `on_block`.
|
||||||
|
|
||||||
```python
|
```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
|
is_total_difficulty_reached = block.total_difficulty >= TRANSITION_TOTAL_DIFFICULTY
|
||||||
return block.is_valid and is_total_difficulty_reached
|
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:
|
if ancestor_at_finalized_slot != store.finalized_checkpoint.root:
|
||||||
store.justified_checkpoint = state.current_justified_checkpoint
|
store.justified_checkpoint = state.current_justified_checkpoint
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ Let `get_pow_chain_head() -> PowBlock` be the function that returns the head of
|
||||||
|
|
||||||
###### `produce_execution_payload`
|
###### `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.
|
The body of this function is implementation dependent.
|
||||||
|
|
||||||
* Set `block.body.execution_payload = get_execution_payload(state)` where:
|
* Set `block.body.execution_payload = get_execution_payload(state)` where:
|
||||||
|
@ -62,9 +62,11 @@ def get_execution_payload(state: BeaconState) -> ExecutionPayload:
|
||||||
return ExecutionPayload()
|
return ExecutionPayload()
|
||||||
else:
|
else:
|
||||||
# Signify merge via producing on top of the last PoW block
|
# 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
|
# Post-merge, normal payload
|
||||||
execution_parent_hash = state.latest_execution_payload_header.block_hash
|
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)
|
||||||
```
|
```
|
||||||
|
|
|
@ -157,6 +157,7 @@ We define the following Python custom types for type hinting and readability:
|
||||||
| `ValidatorIndex` | `uint64` | a validator registry index |
|
| `ValidatorIndex` | `uint64` | a validator registry index |
|
||||||
| `Gwei` | `uint64` | an amount in Gwei |
|
| `Gwei` | `uint64` | an amount in Gwei |
|
||||||
| `Root` | `Bytes32` | a Merkle root |
|
| `Root` | `Bytes32` | a Merkle root |
|
||||||
|
| `Hash32` | `Bytes32` | a 256-bit hash |
|
||||||
| `Version` | `Bytes4` | a fork version number |
|
| `Version` | `Bytes4` | a fork version number |
|
||||||
| `DomainType` | `Bytes4` | a domain type |
|
| `DomainType` | `Bytes4` | a domain type |
|
||||||
| `ForkDigest` | `Bytes4` | a digest of the current fork data |
|
| `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 |
|
| `BLSPubkey` | `Bytes48` | a BLS12-381 public key |
|
||||||
| `BLSSignature` | `Bytes96` | a BLS12-381 signature |
|
| `BLSSignature` | `Bytes96` | a BLS12-381 signature |
|
||||||
|
|
||||||
|
|
||||||
## Constants
|
## Constants
|
||||||
|
|
||||||
The following values are (non-configurable) constants used throughout the specification.
|
The following values are (non-configurable) constants used throughout the specification.
|
||||||
|
@ -374,7 +376,7 @@ class PendingAttestation(Container):
|
||||||
class Eth1Data(Container):
|
class Eth1Data(Container):
|
||||||
deposit_root: Root
|
deposit_root: Root
|
||||||
deposit_count: uint64
|
deposit_count: uint64
|
||||||
block_hash: Bytes32
|
block_hash: Hash32
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `HistoricalBatch`
|
#### `HistoricalBatch`
|
||||||
|
|
Loading…
Reference in New Issue