mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 21:38:31 +00:00
Implement tree states & hierarchical state DB
This commit is contained in:
@@ -83,7 +83,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use store::HotColdDB;
|
||||
use types::{BeaconState, ChainSpec, CloneConfig, EthSpec, Hash256, SignedBeaconBlock};
|
||||
use types::{BeaconState, ChainSpec, EthSpec, Hash256, SignedBeaconBlock};
|
||||
|
||||
const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
|
||||
@@ -195,7 +195,10 @@ pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(),
|
||||
let store = Arc::new(store);
|
||||
|
||||
debug!("Building pubkey cache (might take some time)");
|
||||
let validator_pubkey_cache = ValidatorPubkeyCache::new(&pre_state, store)
|
||||
let validator_pubkey_cache = store.immutable_validators.clone();
|
||||
validator_pubkey_cache
|
||||
.write()
|
||||
.import_new_pubkeys(&pre_state)
|
||||
.map_err(|e| format!("Failed to create pubkey cache: {:?}", e))?;
|
||||
|
||||
/*
|
||||
@@ -226,8 +229,9 @@ pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(),
|
||||
*/
|
||||
|
||||
let mut output_post_state = None;
|
||||
let mut saved_ctxt = None;
|
||||
for i in 0..runs {
|
||||
let pre_state = pre_state.clone_with(CloneConfig::all());
|
||||
let pre_state = pre_state.clone();
|
||||
let block = block.clone();
|
||||
|
||||
let start = Instant::now();
|
||||
@@ -238,7 +242,8 @@ pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(),
|
||||
block,
|
||||
state_root_opt,
|
||||
&config,
|
||||
&validator_pubkey_cache,
|
||||
&*validator_pubkey_cache.read(),
|
||||
&mut saved_ctxt,
|
||||
spec,
|
||||
)?;
|
||||
|
||||
@@ -288,9 +293,12 @@ pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches) -> Result<(),
|
||||
.map_err(|e| format!("Unable to write to output file: {:?}", e))?;
|
||||
}
|
||||
|
||||
drop(pre_state);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn do_transition<T: EthSpec>(
|
||||
mut pre_state: BeaconState<T>,
|
||||
block_root: Hash256,
|
||||
@@ -298,6 +306,7 @@ fn do_transition<T: EthSpec>(
|
||||
mut state_root_opt: Option<Hash256>,
|
||||
config: &Config,
|
||||
validator_pubkey_cache: &ValidatorPubkeyCache<EphemeralHarnessType<T>>,
|
||||
saved_ctxt: &mut Option<ConsensusContext<T>>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<BeaconState<T>, String> {
|
||||
if !config.exclude_cache_builds {
|
||||
@@ -339,9 +348,22 @@ fn do_transition<T: EthSpec>(
|
||||
.map_err(|e| format!("Unable to build caches: {:?}", e))?;
|
||||
debug!("Build all caches (again): {:?}", t.elapsed());
|
||||
|
||||
let mut ctxt = ConsensusContext::new(pre_state.slot())
|
||||
.set_current_block_root(block_root)
|
||||
.set_proposer_index(block.message().proposer_index());
|
||||
let mut ctxt = if let Some(ctxt) = saved_ctxt {
|
||||
ctxt.clone()
|
||||
} else {
|
||||
let mut ctxt = ConsensusContext::new(pre_state.slot())
|
||||
.set_current_block_root(block_root)
|
||||
.set_proposer_index(block.message().proposer_index());
|
||||
|
||||
if config.exclude_cache_builds {
|
||||
ctxt = ctxt.set_epoch_cache(
|
||||
EpochCache::new(&pre_state, spec)
|
||||
.map_err(|e| format!("unable to build epoch cache: {e:?}"))?,
|
||||
);
|
||||
*saved_ctxt = Some(ctxt.clone());
|
||||
}
|
||||
ctxt
|
||||
};
|
||||
|
||||
if !config.no_signature_verification {
|
||||
let get_pubkey = move |validator_index| {
|
||||
|
||||
Reference in New Issue
Block a user