Implement HW's exception-handling suggestion
This commit is contained in:
parent
f371daeb20
commit
50009ea85b
|
@ -6,6 +6,7 @@ def build_phase0_spec(sourcefile, outfile):
|
|||
code_lines = []
|
||||
code_lines.append("""
|
||||
|
||||
import copy
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
|
|
|
@ -1262,16 +1262,21 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit],
|
|||
|
||||
## 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)`. State transitions that trigger an unhandled exception (e.g. a failed `assert` or an out-of-range list access) are considered invalid.
|
||||
The post-state corresponding to a pre-state `state` and a block `block` is defined as `state_transition(state, block)`.
|
||||
|
||||
```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)
|
||||
# Return post-state
|
||||
except Exception:
|
||||
# State is not advanced on exceptions (e.g. a failed `assert` or an out-of-range list access)
|
||||
return pre_state
|
||||
return state
|
||||
|
||||
```
|
||||
|
||||
```python
|
||||
|
|
Loading…
Reference in New Issue