mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-04 02:04:28 +00:00
Allow epoch cache with zero validators.
This commit is contained in:
parent
979353f136
commit
191761f356
@ -3,11 +3,8 @@ use hashing::hash;
|
|||||||
use merkle_proof::verify_merkle_proof;
|
use merkle_proof::verify_merkle_proof;
|
||||||
use ssz::ssz_encode;
|
use ssz::ssz_encode;
|
||||||
use ssz_derive::Encode;
|
use ssz_derive::Encode;
|
||||||
use std::collections::HashMap;
|
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
pub type PublicKeyValidatorIndexHashmap = HashMap<PublicKey, u64>;
|
|
||||||
|
|
||||||
/// Indicates if a `Deposit` is valid to be included in a block in the current epoch of the given
|
/// Indicates if a `Deposit` is valid to be included in a block in the current epoch of the given
|
||||||
/// state.
|
/// state.
|
||||||
///
|
///
|
||||||
|
@ -14,7 +14,7 @@ pub fn process_validator_registry(state: &mut BeaconState, spec: &ChainSpec) ->
|
|||||||
state.previous_shuffling_seed = state.current_shuffling_seed;
|
state.previous_shuffling_seed = state.current_shuffling_seed;
|
||||||
|
|
||||||
if should_update_validator_registry(state, spec)? {
|
if should_update_validator_registry(state, spec)? {
|
||||||
state.update_validator_registry(spec);
|
state.update_validator_registry(spec)?;
|
||||||
|
|
||||||
state.current_shuffling_epoch = next_epoch;
|
state.current_shuffling_epoch = next_epoch;
|
||||||
state.current_shuffling_start_shard = (state.current_shuffling_start_shard
|
state.current_shuffling_start_shard = (state.current_shuffling_start_shard
|
||||||
@ -37,7 +37,7 @@ pub fn process_validator_registry(state: &mut BeaconState, spec: &ChainSpec) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state.process_slashings(spec);
|
state.process_slashings(spec)?;
|
||||||
state.process_exit_queue(spec);
|
state.process_exit_queue(spec);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -7,7 +7,6 @@ use swap_or_not_shuffle::shuffle_list;
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
UnableToShuffle,
|
UnableToShuffle,
|
||||||
NoValidators { epoch: Epoch },
|
|
||||||
UnableToGenerateSeed,
|
UnableToGenerateSeed,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,17 +258,19 @@ impl EpochCrosslinkCommitteesBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self, spec: &ChainSpec) -> Result<EpochCrosslinkCommittees, Error> {
|
pub fn build(self, spec: &ChainSpec) -> Result<EpochCrosslinkCommittees, Error> {
|
||||||
if self.active_validator_indices.is_empty() {
|
// The shuffler fails on a empty list, so if there are no active validator indices, simply
|
||||||
return Err(Error::NoValidators { epoch: self.epoch });
|
// return an empty list.
|
||||||
}
|
let shuffled_active_validator_indices = if self.active_validator_indices.is_empty() {
|
||||||
|
vec![]
|
||||||
let shuffled_active_validator_indices = shuffle_list(
|
} else {
|
||||||
self.active_validator_indices,
|
shuffle_list(
|
||||||
spec.shuffle_round_count,
|
self.active_validator_indices,
|
||||||
&self.shuffling_seed[..],
|
spec.shuffle_round_count,
|
||||||
true,
|
&self.shuffling_seed[..],
|
||||||
)
|
true,
|
||||||
.ok_or_else(|| Error::UnableToShuffle)?;
|
)
|
||||||
|
.ok_or_else(|| Error::UnableToShuffle)?
|
||||||
|
};
|
||||||
|
|
||||||
let mut committees: Vec<Vec<usize>> = shuffled_active_validator_indices
|
let mut committees: Vec<Vec<usize>> = shuffled_active_validator_indices
|
||||||
.honey_badger_split(self.committees_per_epoch as usize)
|
.honey_badger_split(self.committees_per_epoch as usize)
|
||||||
|
@ -134,7 +134,7 @@ impl TestingBeaconStateBuilder {
|
|||||||
state.validator_registry = validators;
|
state.validator_registry = validators;
|
||||||
state.validator_balances = balances;
|
state.validator_balances = balances;
|
||||||
|
|
||||||
debug!("BeaconState built.");
|
debug!("BeaconState initialized.");
|
||||||
|
|
||||||
Self { state, keypairs }
|
Self { state, keypairs }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user