From 3c9b04c3b43c93d3bd272bb4b324854906b562a6 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Thu, 11 Apr 2024 14:09:37 +0100 Subject: [PATCH] Update getStateValidatorIndex --- packages/beacon-node/src/api/impl/beacon/state/utils.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/beacon-node/src/api/impl/beacon/state/utils.ts b/packages/beacon-node/src/api/impl/beacon/state/utils.ts index d3a704df126b..5ed624e9eedf 100644 --- a/packages/beacon-node/src/api/impl/beacon/state/utils.ts +++ b/packages/beacon-node/src/api/impl/beacon/state/utils.ts @@ -129,14 +129,15 @@ export function filterStateValidatorsByStatus( return responses; } -type StateValidatorIndexResponse = {valid: true; validatorIndex: number} | {valid: false; code: number; reason: string}; +type StateValidatorIndexResponse = + | {valid: true; validatorIndex: ValidatorIndex} + | {valid: false; code: number; reason: string}; export function getStateValidatorIndex( id: routes.beacon.ValidatorId | BLSPubkey, state: BeaconStateAllForks, pubkey2index: PubkeyIndexMap ): StateValidatorIndexResponse { - let validatorIndex: ValidatorIndex | undefined; if (typeof id === "string") { // mutate `id` and fallthrough to below if (id.startsWith("0x")) { @@ -151,7 +152,7 @@ export function getStateValidatorIndex( } if (typeof id === "number") { - validatorIndex = id; + const validatorIndex = id; // validator is invalid or added later than given stateId if (!Number.isSafeInteger(validatorIndex)) { return {valid: false, code: 400, reason: "Invalid validator index"}; @@ -163,7 +164,7 @@ export function getStateValidatorIndex( } // typeof id === Uint8Array - validatorIndex = pubkey2index.get(id); + const validatorIndex = pubkey2index.get(id); if (validatorIndex === undefined) { return {valid: false, code: 404, reason: "Validator pubkey not found in state"}; }