Verify shard_block.slot fits the expected offset_slots
This commit is contained in:
parent
c9a53b8039
commit
727353c054
|
@ -127,7 +127,6 @@ def on_shard_block(store: Store, shard_store: ShardStore, signed_shard_block: Si
|
||||||
|
|
||||||
# Check beacon parent exists
|
# Check beacon parent exists
|
||||||
assert shard_block.beacon_parent_root in store.block_states
|
assert shard_block.beacon_parent_root in store.block_states
|
||||||
beacon_state = store.block_states[shard_block.beacon_parent_root]
|
|
||||||
|
|
||||||
# Check that block is later than the finalized shard state slot (optimization to reduce calls to get_ancestor)
|
# Check that block is later than the finalized shard state slot (optimization to reduce calls to get_ancestor)
|
||||||
finalized_beacon_state = store.block_states[store.finalized_checkpoint.root]
|
finalized_beacon_state = store.block_states[store.finalized_checkpoint.root]
|
||||||
|
@ -144,9 +143,11 @@ def on_shard_block(store: Store, shard_store: ShardStore, signed_shard_block: Si
|
||||||
shard_store.blocks[hash_tree_root(shard_block)] = shard_block
|
shard_store.blocks[hash_tree_root(shard_block)] = shard_block
|
||||||
|
|
||||||
# Check the block is valid and compute the post-state
|
# Check the block is valid and compute the post-state
|
||||||
verify_shard_block_message(beacon_state, pre_shard_state, shard_block, shard_block.slot, shard)
|
beacon_head_root = get_head(store)
|
||||||
verify_shard_block_signature(beacon_state, signed_shard_block)
|
beacon_head_state = store.block_states[beacon_head_root]
|
||||||
post_state = get_post_shard_state(beacon_state, pre_shard_state, shard_block)
|
assert verify_shard_block_message(beacon_head_state, pre_shard_state, shard_block, shard_block.slot, shard)
|
||||||
|
assert verify_shard_block_signature(beacon_head_state, signed_shard_block)
|
||||||
|
post_state = get_post_shard_state(beacon_head_state, pre_shard_state, shard_block)
|
||||||
# Add new state for this block to the store
|
# Add new state for this block to the store
|
||||||
shard_store.block_states[hash_tree_root(shard_block)] = post_state
|
shard_store.block_states[hash_tree_root(shard_block)] = post_state
|
||||||
```
|
```
|
||||||
|
|
|
@ -50,6 +50,9 @@ def verify_shard_block_message(beacon_state: BeaconState,
|
||||||
shard: Shard) -> bool:
|
shard: Shard) -> bool:
|
||||||
assert block.shard_parent_root == shard_state.latest_block_root
|
assert block.shard_parent_root == shard_state.latest_block_root
|
||||||
assert block.slot == slot
|
assert block.slot == slot
|
||||||
|
next_slot = Slot(beacon_state.slot + 1)
|
||||||
|
offset_slots = compute_offset_slots(get_latest_slot_for_shard(beacon_state, shard), next_slot)
|
||||||
|
assert slot in offset_slots
|
||||||
assert block.shard == shard
|
assert block.shard == shard
|
||||||
assert block.proposer_index == get_shard_proposer_index(beacon_state, slot, shard)
|
assert block.proposer_index == get_shard_proposer_index(beacon_state, slot, shard)
|
||||||
assert 0 < len(block.body) <= MAX_SHARD_BLOCK_SIZE
|
assert 0 < len(block.body) <= MAX_SHARD_BLOCK_SIZE
|
||||||
|
|
Loading…
Reference in New Issue