Fix #3463 (validator index-out-of-bound errors triggered through the REST API)

This commit is contained in:
Zahary Karadjov 2022-03-07 17:02:15 +02:00
parent 8955edf158
commit 5ef2ce4069
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609

View File

@ -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