mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-01 05:14:49 +00:00
PR feedback from danny: simplify verify_shard_block_message
params
This commit is contained in:
parent
7e67aaeb35
commit
e03a970eaf
@ -169,7 +169,7 @@ def on_shard_block(store: Store, shard_store: ShardStore, signed_shard_block: Si
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Check the block is valid and compute the post-state
|
# Check the block is valid and compute the post-state
|
||||||
assert verify_shard_block_message(beacon_parent_state, shard_parent_state, shard_block, shard_block.slot, shard)
|
assert verify_shard_block_message(beacon_parent_state, shard_parent_state, shard_block)
|
||||||
assert verify_shard_block_signature(beacon_parent_state, signed_shard_block)
|
assert verify_shard_block_signature(beacon_parent_state, signed_shard_block)
|
||||||
|
|
||||||
post_state = get_post_shard_state(beacon_parent_state, shard_parent_state, shard_block)
|
post_state = get_post_shard_state(beacon_parent_state, shard_parent_state, shard_block)
|
||||||
|
@ -43,27 +43,26 @@ def compute_shard_transition_digest(beacon_parent_state: BeaconState,
|
|||||||
### Shard block verification functions
|
### Shard block verification functions
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def verify_shard_block_message(beacon_state: BeaconState,
|
def verify_shard_block_message(beacon_parent_state: BeaconState,
|
||||||
shard_parent_state: ShardState,
|
shard_parent_state: ShardState,
|
||||||
block: ShardBlock,
|
block: ShardBlock) -> bool:
|
||||||
slot: Slot,
|
|
||||||
shard: Shard) -> bool:
|
|
||||||
# Check `shard_parent_root` field
|
# Check `shard_parent_root` field
|
||||||
assert block.shard_parent_root == shard_parent_state.latest_block_root
|
assert block.shard_parent_root == shard_parent_state.latest_block_root
|
||||||
# Check `beacon_parent_root` field
|
# Check `beacon_parent_root` field
|
||||||
beacon_parent_block_header = beacon_state.latest_block_header.copy()
|
beacon_parent_block_header = beacon_parent_state.latest_block_header.copy()
|
||||||
if beacon_parent_block_header.state_root == Root():
|
if beacon_parent_block_header.state_root == Root():
|
||||||
beacon_parent_block_header.state_root = hash_tree_root(beacon_state)
|
beacon_parent_block_header.state_root = hash_tree_root(beacon_parent_state)
|
||||||
beacon_parent_root = hash_tree_root(beacon_parent_block_header)
|
beacon_parent_root = hash_tree_root(beacon_parent_block_header)
|
||||||
assert block.beacon_parent_root == beacon_parent_root
|
assert block.beacon_parent_root == beacon_parent_root
|
||||||
# Check `slot` field
|
# Check `slot` field
|
||||||
next_slot = Slot(slot + 1)
|
shard = block.shard
|
||||||
offset_slots = compute_offset_slots(get_latest_slot_for_shard(beacon_state, shard), next_slot)
|
next_slot = Slot(block.slot + 1)
|
||||||
assert slot in offset_slots
|
offset_slots = compute_offset_slots(get_latest_slot_for_shard(beacon_parent_state, shard), next_slot)
|
||||||
|
assert block.slot in offset_slots
|
||||||
# Check `shard` field
|
# Check `shard` field
|
||||||
assert block.shard == shard
|
assert block.shard == shard
|
||||||
# Check `proposer_index` field
|
# Check `proposer_index` field
|
||||||
assert block.proposer_index == get_shard_proposer_index(beacon_state, slot, shard)
|
assert block.proposer_index == get_shard_proposer_index(beacon_parent_state, block.slot, shard)
|
||||||
# Check `body` field
|
# Check `body` field
|
||||||
assert 0 < len(block.body) <= MAX_SHARD_BLOCK_SIZE
|
assert 0 < len(block.body) <= MAX_SHARD_BLOCK_SIZE
|
||||||
return True
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user