Skip to content

Commit

Permalink
fix: ignore empty array when filtering validator rewards (#6882)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Jun 13, 2024
1 parent 225e67a commit 79a008f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/beacon-node/src/chain/rewards/attestationsRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ function computeTotalAttestationsRewardsAltair(
transitionCache: EpochTransitionCache,
idealRewards: IdealAttestationsReward[],
penalties: AttestationsPenalty[],
validatorIds?: (ValidatorIndex | string)[] // validatorIds filter
validatorIds: (ValidatorIndex | string)[] = []
): TotalAttestationsReward[] {
const rewards = [];
const {statuses} = transitionCache;
const {epochCtx, config} = state;
const validatorIndices = validatorIds
?.map((id) => (typeof id === "number" ? id : epochCtx.pubkey2index.get(id)))
.map((id) => (typeof id === "number" ? id : epochCtx.pubkey2index.get(id)))
.filter((index) => index !== undefined); // Validator indices to include in the result

const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR;

for (let i = 0; i < statuses.length; i++) {
if (validatorIndices !== undefined && !validatorIndices.includes(i)) {
if (validatorIndices.length && !validatorIndices.includes(i)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type BalanceRecord = {val: number}; // Use val for convenient way to increment/d
export async function computeSyncCommitteeRewards(
block: allForks.BeaconBlock,
preState: CachedBeaconStateAllForks,
validatorIds?: (ValidatorIndex | string)[]
validatorIds: (ValidatorIndex | string)[] = []
): Promise<SyncCommitteeRewards> {
const fork = preState.config.getForkName(block.slot);
if (fork === ForkName.phase0) {
Expand Down Expand Up @@ -46,7 +46,7 @@ export async function computeSyncCommitteeRewards(

const rewards = Array.from(balances, ([validatorIndex, v]) => ({validatorIndex, reward: v.val}));

if (validatorIds !== undefined) {
if (validatorIds.length) {
const filtersSet = new Set(validatorIds);
return rewards.filter(
(reward) => filtersSet.has(reward.validatorIndex) || filtersSet.has(index2pubkey[reward.validatorIndex].toHex())
Expand Down

0 comments on commit 79a008f

Please sign in to comment.