mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-04 02:04:28 +00:00
Make separate errors for epoch cache.
Helps with troubleshooting.
This commit is contained in:
parent
816c2c651b
commit
979353f136
@ -1,13 +1,12 @@
|
|||||||
use self::epoch_cache::EpochCache;
|
use self::epoch_cache::{EpochCache, Error as EpochCacheError};
|
||||||
use crate::test_utils::TestRandom;
|
use crate::test_utils::TestRandom;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use int_to_bytes::int_to_bytes32;
|
use int_to_bytes::int_to_bytes32;
|
||||||
use pubkey_cache::PubkeyCache;
|
use pubkey_cache::PubkeyCache;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use ssz::{hash, ssz_encode, SignedRoot, TreeHash};
|
use ssz::{hash, ssz_encode, TreeHash};
|
||||||
use ssz_derive::{Decode, Encode, TreeHash};
|
use ssz_derive::{Decode, Encode, TreeHash};
|
||||||
use std::collections::HashMap;
|
|
||||||
use test_random_derive::TestRandom;
|
use test_random_derive::TestRandom;
|
||||||
|
|
||||||
mod epoch_cache;
|
mod epoch_cache;
|
||||||
@ -44,6 +43,7 @@ pub enum Error {
|
|||||||
registry_len: usize,
|
registry_len: usize,
|
||||||
},
|
},
|
||||||
RelativeEpochError(RelativeEpochError),
|
RelativeEpochError(RelativeEpochError),
|
||||||
|
EpochCacheError(EpochCacheError),
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! safe_add_assign {
|
macro_rules! safe_add_assign {
|
||||||
@ -883,3 +883,9 @@ impl From<RelativeEpochError> for Error {
|
|||||||
Error::RelativeEpochError(e)
|
Error::RelativeEpochError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<EpochCacheError> for Error {
|
||||||
|
fn from(e: EpochCacheError) -> Error {
|
||||||
|
Error::EpochCacheError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
use super::{BeaconState, Error};
|
use super::BeaconState;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use honey_badger_split::SplitExt;
|
use honey_badger_split::SplitExt;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use swap_or_not_shuffle::shuffle_list;
|
use swap_or_not_shuffle::shuffle_list;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum Error {
|
||||||
|
UnableToShuffle,
|
||||||
|
NoValidators { epoch: Epoch },
|
||||||
|
UnableToGenerateSeed,
|
||||||
|
}
|
||||||
|
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
|
||||||
@ -212,7 +219,7 @@ impl EpochCrosslinkCommitteesBuilder {
|
|||||||
active_validator_indices: Vec<usize>,
|
active_validator_indices: Vec<usize>,
|
||||||
registry_change: bool,
|
registry_change: bool,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<Self, BeaconStateError> {
|
) -> Result<Self, Error> {
|
||||||
let current_epoch = state.current_epoch(spec);
|
let current_epoch = state.current_epoch(spec);
|
||||||
let next_epoch = state.next_epoch(spec);
|
let next_epoch = state.next_epoch(spec);
|
||||||
let committees_per_epoch = spec.get_epoch_committee_count(active_validator_indices.len());
|
let committees_per_epoch = spec.get_epoch_committee_count(active_validator_indices.len());
|
||||||
@ -221,7 +228,9 @@ impl EpochCrosslinkCommitteesBuilder {
|
|||||||
current_epoch - state.validator_registry_update_epoch;
|
current_epoch - state.validator_registry_update_epoch;
|
||||||
|
|
||||||
let (seed, shuffling_start_shard) = if registry_change {
|
let (seed, shuffling_start_shard) = if registry_change {
|
||||||
let next_seed = state.generate_seed(next_epoch, spec)?;
|
let next_seed = state
|
||||||
|
.generate_seed(next_epoch, spec)
|
||||||
|
.map_err(|_| Error::UnableToGenerateSeed)?;
|
||||||
(
|
(
|
||||||
next_seed,
|
next_seed,
|
||||||
(state.current_shuffling_start_shard + committees_per_epoch) % spec.shard_count,
|
(state.current_shuffling_start_shard + committees_per_epoch) % spec.shard_count,
|
||||||
@ -229,7 +238,9 @@ impl EpochCrosslinkCommitteesBuilder {
|
|||||||
} else if (epochs_since_last_registry_update > 1)
|
} else if (epochs_since_last_registry_update > 1)
|
||||||
& epochs_since_last_registry_update.is_power_of_two()
|
& epochs_since_last_registry_update.is_power_of_two()
|
||||||
{
|
{
|
||||||
let next_seed = state.generate_seed(next_epoch, spec)?;
|
let next_seed = state
|
||||||
|
.generate_seed(next_epoch, spec)
|
||||||
|
.map_err(|_| Error::UnableToGenerateSeed)?;
|
||||||
(next_seed, state.current_shuffling_start_shard)
|
(next_seed, state.current_shuffling_start_shard)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
@ -247,9 +258,9 @@ impl EpochCrosslinkCommitteesBuilder {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self, spec: &ChainSpec) -> Result<EpochCrosslinkCommittees, BeaconStateError> {
|
pub fn build(self, spec: &ChainSpec) -> Result<EpochCrosslinkCommittees, Error> {
|
||||||
if self.active_validator_indices.is_empty() {
|
if self.active_validator_indices.is_empty() {
|
||||||
return Err(Error::NoValidators);
|
return Err(Error::NoValidators { epoch: self.epoch });
|
||||||
}
|
}
|
||||||
|
|
||||||
let shuffled_active_validator_indices = shuffle_list(
|
let shuffled_active_validator_indices = shuffle_list(
|
||||||
|
Loading…
Reference in New Issue
Block a user