Single-pass epoch processing (#4483)

This commit is contained in:
Michael Sproul
2023-07-18 16:59:55 +10:00
committed by GitHub
parent 079cd67df2
commit 5d2063d262
42 changed files with 1558 additions and 730 deletions

View File

@@ -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,

View File

@@ -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))