diff --git a/beacon_chain/validator_induction/src/inductor.rs b/beacon_chain/validator_induction/src/inductor.rs index c86fce9e6..d26e71bc3 100644 --- a/beacon_chain/validator_induction/src/inductor.rs +++ b/beacon_chain/validator_induction/src/inductor.rs @@ -19,7 +19,7 @@ pub enum ValidatorInductionError { } impl ValidatorInductor { - pub fn new(current_slot: u64, shard_count: u16, validators: Vec) -> Self { + pub fn new(current_slot: u64, shard_count: u64, validators: Vec) -> Self { Self { current_slot, shard_count, diff --git a/beacon_chain/validator_shuffling/Cargo.toml b/beacon_chain/validator_shuffling/Cargo.toml index 269b5c557..b6c35ec3f 100644 --- a/beacon_chain/validator_shuffling/Cargo.toml +++ b/beacon_chain/validator_shuffling/Cargo.toml @@ -6,5 +6,6 @@ authors = ["Paul Hauner "] [dependencies] active-validators = { path = "../utils/active-validators" } honey-badger-split = { path = "../utils/honey-badger-split" } +spec = { path = "../spec" } types = { path = "../types" } vec_shuffle = { path = "../utils/vec_shuffle" } diff --git a/beacon_chain/validator_shuffling/src/lib.rs b/beacon_chain/validator_shuffling/src/lib.rs index fe2447fc0..61cc02bf1 100644 --- a/beacon_chain/validator_shuffling/src/lib.rs +++ b/beacon_chain/validator_shuffling/src/lib.rs @@ -1,5 +1,6 @@ extern crate active_validators; extern crate honey_badger_split; +extern crate spec; extern crate types; extern crate vec_shuffle; diff --git a/beacon_chain/validator_shuffling/src/shuffle.rs b/beacon_chain/validator_shuffling/src/shuffle.rs index 3009f4cbd..3b3009e5d 100644 --- a/beacon_chain/validator_shuffling/src/shuffle.rs +++ b/beacon_chain/validator_shuffling/src/shuffle.rs @@ -2,7 +2,8 @@ use std::cmp::min; use active_validators::active_validator_indices; use honey_badger_split::SplitExt; -use types::{ChainConfig, ShardAndCommittee, ValidatorRecord}; +use spec::ChainSpec; +use types::{ShardAndCommittee, ValidatorRecord}; use vec_shuffle::{shuffle, ShuffleErr}; type DelegatedCycle = Vec>; @@ -21,21 +22,21 @@ pub fn shard_and_committees_for_cycle( seed: &[u8], validators: &[ValidatorRecord], crosslinking_shard_start: u16, - config: &ChainConfig, + spec: &ChainSpec, ) -> Result { let shuffled_validator_indices = { let mut validator_indices = active_validator_indices(validators); shuffle(seed, validator_indices)? }; - let shard_indices: Vec = (0_usize..config.shard_count as usize).into_iter().collect(); + let shard_indices: Vec = (0_usize..spec.shard_count as usize).into_iter().collect(); let crosslinking_shard_start = crosslinking_shard_start as usize; - let cycle_length = config.cycle_length as usize; - let min_committee_size = config.min_committee_size as usize; + let epoch_length = spec.epoch_length as usize; + let min_committee_size = spec.target_committee_size as usize; generate_cycle( &shuffled_validator_indices, &shard_indices, crosslinking_shard_start, - cycle_length, + epoch_length, min_committee_size, ) } @@ -45,29 +46,29 @@ fn generate_cycle( validator_indices: &[usize], shard_indices: &[usize], crosslinking_shard_start: usize, - cycle_length: usize, + epoch_length: usize, min_committee_size: usize, ) -> Result { let validator_count = validator_indices.len(); let shard_count = shard_indices.len(); - if shard_count / cycle_length == 0 { + if shard_count / epoch_length == 0 { return Err(ValidatorAssignmentError::TooFewShards); } let (committees_per_slot, slots_per_committee) = { - if validator_count >= cycle_length * min_committee_size { + if validator_count >= epoch_length * min_committee_size { let committees_per_slot = min( - validator_count / cycle_length / (min_committee_size * 2) + 1, - shard_count / cycle_length, + validator_count / epoch_length / (min_committee_size * 2) + 1, + shard_count / epoch_length, ); let slots_per_committee = 1; (committees_per_slot, slots_per_committee) } else { let committees_per_slot = 1; let mut slots_per_committee = 1; - while (validator_count * slots_per_committee < cycle_length * min_committee_size) - & (slots_per_committee < cycle_length) + while (validator_count * slots_per_committee < epoch_length * min_committee_size) + & (slots_per_committee < epoch_length) { slots_per_committee *= 2; } @@ -76,7 +77,7 @@ fn generate_cycle( }; let cycle = validator_indices - .honey_badger_split(cycle_length) + .honey_badger_split(epoch_length) .enumerate() .map(|(i, slot_indices)| { let shard_start = @@ -108,7 +109,7 @@ mod tests { validator_count: &usize, shard_count: &usize, crosslinking_shard_start: usize, - cycle_length: usize, + epoch_length: usize, min_committee_size: usize, ) -> ( Vec, @@ -121,7 +122,7 @@ mod tests { &validator_indices, &shard_indices, crosslinking_shard_start, - cycle_length, + epoch_length, min_committee_size, ); (validator_indices, shard_indices, result) @@ -183,13 +184,13 @@ mod tests { let validator_count: usize = 100; let shard_count: usize = 20; let crosslinking_shard_start: usize = 0; - let cycle_length: usize = 20; + let epoch_length: usize = 20; let min_committee_size: usize = 10; let (validators, shards, result) = generate_cycle_helper( &validator_count, &shard_count, crosslinking_shard_start, - cycle_length, + epoch_length, min_committee_size, ); let cycle = result.unwrap(); @@ -242,13 +243,13 @@ mod tests { let validator_count: usize = 523; let shard_count: usize = 31; let crosslinking_shard_start: usize = 0; - let cycle_length: usize = 11; + let epoch_length: usize = 11; let min_committee_size: usize = 5; let (validators, shards, result) = generate_cycle_helper( &validator_count, &shard_count, crosslinking_shard_start, - cycle_length, + epoch_length, min_committee_size, ); let cycle = result.unwrap();