Skip to content

Commit

Permalink
fix: ignore empty ids/statuses arrays when filtering validators (#6876)
Browse files Browse the repository at this point in the history
fix: ignore empty ids/statuses when filtering validators
  • Loading branch information
nflaig authored Jun 11, 2024
1 parent 4e86094 commit 3be656b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/beacon-node/src/api/impl/beacon/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ export function getBeaconStateApi({
};
},

async getStateValidators({stateId, validatorIds, statuses}) {
async getStateValidators({stateId, validatorIds = [], statuses = []}) {
const {state, executionOptimistic, finalized} = await resolveStateId(chain, stateId);
const currentEpoch = getCurrentEpoch(state);
const {validators, balances} = state; // Get the validators sub tree once for all the loop
const {pubkey2index} = chain.getHeadState().epochCtx;

const validatorResponses: routes.beacon.ValidatorResponse[] = [];
if (validatorIds) {
if (validatorIds.length) {
for (const id of validatorIds) {
const resp = getStateValidatorIndex(id, state, pubkey2index);
if (resp.valid) {
const validatorIndex = resp.validatorIndex;
const validator = validators.getReadonly(validatorIndex);
if (statuses && !statuses.includes(getValidatorStatus(validator, currentEpoch))) {
if (statuses.length && !statuses.includes(getValidatorStatus(validator, currentEpoch))) {
continue;
}
const validatorResponse = toValidatorResponse(
Expand All @@ -104,7 +104,7 @@ export function getBeaconStateApi({
data: validatorResponses,
meta: {executionOptimistic, finalized},
};
} else if (statuses) {
} else if (statuses.length) {
const validatorsByStatus = filterStateValidatorsByStatus(statuses, state, pubkey2index, currentEpoch);
return {
data: validatorsByStatus,
Expand Down

0 comments on commit 3be656b

Please sign in to comment.