mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
Use upgradable read lock for pubkey cache (#6190)
* Use upgradable read for pubkey cache
This commit is contained in:
@@ -3481,9 +3481,15 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
// would be difficult to check that they all lock fork choice first.
|
// would be difficult to check that they all lock fork choice first.
|
||||||
let mut ops = {
|
let mut ops = {
|
||||||
let _timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_PUBKEY_CACHE_LOCK);
|
let _timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_PUBKEY_CACHE_LOCK);
|
||||||
self.validator_pubkey_cache
|
let pubkey_cache = self.validator_pubkey_cache.upgradable_read();
|
||||||
.write()
|
|
||||||
.import_new_pubkeys(&state)?
|
// Only take a write lock if there are new keys to import.
|
||||||
|
if state.validators().len() > pubkey_cache.len() {
|
||||||
|
parking_lot::RwLockUpgradableReadGuard::upgrade(pubkey_cache)
|
||||||
|
.import_new_pubkeys(&state)?
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the state to the attester cache, only if it is from the previous epoch or later.
|
// Apply the state to the attester cache, only if it is from the previous epoch or later.
|
||||||
|
|||||||
Reference in New Issue
Block a user