Remove multiple slots per committee option

This commit is contained in:
Vitalik Buterin 2018-10-09 19:26:03 -04:00
parent 18c799a5a2
commit 20e31b2930
No known key found for this signature in database
GPG Key ID: A99D082A6179F987
1 changed files with 11 additions and 11 deletions

View File

@ -348,25 +348,25 @@ def split(lst, N):
return [lst[len(lst)*i//N: len(lst)*(i+1)//N] for i in range(N)]
```
A helper method for readability:
```python
def clamp(minval, x, maxval):
return minval if x < minval else maxval if x > maxval else x
```
Now, our combined helper method:
```python
def get_new_shuffling(seed, validators, crosslinking_start_shard):
active_validators = get_active_validator_indices(validators)
if len(active_validators) >= CYCLE_LENGTH * MIN_COMMITTEE_SIZE:
committees_per_slot = min(len(active_validators) // CYCLE_LENGTH // (MIN_COMMITTEE_SIZE * 2) + 1, SHARD_COUNT // CYCLE_LENGTH)
slots_per_committee = 1
else:
committees_per_slot = 1
slots_per_committee = 1
while len(active_validators) * slots_per_committee < CYCLE_LENGTH * MIN_COMMITTEE_SIZE \
and slots_per_committee < CYCLE_LENGTH:
slots_per_committee *= 2
committees_per_slot = clamp(1,
len(active_validators) // CYCLE_LENGTH // (MIN_COMMITTEE_SIZE * 2) + 1,
SHARD_COUNT // CYCLE_LENGTH)
o = []
for i, slot_indices in enumerate(split(shuffle(active_validators, seed), CYCLE_LENGTH)):
shard_indices = split(slot_indices, committees_per_slot)
shard_start = crosslinking_start_shard + \
i * committees_per_slot // slots_per_committee
shard_start = crosslinking_start_shard + i * committees_per_slot
o.append([ShardAndCommittee(
shard = (shard_start + j) % SHARD_COUNT,
committee = indices