Reorg `shard_state_transition` argument and fix `get_shard_transition_fields`

This commit is contained in:
Hsiao-Wei Wang 2020-06-22 23:41:02 +08:00
parent 4f618fc62d
commit eec1442417
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
3 changed files with 9 additions and 8 deletions

View File

@ -170,7 +170,7 @@ def on_shard_block(store: Store, shard_store: ShardStore, signed_shard_block: Si
# Check the block is valid and compute the post-state
shard_state = shard_parent_state.copy()
shard_state_transition(beacon_parent_state, shard_state, shard_block)
shard_state_transition(shard_state, shard_block, validate_message=True, beacon_parent_state=beacon_parent_state)
# Add new block to the store
shard_store.blocks[hash_tree_root(shard_block)] = shard_block

View File

@ -61,11 +61,12 @@ def verify_shard_block_signature(beacon_state: BeaconState,
## Shard state transition
```python
def shard_state_transition(beacon_parent_state: BeaconState,
shard_state: ShardState,
def shard_state_transition(shard_state: ShardState,
block: ShardBlock,
validate_message: bool = True) -> bool:
validate_message: bool = True,
beacon_parent_state: Optional[BeaconState] = None) -> bool:
if validate_message:
assert beacon_parent_state is not None
assert verify_shard_block_message(beacon_parent_state, shard_state, block)
process_shard_block(shard_state, block)
@ -126,7 +127,7 @@ def is_valid_fraud_proof(beacon_state: BeaconState,
else:
shard_state = transition.shard_states[offset_index - 1] # Not doing the actual state updates here.
shard_state_transition(beacon_state, shard_state, block, validate_message=False)
shard_state_transition(shard_state, block, validate_message=False)
if shard_state != transition.shard_states[offset_index]:
return True

View File

@ -280,13 +280,12 @@ def get_shard_transition_fields(
beacon_state: BeaconState,
shard: Shard,
shard_blocks: Sequence[SignedShardBlock],
validate_signature: bool=True,
) -> Tuple[Sequence[uint64], Sequence[Root], Sequence[ShardState]]:
shard_states = []
shard_data_roots = []
shard_block_lengths = []
shard_state = beacon_state.shard_states[shard].copy()
shard_state = beacon_state.shard_states[shard]
shard_block_slots = [shard_block.message.slot for shard_block in shard_blocks]
offset_slots = compute_offset_slots(
get_latest_slot_for_shard(beacon_state, shard),
@ -299,7 +298,8 @@ def get_shard_transition_fields(
else:
shard_block = SignedShardBlock(message=ShardBlock(slot=slot, shard=shard))
shard_data_roots.append(Root())
shard_state_transition(beacon_state, shard_state, shard_block.message, validate_message=False)
shard_state = shard_state.copy()
shard_state_transition(shard_state, shard_block.message, validate_message=False)
shard_states.append(shard_state)
shard_block_lengths.append(len(shard_block.message.body))