Move block timing assertion 1st

This commit is contained in:
Carl Beekhuizen 2019-06-21 12:19:08 +02:00
parent e88a96c45e
commit f90469ea25
No known key found for this signature in database
GPG Key ID: D05CA176D0020646
1 changed files with 2 additions and 1 deletions

View File

@ -140,13 +140,14 @@ def on_tick(store: Store, time: int) -> None:
```python ```python
def on_block(store: Store, block: BeaconBlock) -> None: def on_block(store: Store, block: BeaconBlock) -> None:
# Blocks cannot be in the future. If they are, their consideration must be delayed until the are in the past.
assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
# Add new block to the store # Add new block to the store
store.blocks[signing_root(block)] = block store.blocks[signing_root(block)] = block
# Check block is a descendant of the finalized block # Check block is a descendant of the finalized block
assert get_ancestor(store, signing_root(block), store.blocks[store.finalized_root].slot) == store.finalized_root assert get_ancestor(store, signing_root(block), store.blocks[store.finalized_root].slot) == store.finalized_root
# Check block slot against Unix time # Check block slot against Unix time
pre_state = store.states[block.parent_root].copy() pre_state = store.states[block.parent_root].copy()
assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
# Check the block is valid and compute the post-state # Check the block is valid and compute the post-state
state = state_transition(pre_state, block) state = state_transition(pre_state, block)
# Add new state to the store # Add new state to the store