Skip to content

Commit

Permalink
Fix #3463 (validator index-out-of-bound errors triggered through the …
Browse files Browse the repository at this point in the history
…REST API)
  • Loading branch information
zah committed Mar 7, 2022
1 parent 187eabe commit 7ffb88e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion beacon_chain/rpc/rest_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,15 @@ func keysToIndices*(cacheTable: var Table[ValidatorPubKey, ValidatorIndex],
keys: openArray[ValidatorPubKey]
): seq[Option[ValidatorIndex]] =
var indices = newSeq[Option[ValidatorIndex]](len(keys))
let totalValidatorsInState = getStateField(forkedState, validators).lenu64
var keyset =
block:
var res: Table[ValidatorPubKey, int]
for inputIndex, pubkey in keys.pairs():
# Try to search in cache first.
cacheTable.withValue(pubkey, vindex):
indices[inputIndex] = some(vindex[])
if uint64(vindex[]) < totalValidatorsInState:
indices[inputIndex] = some(vindex[])
do:
res[pubkey] = inputIndex
res
Expand Down

0 comments on commit 7ffb88e

Please sign in to comment.