mirror of
https://github.com/ethereum/consensus-specs.git
synced 2026-02-03 04:54:57 -05:00
Revert exception handling
This commit is contained in:
@@ -1216,19 +1216,15 @@ Let `genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))`.
|
||||
|
||||
## Beacon chain state transition function
|
||||
|
||||
The post-state corresponding to a pre-state `state` and a block `block` is defined as `state_transition(state, block)`.
|
||||
The post-state corresponding to a pre-state `state` and a block `block` is defined as `state_transition(state, block)`. State transitions that trigger an unhandled excpetion (e.g. a failed `assert` or an out-of-range list access) are considered invalid.
|
||||
|
||||
```python
|
||||
def state_transition(state: BeaconState, block: BeaconBlock) -> BeaconState:
|
||||
pre_state = copy.deepcopy(state)
|
||||
try:
|
||||
# Process slots (including those with no blocks) since block
|
||||
process_slots(state, block.slot)
|
||||
# Process block
|
||||
process_block(state, block)
|
||||
except Exception:
|
||||
# State is not advanced on exceptions (e.g. a failed `assert` or an out-of-range list access)
|
||||
return pre_state
|
||||
# Process slots (including those with no blocks) since block
|
||||
process_slots(state, block.slot)
|
||||
# Process block
|
||||
process_block(state, block)
|
||||
# Return post-state
|
||||
return state
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user