Change get_shuffling to compute_committee

See #729 and #774 

The behavior now is that the first committee will consist of `get_permuted_index(0..n-1)`, the second committee `get_permuted_index(n....2n-1)`, etc.
This commit is contained in:
vbuterin 2019-03-14 20:28:44 -05:00 committed by GitHub
parent 15bf3c4258
commit 24468de23b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 27 deletions

View File

@ -63,7 +63,7 @@
- [`get_permuted_index`](#get_permuted_index) - [`get_permuted_index`](#get_permuted_index)
- [`split`](#split) - [`split`](#split)
- [`get_epoch_committee_count`](#get_epoch_committee_count) - [`get_epoch_committee_count`](#get_epoch_committee_count)
- [`get_shuffling`](#get_shuffling) - [`compute_committee`](#compute_committee)
- [`get_previous_epoch_committee_count`](#get_previous_epoch_committee_count) - [`get_previous_epoch_committee_count`](#get_previous_epoch_committee_count)
- [`get_current_epoch_committee_count`](#get_current_epoch_committee_count) - [`get_current_epoch_committee_count`](#get_current_epoch_committee_count)
- [`get_next_epoch_committee_count`](#get_next_epoch_committee_count) - [`get_next_epoch_committee_count`](#get_next_epoch_committee_count)
@ -803,28 +803,26 @@ def get_epoch_committee_count(active_validator_count: int) -> int:
) * SLOTS_PER_EPOCH ) * SLOTS_PER_EPOCH
``` ```
### `get_shuffling` ### `compute_committee`
```python ```python
def get_shuffling(seed: Bytes32, def compute_committee(validator_indices: [int],
validators: List[Validator], seed: Bytes32,
epoch: Epoch) -> List[List[ValidatorIndex]]: index: int,
total_committees: int) -> List[ValidatorIndex]:
""" """
Shuffle active validators and split into crosslink committees. Return the index'th shuffled committee out of a total `total_committees`
Return a list of committees (each a list of validator indices). using the given validator_indices and seed
""" """
# Shuffle active validator indices start_offset = get_split_offset(len(validator_indices), total_committees, index)
active_validator_indices = get_active_validator_indices(validators, epoch) end_offset = get_split_offset(len(validator_indices), total_committees, index + 1)
length = len(active_validator_indices) return [
shuffled_indices = [active_validator_indices[get_permuted_index(i, length, seed)] for i in range(length)] validator_indices[get_permuted_index(i, len(validator_indices), seed)]
for i in range(start_offset, end_offset)
# Split the shuffled active validator indices ]
return split(shuffled_indices, get_epoch_committee_count(length))
``` ```
**Invariant**: if `get_shuffling(seed, validators, epoch)` returns some value `x` for some `epoch <= get_current_epoch(state) + ACTIVATION_EXIT_DELAY`, it should return the same value `x` for the same `seed` and `epoch` and possible future modifications of `validators` forever in phase 0, and until the ~1 year deletion delay in phase 2 and in the future. **Note**: this definition and the next few definitions are highly inefficient as algorithms as they re-calculate many sub-expressions. Production implementations are expected to appropriately use caching/memoization to avoid redoing work.
**Note**: this definition and the next few definitions make heavy use of repetitive computing. Production implementations are expected to appropriately use caching/memoization to avoid redoing work.
### `get_previous_epoch_committee_count` ### `get_previous_epoch_committee_count`
@ -916,22 +914,17 @@ def get_crosslink_committees_at_slot(state: BeaconState,
shuffling_epoch = state.current_shuffling_epoch shuffling_epoch = state.current_shuffling_epoch
shuffling_start_shard = state.current_shuffling_start_shard shuffling_start_shard = state.current_shuffling_start_shard
shuffling = get_shuffling( indices = get_active_validator_indices(state.validator_registry, shuffling_epoch)
seed, committee_count = get_epoch_committee_count(len(indices))
state.validator_registry, committees_per_slot = committee_count // EPOCH_LENGTH
shuffling_epoch,
)
offset = slot % SLOTS_PER_EPOCH
committees_per_slot = committees_per_epoch // SLOTS_PER_EPOCH
slot_start_shard = (shuffling_start_shard + committees_per_slot * offset) % SHARD_COUNT
return [ return [
( (
shuffling[committees_per_slot * offset + i], compute_committee(indices, seed, committees_per_slot * offset + i, committee_count)
(slot_start_shard + i) % SHARD_COUNT, (slot_start_shard + i) % SHARD_COUNT,
) )
for i in range(committees_per_slot) for i in range(committees_per_slot)
] ]
``` ```
### `get_block_root` ### `get_block_root`