Ensure per_epoch processing always runs.

Previously, it was running _after_ a state transition, not before it
with the slot processing.
This commit is contained in:
Paul Hauner
2019-01-31 16:39:44 +11:00
parent ae39a24e71
commit 8073296f5d
5 changed files with 44 additions and 21 deletions

View File

@@ -22,6 +22,7 @@ pub use self::attestation_participants::Error as AttestationParticipantsError;
pub use self::attestation_validation::Error as AttestationValidationError;
pub use self::committees::Error as CommitteesError;
pub use self::epoch_processing::Error as EpochProcessingError;
pub use self::slot_processing::Error as SlotProcessingError;
// Custody will not be added to the specs until Phase 1 (Sharding Phase) so dummy class used.
type CustodyChallenge = usize;

View File

@@ -1,11 +1,21 @@
use crate::{beacon_state::CommitteesError, BeaconState, ChainSpec, Hash256};
use crate::{
beacon_state::{CommitteesError, EpochProcessingError},
BeaconState, ChainSpec, Hash256,
};
use log::debug;
#[derive(Debug, PartialEq)]
pub enum Error {
CommitteesError(CommitteesError),
EpochProcessingError(EpochProcessingError),
}
impl BeaconState {
pub fn per_slot_processing(
&mut self,
previous_block_root: Hash256,
spec: &ChainSpec,
) -> Result<(), CommitteesError> {
) -> Result<(), Error> {
self.slot += 1;
let block_proposer = self.get_beacon_proposer_index(self.slot, spec)?;
@@ -22,6 +32,10 @@ impl BeaconState {
let root = merkle_root(&self.latest_block_roots[..]);
self.batched_block_roots.push(root);
}
if self.slot % spec.epoch_length == 0 {
self.per_epoch_processing(spec)?;
}
Ok(())
}
@@ -45,3 +59,15 @@ impl BeaconState {
fn merkle_root(_input: &[Hash256]) -> Hash256 {
Hash256::zero()
}
impl From<CommitteesError> for Error {
fn from(e: CommitteesError) -> Error {
Error::CommitteesError(e)
}
}
impl From<EpochProcessingError> for Error {
fn from(e: EpochProcessingError) -> Error {
Error::EpochProcessingError(e)
}
}