Skip to content

Commit 5a06be0

Browse files
authored
Merge of #6190
2 parents a843785 + 2d213bb commit 5a06be0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,9 +3481,15 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
34813481
// would be difficult to check that they all lock fork choice first.
34823482
let mut ops = {
34833483
let _timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_PUBKEY_CACHE_LOCK);
3484-
self.validator_pubkey_cache
3485-
.write()
3486-
.import_new_pubkeys(&state)?
3484+
let pubkey_cache = self.validator_pubkey_cache.upgradable_read();
3485+
3486+
// Only take a write lock if there are new keys to import.
3487+
if state.validators().len() > pubkey_cache.len() {
3488+
parking_lot::RwLockUpgradableReadGuard::upgrade(pubkey_cache)
3489+
.import_new_pubkeys(&state)?
3490+
} else {
3491+
vec![]
3492+
}
34873493
};
34883494

34893495
// Apply the state to the attester cache, only if it is from the previous epoch or later.

0 commit comments

Comments
 (0)