mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-21 06:48:27 +00:00
minimize the number of places we are calling update_pubkey_cache (#1626)
## Issue Addressed - Resolves #1080 ## Proposed Changes - Call `update_pubkey_cache` only in the `build_all_caches` method and `get_validator_index` method. ## Additional Info This does reduce the number of places the cache is updated, making it simpler. But the `get_validator_index` method is used a couple times when we are iterating through the entire validator registry (or set of active validators). Before, we would only call `update_pubkey_cache` once before iterating through all validators. So I'm not _totally_ sure this change is worth it.
This commit is contained in:
@@ -300,19 +300,12 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// If a validator pubkey exists in the validator registry, returns `Some(i)`, otherwise
|
||||
/// returns `None`.
|
||||
///
|
||||
/// Requires a fully up-to-date `pubkey_cache`, returns an error if this is not the case.
|
||||
pub fn get_validator_index(&self, pubkey: &PublicKeyBytes) -> Result<Option<usize>, Error> {
|
||||
if self.pubkey_cache.len() == self.validators.len() {
|
||||
Ok(self.pubkey_cache.get(pubkey))
|
||||
} else {
|
||||
Err(Error::PubkeyCacheIncomplete {
|
||||
cache_len: self.pubkey_cache.len(),
|
||||
registry_len: self.validators.len(),
|
||||
})
|
||||
}
|
||||
/// This method ensures the state's pubkey cache is fully up-to-date before checking if the validator
|
||||
/// exists in the registry. If a validator pubkey exists in the validator registry, returns `Some(i)`,
|
||||
/// otherwise returns `None`.
|
||||
pub fn get_validator_index(&mut self, pubkey: &PublicKeyBytes) -> Result<Option<usize>, Error> {
|
||||
self.update_pubkey_cache()?;
|
||||
Ok(self.pubkey_cache.get(pubkey))
|
||||
}
|
||||
|
||||
/// The epoch corresponding to `self.slot`.
|
||||
|
||||
Reference in New Issue
Block a user