Merge pull request #2104 from ethereum/state_transition_patch
Make `state_transition` not return post-state
This commit is contained in:
commit
6b44f63751
|
@ -1202,7 +1202,7 @@ Let `genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))`.
|
|||
The post-state corresponding to a pre-state `state` and a signed block `signed_block` is defined as `state_transition(state, signed_block)`. State transitions that trigger an unhandled exception (e.g. a failed `assert` or an out-of-range list access) are considered invalid. State transitions that cause a `uint64` overflow or underflow are also considered invalid.
|
||||
|
||||
```python
|
||||
def state_transition(state: BeaconState, signed_block: SignedBeaconBlock, validate_result: bool=True) -> BeaconState:
|
||||
def state_transition(state: BeaconState, signed_block: SignedBeaconBlock, validate_result: bool=True) -> None:
|
||||
block = signed_block.message
|
||||
# Process slots (including those with no blocks) since block
|
||||
process_slots(state, block.slot)
|
||||
|
@ -1214,8 +1214,6 @@ def state_transition(state: BeaconState, signed_block: SignedBeaconBlock, valida
|
|||
# Verify state root
|
||||
if validate_result:
|
||||
assert block.state_root == hash_tree_root(state)
|
||||
# Return post-state
|
||||
return state
|
||||
```
|
||||
|
||||
```python
|
||||
|
|
|
@ -354,7 +354,8 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
|
|||
assert get_ancestor(store, block.parent_root, finalized_slot) == store.finalized_checkpoint.root
|
||||
|
||||
# Check the block is valid and compute the post-state
|
||||
state = state_transition(pre_state, signed_block, True)
|
||||
state = pre_state.copy()
|
||||
state_transition(state, signed_block, True)
|
||||
# Add new block to the store
|
||||
store.blocks[hash_tree_root(block)] = block
|
||||
# Add new state for this block to the store
|
||||
|
|
|
@ -376,7 +376,7 @@ It is useful to be able to run a state transition function (working on a copy of
|
|||
def compute_new_state_root(state: BeaconState, block: BeaconBlock) -> Root:
|
||||
temp_state: BeaconState = state.copy()
|
||||
signed_block = SignedBeaconBlock(message=block)
|
||||
temp_state = state_transition(temp_state, signed_block, validate_result=False)
|
||||
state_transition(temp_state, signed_block, validate_result=False)
|
||||
return hash_tree_root(temp_state)
|
||||
```
|
||||
|
||||
|
|
|
@ -72,14 +72,13 @@ The post-state corresponding to a pre-state `shard_state` and a signed block `si
|
|||
def shard_state_transition(shard_state: ShardState,
|
||||
signed_block: SignedShardBlock,
|
||||
beacon_parent_state: BeaconState,
|
||||
validate_result: bool = True) -> ShardState:
|
||||
validate_result: bool = True) -> None:
|
||||
assert verify_shard_block_message(beacon_parent_state, shard_state, signed_block.message)
|
||||
|
||||
if validate_result:
|
||||
assert verify_shard_block_signature(beacon_parent_state, signed_block)
|
||||
|
||||
process_shard_block(shard_state, signed_block.message)
|
||||
return shard_state
|
||||
```
|
||||
|
||||
```python
|
||||
|
|
Loading…
Reference in New Issue