From b9920a3a59a2c3bcb5fbaeeac891322006aef4e7 Mon Sep 17 00:00:00 2001 From: tersec Date: Mon, 7 Aug 2023 14:52:42 +0000 Subject: [PATCH] don't overwrite immutable parts of already-present validators (#5264) --- beacon_chain/beacon_chain_db.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index 6672bc624..dcbfbf099 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -1112,12 +1112,14 @@ proc getStateOnlyMutableValidators( # TODO rollback is needed to deal with bug - use `noRollback` to ignore: # https://github.com/nim-lang/Nim/issues/14126 + let prevNumValidators = output.validators.len + case store.getSnappySSZ(key, toBeaconStateNoImmutableValidators(output)) of GetResult.found: let numValidators = output.validators.len doAssert immutableValidators.len >= numValidators - for i in 0 ..< numValidators: + for i in prevNumValidators ..< numValidators: let # Bypass hash cache invalidation dstValidator = addr output.validators.data[i] @@ -1151,12 +1153,14 @@ proc getStateOnlyMutableValidators( # TODO rollback is needed to deal with bug - use `noRollback` to ignore: # https://github.com/nim-lang/Nim/issues/14126 + let prevNumValidators = output.validators.len + case store.getSZSSZ(key, toBeaconStateNoImmutableValidators(output)) of GetResult.found: let numValidators = output.validators.len doAssert immutableValidators.len >= numValidators - for i in 0 ..< numValidators: + for i in prevNumValidators ..< numValidators: # Bypass hash cache invalidation let dstValidator = addr output.validators.data[i] @@ -1188,12 +1192,14 @@ proc getStateOnlyMutableValidators( # TODO rollback is needed to deal with bug - use `noRollback` to ignore: # https://github.com/nim-lang/Nim/issues/14126 + let prevNumValidators = output.validators.len + case store.getSZSSZ(key, toBeaconStateNoImmutableValidators(output)) of GetResult.found: let numValidators = output.validators.len doAssert immutableValidators.len >= numValidators - for i in 0 ..< numValidators: + for i in prevNumValidators ..< numValidators: # Bypass hash cache invalidation let dstValidator = addr output.validators.data[i] assign(dstValidator.pubkey, immutableValidators[i].pubkey.toPubKey())