Move advance_slot to its own file.

This commit is contained in:
Paul Hauner 2019-02-01 16:30:42 +11:00
parent db230475d7
commit 942ef4b002
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
3 changed files with 26 additions and 13 deletions

View File

@ -4,7 +4,6 @@ use types::{beacon_state::SlotProcessingError, BeaconBlock, BeaconState, Hash256
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum Error { pub enum Error {
PastSlot,
SlotProcessingError(SlotProcessingError), SlotProcessingError(SlotProcessingError),
} }
@ -32,17 +31,6 @@ where
pub fn head(&self) -> RwLockReadGuard<CheckPoint> { pub fn head(&self) -> RwLockReadGuard<CheckPoint> {
self.canonical_head.read() self.canonical_head.read()
} }
pub fn advance_state(&self, slot: u64) -> Result<(), SlotProcessingError> {
let state_slot = self.state.read().slot;
let head_block_root = self.head().beacon_block_root;
for _ in state_slot..slot {
self.state
.write()
.per_slot_processing(head_block_root.clone(), &self.spec)?;
}
Ok(())
}
} }
impl From<SlotProcessingError> for Error { impl From<SlotProcessingError> for Error {

View File

@ -10,7 +10,7 @@ pub mod dump;
mod finalized_head; mod finalized_head;
mod info; mod info;
mod lmd_ghost; mod lmd_ghost;
// mod state_transition; mod state;
use self::attestation_targets::AttestationTargets; use self::attestation_targets::AttestationTargets;
use self::block_graph::BlockGraph; use self::block_graph::BlockGraph;

View File

@ -0,0 +1,25 @@
use crate::{BeaconChain, ClientDB, SlotClock};
use types::beacon_state::SlotProcessingError;
impl<T, U> BeaconChain<T, U>
where
T: ClientDB,
U: SlotClock,
{
/// Advance the `self.state` `BeaconState` to the supplied slot.
///
/// This will perform per_slot and per_epoch processing as required.
///
/// The `previous_block_root` will be set to the root of the current head block (as determined
/// by the fork-choice rule).
pub fn advance_state(&self, slot: u64) -> Result<(), SlotProcessingError> {
let state_slot = self.state.read().slot;
let head_block_root = self.head().beacon_block_root;
for _ in state_slot..slot {
self.state
.write()
.per_slot_processing(head_block_root.clone(), &self.spec)?;
}
Ok(())
}
}