Add method for dropping pubkey cache. Add bench.

This commit is contained in:
Paul Hauner 2019-03-13 16:49:32 +11:00
parent 6cd3c4bd1a
commit 587be831b5
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 22 additions and 0 deletions

View File

@ -426,6 +426,23 @@ fn bench_block_processing(
.sample_size(10),
);
let mut state = initial_state.clone();
state.drop_pubkey_cache();
c.bench(
&format!("{}/block_processing", desc),
Benchmark::new("build_pubkey_cache", move |b| {
b.iter_batched(
|| state.clone(),
|mut state| {
state.update_pubkey_cache().unwrap();
state
},
criterion::BatchSize::SmallInput,
)
})
.sample_size(10),
);
let block = initial_block.clone();
c.bench(
&format!("{}/block_processing", desc),

View File

@ -322,6 +322,11 @@ impl BeaconState {
Ok(())
}
/// Completely drops the `pubkey_cache`, replacing it with a new, empty cache.
pub fn drop_pubkey_cache(&mut self) {
self.pubkey_cache = PubkeyCache::empty()
}
/// If a validator pubkey exists in the validator registry, returns `Some(i)`, otherwise
/// returns `None`.
///