Fix error with get_permutated_index.

Error types were modified. Error involved shuffling with the _value_of
active validator indicies, not an _index_.
This commit is contained in:
Paul Hauner 2019-02-26 16:26:06 +13:00
parent 59d6b1fdd0
commit 53663e54b5
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -7,7 +7,7 @@ use crate::{
};
use bls::verify_proof_of_possession;
use honey_badger_split::SplitExt;
use log::{debug, trace};
use log::{debug, trace, error};
use rand::RngCore;
use serde_derive::Serialize;
use ssz::{hash, Decodable, DecodeError, Encodable, SszStream, TreeHash};
@ -387,12 +387,13 @@ impl BeaconState {
seed: Hash256,
epoch: Epoch,
spec: &ChainSpec,
) -> Option<Vec<Vec<usize>>> {
) -> Result<Vec<Vec<usize>>, Error> {
let active_validator_indices =
get_active_validator_indices(&self.validator_registry, epoch);
if active_validator_indices.is_empty() {
return None;
error!("get_shuffling: no validators.");
return Err(Error::InsufficientValidators);
}
let committees_per_epoch =
@ -405,22 +406,21 @@ impl BeaconState {
);
let mut shuffled_active_validator_indices = vec![0; active_validator_indices.len()];
for &i in &active_validator_indices {
for (i, _) in active_validator_indices.iter().enumerate() {
let shuffled_i = get_permutated_index(
i,
active_validator_indices.len(),
&seed[..],
spec.shuffle_round_count,
)?;
)
.ok_or_else(|| Error::UnableToShuffle)?;
shuffled_active_validator_indices[i] = active_validator_indices[shuffled_i]
}
Some(
shuffled_active_validator_indices
Ok(shuffled_active_validator_indices
.honey_badger_split(committees_per_epoch as usize)
.map(|slice: &[usize]| slice.to_vec())
.collect(),
)
.collect())
}
/// Return the number of committees in the previous epoch.
@ -525,7 +525,6 @@ impl BeaconState {
self.get_committee_params_at_slot(slot, registry_change, spec)?;
self.get_shuffling(seed, shuffling_epoch, spec)
.ok_or_else(|| Error::UnableToShuffle)
}
/// Returns the following params for the given slot: