Remove dynasty from delegation fn

This commit is contained in:
Paul Hauner 2018-10-20 02:36:55 +11:00
parent 725741307a
commit f00b39dd3c
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -1,27 +1,26 @@
use super::honey_badger_split::SplitExt; use super::honey_badger_split::SplitExt;
use super::types::{ShardAndCommittee, ValidatorRecord, ChainConfig}; use super::types::{
ShardAndCommittee,
ValidatorRecord,
ValidatorStatus,
ChainConfig,
};
use super::TransitionError; use super::TransitionError;
use super::shuffle; use super::shuffle;
use std::cmp::min; use std::cmp::min;
type DelegatedCycle = Vec<Vec<ShardAndCommittee>>; type DelegatedCycle = Vec<Vec<ShardAndCommittee>>;
/// Produce a vector of validators indicies where those validators start and end /// Returns the indicies of each active validator in a given vec of validators.
/// dynasties are within the supplied `dynasty`. fn active_validator_indicies(validators: &[ValidatorRecord])
fn active_validator_indicies(
dynasty: u64,
validators: &[ValidatorRecord])
-> Vec<usize> -> Vec<usize>
{ {
validators.iter() validators.iter()
.enumerate() .enumerate()
.filter_map(|(i, validator)| { .filter_map(|(i, validator)| {
if (validator.start_dynasty >= dynasty) & match validator.status {
(validator.end_dynasty < dynasty) x if x == ValidatorStatus::Active as u8 => Some(i),
{ _ => None
Some(i)
} else {
None
} }
}) })
.collect() .collect()
@ -35,13 +34,12 @@ fn active_validator_indicies(
pub fn delegate_validators( pub fn delegate_validators(
seed: &[u8], seed: &[u8],
validators: &[ValidatorRecord], validators: &[ValidatorRecord],
dynasty: u64,
crosslinking_shard_start: u16, crosslinking_shard_start: u16,
config: &ChainConfig) config: &ChainConfig)
-> Result<DelegatedCycle, TransitionError> -> Result<DelegatedCycle, TransitionError>
{ {
let shuffled_validator_indices = { let shuffled_validator_indices = {
let mut validator_indices = active_validator_indicies(dynasty, validators); let mut validator_indices = active_validator_indicies(validators);
match shuffle(seed, validator_indices) { match shuffle(seed, validator_indices) {
Ok(shuffled) => shuffled, Ok(shuffled) => shuffled,
_ => return Err(TransitionError::InvalidInput( _ => return Err(TransitionError::InvalidInput(