Expose get_commitee

This commit is contained in:
Justin Drake 2019-05-01 09:09:24 +01:00
parent a6e76ef9c6
commit a0158c606e
2 changed files with 16 additions and 27 deletions

View File

@ -73,6 +73,7 @@
- [`get_beacon_proposer_index`](#get_beacon_proposer_index)
- [`verify_merkle_branch`](#verify_merkle_branch)
- [`get_shuffled_index`](#get_shuffled_index)
- [`get_committee`](#get_committee)
- [`get_crosslink_committee`](#get_crosslink_committee)
- [`get_attesting_indices`](#get_attesting_indices)
- [`int_to_bytes1`, `int_to_bytes2`, ...](#int_to_bytes1-int_to_bytes2-)
@ -907,24 +908,23 @@ def get_shuffled_index(index: ValidatorIndex, index_count: int, seed: Bytes32) -
return index
```
### `get_committee`
```python
def get_committee(state: BeaconState, epoch: Epoch, index: int, count: int) -> List[ValidatorIndex]:
active_indices = get_active_validator_indices(state, epoch)
return [
active_indices[get_shuffled_index(i, len(active_indices), generate_seed(state, epoch))]
for i in range((len(active_indices) * index) // count, (len(active_indices) * (index + 1)) // count)
]
```
### `get_crosslink_committee`
```python
def get_crosslink_committee(state: BeaconState, epoch: Epoch, shard: Shard) -> List[ValidatorIndex]:
"""
Return the crosslink committee at ``epoch`` for ``shard``.
"""
active_indices = get_active_validator_indices(state, epoch)
committee_count = get_epoch_committee_count(state, epoch)
committee_index = (shard + SHARD_COUNT - get_epoch_start_shard(state, epoch)) % SHARD_COUNT
start_validator_index = (len(active_indices) * committee_index) // committee_count
end_validator_index = (len(active_indices) * (committee_index + 1)) // committee_count
seed = generate_seed(state, epoch)
return [
active_indices[get_shuffled_index(i, len(active_indices), seed)]
for i in range(start_validator_index, end_validator_index)
]
return get_committee(state, epoch, committee_index, get_epoch_committee_count(state, epoch))
```
### `get_attesting_indices`

View File

@ -120,22 +120,11 @@ This document describes the shard data layer and the shard fork choice rule in P
### `get_period_committee`
```python
def get_period_committee(state: BeaconState,
shard: Shard,
committee_start_epoch: Epoch,
index: int,
committee_count: int) -> List[ValidatorIndex]:
def get_period_committee(state: BeaconState, epoch: Epoch, shard: Shard, index: int, count: int) -> List[ValidatorIndex]:
"""
Return committee for a period. Used to construct persistent committees.
"""
active_validator_indices = get_active_validator_indices(state.validator_registry, committee_start_epoch)
seed = generate_seed(state, committee_start_epoch)
return compute_committee(
validator_indices=active_validator_indices,
seed=seed,
index=shard * committee_count + index,
total_committees=SHARD_COUNT * committee_count,
)
return get_committee(state, epoch, shard * count + index, SHARD_COUNT * count)
```
### `get_switchover_epoch`
@ -165,7 +154,7 @@ def get_persistent_committee(state: BeaconState,
len(get_active_validator_indices(state.validator_registry, later_start_epoch)) //
(SHARD_COUNT * TARGET_COMMITTEE_SIZE),
) + 1
index = slot % committee_count
earlier_committee = get_period_committee(state, shard, earlier_start_epoch, index, committee_count)
later_committee = get_period_committee(state, shard, later_start_epoch, index, committee_count)