Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use upgradable read lock for pubkey cache #6190

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3481,9 +3481,15 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// would be difficult to check that they all lock fork choice first.
let mut ops = {
let _timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_PUBKEY_CACHE_LOCK);
self.validator_pubkey_cache
.write()
.import_new_pubkeys(&state)?
let pubkey_cache = self.validator_pubkey_cache.upgradable_read();

// 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.
Expand Down
Loading