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

fix: sync cached balance when adding new validator to registry #7255

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache {
await this.datastore.init();
}
const persistedKeys = await this.datastore.readKeys();
for (const persistedKey of persistedKeys) {
const cp = datastoreKeyToCheckpoint(persistedKey);
this.cache.set(toCacheKey(cp), {type: CacheItemType.persisted, value: persistedKey});
this.epochIndex.getOrDefault(cp.epoch).add(toRootHex(cp.root));
}
this.logger.info("Loaded persisted checkpoint states from the last run", {
// all checkpoint states from the last run are not trusted, remove them
// otherwise if we have a bad checkpoint state from the last run, the node get stucked
// this was found during mekong devnet, see https://github.com/ChainSafe/lodestar/pull/7255
await Promise.all(persistedKeys.map((key) => this.datastore.remove(key)));
this.logger.info("Removed persisted checkpoint states from the last run", {
count: persistedKeys.length,
maxEpochsInMemory: this.maxEpochsInMemory,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ function applyPendingDeposit(
addValidatorToRegistry(ForkSeq.electra, state, pubkey, withdrawalCredentials, amount);
const newValidatorIndex = state.validators.length - 1;
cache.isCompoundingValidatorArr[newValidatorIndex] = hasCompoundingWithdrawalCredential(withdrawalCredentials);
// set balance, so that the next deposit of same pubkey will increase the balance correctly
// this is to fix the double deposit issue found in mekong
// see https://github.com/ChainSafe/lodestar/pull/7255
if (cachedBalances) {
cachedBalances[newValidatorIndex] = amount;
}
}
} else {
// Increase balance
Expand Down
Loading