diff --git a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts index 7fb67a75867..d0540e507df 100644 --- a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts +++ b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts @@ -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, }); diff --git a/packages/state-transition/src/epoch/processPendingDeposits.ts b/packages/state-transition/src/epoch/processPendingDeposits.ts index e00e1ef93c8..d925aa1cc74 100644 --- a/packages/state-transition/src/epoch/processPendingDeposits.ts +++ b/packages/state-transition/src/epoch/processPendingDeposits.ts @@ -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