mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 21:34:46 +00:00
Single-pass epoch processing (#4483)
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::hdiff;
|
||||
use crate::hot_cold_store::HotColdDBError;
|
||||
use ssz::DecodeError;
|
||||
use state_processing::BlockReplayError;
|
||||
use types::{milhouse, BeaconStateError, Epoch, Hash256, InconsistentFork, Slot};
|
||||
use types::{milhouse, BeaconStateError, Epoch, EpochCacheError, Hash256, InconsistentFork, Slot};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
@@ -71,6 +71,7 @@ pub enum Error {
|
||||
Hdiff(hdiff::Error),
|
||||
InconsistentFork(InconsistentFork),
|
||||
ZeroCacheSize,
|
||||
CacheBuildError(EpochCacheError),
|
||||
}
|
||||
|
||||
pub trait HandleUnavailable<T> {
|
||||
@@ -141,6 +142,12 @@ impl From<InconsistentFork> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EpochCacheError> for Error {
|
||||
fn from(e: EpochCacheError) -> Error {
|
||||
Error::CacheBuildError(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DBError {
|
||||
pub message: String,
|
||||
|
||||
@@ -30,7 +30,8 @@ use slog::{debug, error, info, warn, Logger};
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use state_processing::{
|
||||
block_replayer::PreSlotHook, BlockProcessingError, BlockReplayer, SlotProcessingError,
|
||||
block_replayer::PreSlotHook, AllCaches, BlockProcessingError, BlockReplayer,
|
||||
SlotProcessingError,
|
||||
};
|
||||
use std::cmp::min;
|
||||
use std::collections::VecDeque;
|
||||
@@ -1152,7 +1153,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
let state_cacher_hook = |opt_state_root: Option<Hash256>, state: &mut BeaconState<_>| {
|
||||
// Ensure all caches are built before attempting to cache.
|
||||
state.update_tree_hash_cache()?;
|
||||
state.build_caches(&self.spec)?;
|
||||
state.build_all_caches(&self.spec)?;
|
||||
|
||||
if let Some(state_root) = opt_state_root {
|
||||
// Cache
|
||||
@@ -1246,7 +1247,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
)?;
|
||||
|
||||
state.update_tree_hash_cache()?;
|
||||
state.build_caches(&self.spec)?;
|
||||
state.build_all_caches(&self.spec)?;
|
||||
}
|
||||
|
||||
// Apply state diff. Block replay should have ensured that the diff is now applicable.
|
||||
@@ -1280,7 +1281,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
let tree_hash_ms = t.elapsed().as_millis();
|
||||
|
||||
let t = std::time::Instant::now();
|
||||
state.build_caches(&self.spec)?;
|
||||
state.build_all_caches(&self.spec)?;
|
||||
let cache_ms = t.elapsed().as_millis();
|
||||
|
||||
debug!(
|
||||
@@ -1358,7 +1359,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
|
||||
// Do a tree hash here so that the cache is fully built.
|
||||
state.update_tree_hash_cache()?;
|
||||
state.build_caches(&self.spec)?;
|
||||
state.build_all_caches(&self.spec)?;
|
||||
|
||||
let latest_block_root = state.get_latest_block_root(*state_root);
|
||||
Ok((state, latest_block_root))
|
||||
|
||||
Reference in New Issue
Block a user