Optimization: reduce BLS decompression (#766)

* Add RwLock-style caching for BLS pubkeys

* Tidy docker ignore

* Remove RwLocks

* Merge in master
This commit is contained in:
Paul Hauner
2020-01-10 15:32:10 +11:00
committed by GitHub
parent 5a8f2dd961
commit 370c658c7c
7 changed files with 182 additions and 139 deletions

View File

@@ -62,6 +62,7 @@ pub enum Error {
CommitteeCacheUninitialized(Option<RelativeEpoch>),
SszTypesError(ssz_types::Error),
CachedTreeHashError(cached_tree_hash::Error),
InvalidValidatorPubkey(ssz::DecodeError),
}
/// Control whether an epoch-indexed field can be indexed at the next epoch or not.
@@ -784,6 +785,7 @@ impl<T: EthSpec> BeaconState<T> {
self.update_pubkey_cache()?;
self.build_tree_hash_cache()?;
self.exit_cache.build(&self.validators, spec)?;
self.decompress_validator_pubkeys()?;
Ok(())
}
@@ -945,6 +947,23 @@ impl<T: EthSpec> BeaconState<T> {
self.tree_hash_cache = BeaconTreeHashCache::default();
}
/// Iterate through all validators and decompress their public key, unless it has already been
/// decompressed.
///
/// Does not check the validity of already decompressed keys.
pub fn decompress_validator_pubkeys(&mut self) -> Result<(), Error> {
self.validators.iter_mut().try_for_each(|validator| {
if validator.pubkey.decompressed().is_none() {
validator
.pubkey
.decompress()
.map_err(|e| Error::InvalidValidatorPubkey(e))
} else {
Ok(())
}
})
}
pub fn clone_without_caches(&self) -> Self {
BeaconState {
genesis_time: self.genesis_time,

View File

@@ -1,5 +1,4 @@
use crate::{test_utils::TestRandom, Epoch, Hash256, PublicKeyBytes};
use serde_derive::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use test_random_derive::TestRandom;