Skip to content

Commit

Permalink
fix: sync cached balance when adding new validator to registry (#7255)
Browse files Browse the repository at this point in the history
* fix: sync cached balance when adding new validator to registry

* chore: add more comments

* fix: remove persisted checkpoint states from the previous run at startup
  • Loading branch information
twoeths authored and nflaig committed Nov 28, 2024
1 parent f1e8198 commit 7f96e70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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
6 changes: 6 additions & 0 deletions packages/state-transition/src/epoch/processPendingDeposits.ts
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

0 comments on commit 7f96e70

Please sign in to comment.