Remove shard_count from ChainSpec
This commit is contained in:
parent
7ea1c4bb12
commit
2fd45e093c
@ -14,6 +14,23 @@ pub trait EthSpec:
|
|||||||
|
|
||||||
fn spec() -> ChainSpec;
|
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.
|
/// 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
|
/// This is the _absolute_ minimum, the number required to make the chain operate in the most
|
||||||
|
@ -43,14 +43,13 @@ impl EpochCache {
|
|||||||
return Err(BeaconStateError::InsufficientValidators);
|
return Err(BeaconStateError::InsufficientValidators);
|
||||||
}
|
}
|
||||||
|
|
||||||
let committee_count =
|
let committee_count = T::get_epoch_committee_count(active_validator_indices.len()) as usize;
|
||||||
spec.get_epoch_committee_count(active_validator_indices.len()) as usize;
|
|
||||||
|
|
||||||
let shuffling_start_shard = match relative_epoch {
|
let shuffling_start_shard = match relative_epoch {
|
||||||
RelativeEpoch::Current => state.latest_start_shard,
|
RelativeEpoch::Current => state.latest_start_shard,
|
||||||
RelativeEpoch::Previous => {
|
RelativeEpoch::Previous => {
|
||||||
let committees_in_previous_epoch =
|
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)
|
(state.latest_start_shard + T::shard_count() as u64 - committees_in_previous_epoch)
|
||||||
% T::shard_count() as u64
|
% T::shard_count() as u64
|
||||||
@ -59,9 +58,9 @@ impl EpochCache {
|
|||||||
let current_active_validators =
|
let current_active_validators =
|
||||||
get_active_validator_count(&state.validator_registry, state.current_epoch());
|
get_active_validator_count(&state.validator_registry, state.current_epoch());
|
||||||
let committees_in_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
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ mod committees {
|
|||||||
fn committee_consistency_test_suite<T: EthSpec>(cached_epoch: RelativeEpoch) {
|
fn committee_consistency_test_suite<T: EthSpec>(cached_epoch: RelativeEpoch) {
|
||||||
let spec = T::spec();
|
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);
|
committee_consistency_test::<T>(validator_count as usize, Epoch::new(0), cached_epoch);
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ pub struct ChainSpec {
|
|||||||
/*
|
/*
|
||||||
* Misc
|
* Misc
|
||||||
*/
|
*/
|
||||||
pub shard_count: u64,
|
pub target_committee_size: usize,
|
||||||
pub target_committee_size: u64,
|
|
||||||
pub max_indices_per_attestation: u64,
|
pub max_indices_per_attestation: u64,
|
||||||
pub min_per_epoch_churn_limit: u64,
|
pub min_per_epoch_churn_limit: u64,
|
||||||
pub churn_limit_quotient: u64,
|
pub churn_limit_quotient: u64,
|
||||||
@ -113,19 +112,6 @@ pub struct ChainSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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.
|
/// Get the domain number that represents the fork meta and signature domain.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.1
|
/// Spec v0.6.1
|
||||||
@ -156,7 +142,6 @@ impl ChainSpec {
|
|||||||
/*
|
/*
|
||||||
* Misc
|
* Misc
|
||||||
*/
|
*/
|
||||||
shard_count: 1_024,
|
|
||||||
target_committee_size: 128,
|
target_committee_size: 128,
|
||||||
max_indices_per_attestation: 4096,
|
max_indices_per_attestation: 4096,
|
||||||
min_per_epoch_churn_limit: 4,
|
min_per_epoch_churn_limit: 4,
|
||||||
@ -263,7 +248,6 @@ impl ChainSpec {
|
|||||||
let genesis_epoch = genesis_slot.epoch(slots_per_epoch);
|
let genesis_epoch = genesis_slot.epoch(slots_per_epoch);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
shard_count: 8,
|
|
||||||
target_committee_size: 1,
|
target_committee_size: 1,
|
||||||
genesis_slot,
|
genesis_slot,
|
||||||
genesis_epoch,
|
genesis_epoch,
|
||||||
|
Loading…
Reference in New Issue
Block a user