Skip to content

Commit

Permalink
Prepopulate validatorIdentities in else clause
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Sep 26, 2024
1 parent b5a4f06 commit 618f89f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/beacon-node/src/api/impl/beacon/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ export function getBeaconStateApi({
const {state, executionOptimistic, finalized} = await getStateResponse(chain, stateId);
const {pubkey2index} = chain.getHeadState().epochCtx;

const validatorIdentities: routes.beacon.ValidatorIdentities = [];
let validatorIdentities: routes.beacon.ValidatorIdentities;

if (validatorIds.length) {
validatorIdentities = [];
for (const id of validatorIds) {
const resp = getStateValidatorIndex(id, state, pubkey2index);
if (resp.valid) {
Expand All @@ -147,9 +148,10 @@ export function getBeaconStateApi({
}
} else {
const validatorsArr = state.validators.getAllReadonlyValues();
validatorIdentities = new Array(validatorsArr.length) as routes.beacon.ValidatorIdentities;
for (let i = 0; i < validatorsArr.length; i++) {
const {pubkey, activationEpoch} = validatorsArr[i];
validatorIdentities.push({index: i, pubkey, activationEpoch});
validatorIdentities[i] = {index: i, pubkey, activationEpoch};
}
}

Expand Down

0 comments on commit 618f89f

Please sign in to comment.