epoch processing: fix shard delta calculation
This commit is contained in:
parent
49e19e2b7d
commit
c151e5861e
@ -300,11 +300,10 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
|
|
||||||
pub fn next_epoch_start_shard(&self) -> Result<u64, Error> {
|
pub fn next_epoch_start_shard(&self) -> Result<u64, Error> {
|
||||||
let cache = self.cache(RelativeEpoch::Current)?;
|
let cache = self.cache(RelativeEpoch::Current)?;
|
||||||
|
let active_validator_count = cache.active_validator_count();
|
||||||
|
let shard_delta = T::get_shard_delta(active_validator_count);
|
||||||
|
|
||||||
Ok(
|
Ok((self.latest_start_shard + shard_delta) % T::ShardCount::to_u64())
|
||||||
(cache.epoch_start_shard() + cache.epoch_committee_count() as u64)
|
|
||||||
& T::shard_count() as u64,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the slot of an attestation.
|
/// Get the slot of an attestation.
|
||||||
|
@ -29,6 +29,16 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq {
|
|||||||
) * slots_per_epoch
|
) * slots_per_epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the number of shards to increment `state.latest_start_shard` by in a given epoch.
|
||||||
|
///
|
||||||
|
/// Spec v0.6.3
|
||||||
|
fn get_shard_delta(active_validator_count: usize) -> u64 {
|
||||||
|
std::cmp::min(
|
||||||
|
Self::get_epoch_committee_count(active_validator_count) as u64,
|
||||||
|
Self::ShardCount::to_u64() - Self::ShardCount::to_u64() / Self::spec().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
|
||||||
|
@ -49,19 +49,17 @@ impl CommitteeCache {
|
|||||||
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 shard_delta = T::get_shard_delta(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::ShardCount::to_u64() - shard_delta)
|
||||||
% T::shard_count() as u64
|
% T::ShardCount::to_u64()
|
||||||
}
|
}
|
||||||
RelativeEpoch::Next => {
|
RelativeEpoch::Next => {
|
||||||
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 shard_delta = T::get_shard_delta(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 + shard_delta) % T::ShardCount::to_u64()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user