Skip to content

Commit a5ea05c

Browse files
authored
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
1 parent 6d5a2be commit a5ea05c

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

beacon_node/beacon_chain/src/builder.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,31 @@ where
847847
));
848848
}
849849

850-
let validator_pubkey_cache = self.validator_pubkey_cache.map(Ok).unwrap_or_else(|| {
851-
ValidatorPubkeyCache::new(&head_snapshot.beacon_state, store.clone())
852-
.map_err(|e| format!("Unable to init validator pubkey cache: {:?}", e))
853-
})?;
850+
let validator_pubkey_cache = self
851+
.validator_pubkey_cache
852+
.map(|mut validator_pubkey_cache| {
853+
// If any validators weren't persisted to disk on previous runs, this will use the head state to
854+
// "top-up" the in-memory validator cache and its on-disk representation with any missing validators.
855+
let pubkey_store_ops = validator_pubkey_cache
856+
.import_new_pubkeys(&head_snapshot.beacon_state)
857+
.map_err(|e| format!("Unable to top-up persisted pubkey cache {:?}", e))?;
858+
if !pubkey_store_ops.is_empty() {
859+
// Write any missed validators to disk
860+
debug!(
861+
store.log,
862+
"Topping up validator pubkey cache";
863+
"missing_validators" => pubkey_store_ops.len()
864+
);
865+
store
866+
.do_atomically_with_block_and_blobs_cache(pubkey_store_ops)
867+
.map_err(|e| format!("Unable to write pubkeys to disk {:?}", e))?;
868+
}
869+
Ok(validator_pubkey_cache)
870+
})
871+
.unwrap_or_else(|| {
872+
ValidatorPubkeyCache::new(&head_snapshot.beacon_state, store.clone())
873+
.map_err(|e| format!("Unable to init validator pubkey cache: {:?}", e))
874+
})?;
854875

855876
let migrator_config = self.store_migrator_config.unwrap_or_default();
856877
let store_migrator = BackgroundMigrator::new(

0 commit comments

Comments
 (0)