Add parent_hash, number to ApplicationPayload
This commit is contained in:
parent
b52cde0c86
commit
106e1b98ba
|
@ -81,13 +81,14 @@ class BeaconBlockBody(phase0.BeaconBlockBody):
|
||||||
|
|
||||||
#### `BeaconState`
|
#### `BeaconState`
|
||||||
|
|
||||||
*Note*: `BeaconState` fields remain unchanged other than addition of `application_state_root` and `application_block_hash`.
|
*Note*: `BeaconState` fields remain unchanged other than addition of application payload fields.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class BeaconState(phase0.BeaconState):
|
class BeaconState(phase0.BeaconState):
|
||||||
# Application-layer
|
# Application-layer
|
||||||
application_state_root: Bytes32 # [New in Merge]
|
application_state_root: Bytes32 # [New in Merge]
|
||||||
application_block_hash: Bytes32 # [New in Merge]
|
application_block_hash: Bytes32 # [New in Merge]
|
||||||
|
application_block_number: uint64 # [New in Merge]
|
||||||
```
|
```
|
||||||
|
|
||||||
### New containers
|
### New containers
|
||||||
|
@ -99,8 +100,10 @@ The application payload included in a `BeaconBlockBody`.
|
||||||
```python
|
```python
|
||||||
class ApplicationPayload(Container):
|
class ApplicationPayload(Container):
|
||||||
block_hash: Bytes32 # Hash of application block
|
block_hash: Bytes32 # Hash of application block
|
||||||
|
parent_hash: Bytes32
|
||||||
coinbase: Bytes20
|
coinbase: Bytes20
|
||||||
state_root: Bytes32
|
state_root: Bytes32
|
||||||
|
number: uint64
|
||||||
gas_limit: uint64
|
gas_limit: uint64
|
||||||
gas_used: uint64
|
gas_used: uint64
|
||||||
receipt_root: Bytes32
|
receipt_root: Bytes32
|
||||||
|
@ -161,15 +164,18 @@ def process_application_payload(state: BeaconState, body: BeaconBlockBody) -> No
|
||||||
Note: This function is designed to be able to be run in parallel with the other `process_block` sub-functions
|
Note: This function is designed to be able to be run in parallel with the other `process_block` sub-functions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if is_transition_completed(state):
|
if not is_transition_completed(state):
|
||||||
application_state = get_application_state(state.application_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
|
|
||||||
elif is_transition_block(state, body):
|
|
||||||
assert body.application_payload == ApplicationPayload(block_hash=body.application_payload.block_hash)
|
|
||||||
state.application_block_hash = body.application_payload.block_hash
|
|
||||||
else:
|
|
||||||
assert body.application_payload == ApplicationPayload()
|
assert body.application_payload == ApplicationPayload()
|
||||||
|
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
|
||||||
|
|
||||||
|
application_state = get_application_state(state.application_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
|
||||||
```
|
```
|
||||||
|
|
|
@ -77,7 +77,7 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
|
||||||
# [New in Merge]
|
# [New in Merge]
|
||||||
if is_transition_block(pre_state, block.body):
|
if is_transition_block(pre_state, block.body):
|
||||||
# Delay consideration of block until PoW block is processed by the PoW node
|
# Delay consideration of block until PoW block is processed by the PoW node
|
||||||
pow_block = get_pow_block(block.body.application_payload.block_hash)
|
pow_block = get_pow_block(block.body.application_payload.parent_hash)
|
||||||
assert pow_block.is_processed
|
assert pow_block.is_processed
|
||||||
assert is_valid_transition_block(pow_block)
|
assert is_valid_transition_block(pow_block)
|
||||||
|
|
||||||
|
|
|
@ -57,12 +57,12 @@ The body of this function is implementation dependent.
|
||||||
def get_application_payload(state: BeaconState) -> ApplicationPayload:
|
def get_application_payload(state: BeaconState) -> ApplicationPayload:
|
||||||
if not is_transition_completed(state):
|
if not is_transition_completed(state):
|
||||||
pow_block = get_pow_chain_head()
|
pow_block = get_pow_chain_head()
|
||||||
if pow_block.total_difficulty < TRANSITION_TOTAL_DIFFICULTY:
|
if not is_valid_transition_block(pow_block):
|
||||||
# Pre-merge, empty payload
|
# Pre-merge, empty payload
|
||||||
return ApplicationPayload()
|
return ApplicationPayload()
|
||||||
else:
|
else:
|
||||||
# Signify merge via last PoW block_hash and an otherwise empty payload
|
# Signify merge via producing on top of the last PoW block
|
||||||
return ApplicationPayload(block_hash=pow_block.block_hash)
|
return produce_application_payload(pow_block.block_hash)
|
||||||
|
|
||||||
# Post-merge, normal payload
|
# Post-merge, normal payload
|
||||||
application_parent_hash = state.application_block_hash
|
application_parent_hash = state.application_block_hash
|
||||||
|
|
Loading…
Reference in New Issue