reformat compute_subnet_for_attestation to not use for loop

This commit is contained in:
Danny Ryan 2020-05-14 13:50:29 -06:00
parent 511f803496
commit 3dd168335b
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
1 changed files with 5 additions and 4 deletions

View File

@ -423,11 +423,12 @@ Finally, the validator broadcasts `attestation` to the associated attestation su
```python
def compute_subnet_for_attestation(state: BeaconState, attestation: Attestation) -> uint64:
"""
Compute the correct subnet for an attestation for Phase 0.
Note, this mimics expected Phase 1 behavior where attestations will be mapped to their shard subnet.
"""
slots_since_epoch_start = attestation.data.slot % SLOTS_PER_EPOCH
committees_since_epoch_start = sum([
get_committee_count_at_slot(state, Slot(slot))
for slot in range(slots_since_epoch_start)
])
committees_since_epoch_start = get_committee_count_at_slot(state, attestation.data.slot) * slots_since_epoch_start
return (committees_since_epoch_start + attestation.data.index) % ATTESTATION_SUBNET_COUNT
```