Add `shard_block.slot` to seed

This commit is contained in:
Hsiao-Wei Wang 2020-06-04 11:19:04 +08:00
parent c0108afe77
commit 8afb93f5a3
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
1 changed files with 6 additions and 2 deletions

View File

@ -537,9 +537,13 @@ def get_light_client_committee(beacon_state: BeaconState, epoch: Epoch) -> Seque
```python ```python
def get_shard_proposer_index(beacon_state: BeaconState, slot: Slot, shard: Shard) -> ValidatorIndex: def get_shard_proposer_index(beacon_state: BeaconState, slot: Slot, shard: Shard) -> ValidatorIndex:
committee = get_shard_committee(beacon_state, compute_epoch_at_slot(slot), shard) """
Return the proposer's index of shard block at ``slot``.
"""
epoch = compute_epoch_at_slot(slot) epoch = compute_epoch_at_slot(slot)
r = bytes_to_int(get_seed(beacon_state, epoch, DOMAIN_SHARD_COMMITTEE)[:8]) committee = get_shard_committee(beacon_state, epoch, shard)
seed = hash(get_seed(beacon_state, epoch, DOMAIN_SHARD_COMMITTEE) + int_to_bytes(slot, length=8))
r = bytes_to_int(seed[:8])
return committee[r % len(committee)] return committee[r % len(committee)]
``` ```