mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-02 04:03:35 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user