Remove shard_count from ChainSpec

This commit is contained in:
Paul Hauner 2019-05-20 14:00:47 +10:00
parent 7ea1c4bb12
commit 2fd45e093c
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
4 changed files with 23 additions and 23 deletions

View File

@ -14,6 +14,23 @@ pub trait EthSpec:
fn spec() -> ChainSpec;
/// Return the number of committees in one epoch.
///
/// Spec v0.6.1
fn get_epoch_committee_count(active_validator_count: usize) -> usize {
let target_committee_size = Self::spec().target_committee_size;
let shard_count = Self::shard_count();
let slots_per_epoch = Self::slots_per_epoch() as usize;
std::cmp::max(
1,
std::cmp::min(
shard_count / slots_per_epoch,
active_validator_count / slots_per_epoch / target_committee_size,
),
) * slots_per_epoch
}
/// Returns the minimum number of validators required for this spec.
///
/// This is the _absolute_ minimum, the number required to make the chain operate in the most

View File

@ -43,14 +43,13 @@ impl EpochCache {
return Err(BeaconStateError::InsufficientValidators);
}
let committee_count =
spec.get_epoch_committee_count(active_validator_indices.len()) as usize;
let committee_count = T::get_epoch_committee_count(active_validator_indices.len()) as usize;
let shuffling_start_shard = match relative_epoch {
RelativeEpoch::Current => state.latest_start_shard,
RelativeEpoch::Previous => {
let committees_in_previous_epoch =
spec.get_epoch_committee_count(active_validator_indices.len());
T::get_epoch_committee_count(active_validator_indices.len()) as u64;
(state.latest_start_shard + T::shard_count() as u64 - committees_in_previous_epoch)
% T::shard_count() as u64
@ -59,9 +58,9 @@ impl EpochCache {
let current_active_validators =
get_active_validator_count(&state.validator_registry, state.current_epoch());
let committees_in_current_epoch =
spec.get_epoch_committee_count(current_active_validators);
T::get_epoch_committee_count(current_active_validators) as u64;
(state.latest_start_shard + committees_in_current_epoch) % T::shard_count as u64
(state.latest_start_shard + committees_in_current_epoch) % T::shard_count() as u64
}
};

View File

@ -266,7 +266,7 @@ mod committees {
fn committee_consistency_test_suite<T: EthSpec>(cached_epoch: RelativeEpoch) {
let spec = T::spec();
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
let validator_count = (T::shard_count() * spec.target_committee_size) + 1;
committee_consistency_test::<T>(validator_count as usize, Epoch::new(0), cached_epoch);

View File

@ -24,8 +24,7 @@ pub struct ChainSpec {
/*
* Misc
*/
pub shard_count: u64,
pub target_committee_size: u64,
pub target_committee_size: usize,
pub max_indices_per_attestation: u64,
pub min_per_epoch_churn_limit: u64,
pub churn_limit_quotient: u64,
@ -113,19 +112,6 @@ pub struct ChainSpec {
}
impl ChainSpec {
/// Return the number of committees in one epoch.
///
/// Spec v0.6.1
pub fn get_epoch_committee_count(&self, active_validator_count: usize) -> u64 {
std::cmp::max(
1,
std::cmp::min(
self.shard_count / self.slots_per_epoch,
active_validator_count as u64 / self.slots_per_epoch / self.target_committee_size,
),
) * self.slots_per_epoch
}
/// Get the domain number that represents the fork meta and signature domain.
///
/// Spec v0.6.1
@ -156,7 +142,6 @@ impl ChainSpec {
/*
* Misc
*/
shard_count: 1_024,
target_committee_size: 128,
max_indices_per_attestation: 4096,
min_per_epoch_churn_limit: 4,
@ -263,7 +248,6 @@ impl ChainSpec {
let genesis_epoch = genesis_slot.epoch(slots_per_epoch);
Self {
shard_count: 8,
target_committee_size: 1,
genesis_slot,
genesis_epoch,