Optimisations and bug fixes for state advance

This commit is reasonably performant on Prater!
This commit is contained in:
Michael Sproul
2022-02-17 14:00:57 +11:00
parent f5dae9106e
commit 1db0e32bfb
13 changed files with 171 additions and 56 deletions

View File

@@ -43,7 +43,9 @@ pub fn run_transition_blocks<T: EthSpec>(
let block: SignedBeaconBlock<T> =
load_from_ssz_with(&block_path, spec, SignedBeaconBlock::from_ssz_bytes)?;
let t = std::time::Instant::now();
let post_state = do_transition(pre_state.clone(), block, spec)?;
println!("Total transition time: {}ms", t.elapsed().as_millis());
let mut output_file =
File::create(output_path).map_err(|e| format!("Unable to create output file: {:?}", e))?;
@@ -67,25 +69,47 @@ fn do_transition<T: EthSpec>(
.build_all_caches(spec)
.map_err(|e| format!("Unable to build caches: {:?}", e))?;
let t = std::time::Instant::now();
pre_state
.update_tree_hash_cache()
.map_err(|e| format!("Unable to build tree hash cache: {:?}", e))?;
println!("Initial tree hash: {}ms", t.elapsed().as_millis());
// Transition the parent state to the block slot.
let t = std::time::Instant::now();
for i in pre_state.slot().as_u64()..block.slot().as_u64() {
per_slot_processing(&mut pre_state, None, spec)
.map_err(|e| format!("Failed to advance slot on iteration {}: {:?}", i, e))?;
}
println!("Slot processing: {}ms", t.elapsed().as_millis());
let t = std::time::Instant::now();
pre_state
.update_tree_hash_cache()
.map_err(|e| format!("Unable to build tree hash cache: {:?}", e))?;
println!("Pre-block tree hash: {}ms", t.elapsed().as_millis());
pre_state
.build_all_caches(spec)
.map_err(|e| format!("Unable to build caches: {:?}", e))?;
let t = std::time::Instant::now();
per_block_processing(
&mut pre_state,
&block,
None,
BlockSignatureStrategy::VerifyIndividual,
BlockSignatureStrategy::VerifyBulk,
VerifyBlockRoot::True,
spec,
)
.map_err(|e| format!("State transition failed: {:?}", e))?;
println!("Process block: {}ms", t.elapsed().as_millis());
let t = std::time::Instant::now();
pre_state
.update_tree_hash_cache()
.map_err(|e| format!("Unable to build tree hash cache: {:?}", e))?;
println!("Post-block tree hash: {}ms", t.elapsed().as_millis());
Ok(pre_state)
}
@@ -100,5 +124,13 @@ pub fn load_from_ssz_with<T>(
let mut bytes = vec![];
file.read_to_end(&mut bytes)
.map_err(|e| format!("Unable to read from file {:?}: {:?}", path, e))?;
decoder(&bytes, spec).map_err(|e| format!("Ssz decode failed: {:?}", e))
let t = std::time::Instant::now();
let result = decoder(&bytes, spec).map_err(|e| format!("Ssz decode failed: {:?}", e));
println!(
"SSZ decoding {}: {}ms",
path.display(),
t.elapsed().as_millis()
);
result
}