Top-up pubkey cache on startup (#7217)

This is a workaround for #7216


  In the case of gaps between the in-memory pub key cache and its on-disk representation, use the head state on startup to "top-up" the cache/db w/ any missing validators
This commit is contained in:
Eitan Seri-Levi
2025-03-28 02:29:19 -06:00
committed by GitHub
parent 6d5a2be7f9
commit a5ea05ce2a

View File

@@ -847,10 +847,31 @@ where
));
}
let validator_pubkey_cache = self.validator_pubkey_cache.map(Ok).unwrap_or_else(|| {
ValidatorPubkeyCache::new(&head_snapshot.beacon_state, store.clone())
.map_err(|e| format!("Unable to init validator pubkey cache: {:?}", e))
})?;
let validator_pubkey_cache = self
.validator_pubkey_cache
.map(|mut validator_pubkey_cache| {
// If any validators weren't persisted to disk on previous runs, this will use the head state to
// "top-up" the in-memory validator cache and its on-disk representation with any missing validators.
let pubkey_store_ops = validator_pubkey_cache
.import_new_pubkeys(&head_snapshot.beacon_state)
.map_err(|e| format!("Unable to top-up persisted pubkey cache {:?}", e))?;
if !pubkey_store_ops.is_empty() {
// Write any missed validators to disk
debug!(
store.log,
"Topping up validator pubkey cache";
"missing_validators" => pubkey_store_ops.len()
);
store
.do_atomically_with_block_and_blobs_cache(pubkey_store_ops)
.map_err(|e| format!("Unable to write pubkeys to disk {:?}", e))?;
}
Ok(validator_pubkey_cache)
})
.unwrap_or_else(|| {
ValidatorPubkeyCache::new(&head_snapshot.beacon_state, store.clone())
.map_err(|e| format!("Unable to init validator pubkey cache: {:?}", e))
})?;
let migrator_config = self.store_migrator_config.unwrap_or_default();
let store_migrator = BackgroundMigrator::new(