Skip to content

Commit 075956b

Browse files
authored
refactor: use map to lookup combined beacon committee selection for duty (#8710)
#8669 (comment)
1 parent ae3f082 commit 075956b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/validator/src/services/attestationDuties.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,20 +469,33 @@ export class AttestationDutiesService {
469469

470470
const res = await this.api.validator.submitBeaconCommitteeSelections({selections: partialSelections});
471471

472-
const combinedSelections = res.value();
473-
this.logger.debug("Received combined beacon committee selection proofs", {epoch, count: combinedSelections.length});
472+
const combinedSelections = new Map<ValidatorIndex, routes.validator.BeaconCommitteeSelection>();
473+
for (const selection of res.value()) {
474+
combinedSelections.set(selection.validatorIndex, selection);
475+
}
476+
this.logger.debug("Received combined beacon committee selection proofs", {epoch, count: combinedSelections.size});
474477

475478
for (const dutyAndProof of duties) {
476479
const {slot, validatorIndex, committeeIndex, committeeLength} = dutyAndProof.duty;
477480
const logCtxValidator = {slot, index: committeeIndex, validatorIndex};
478481

479-
const combinedSelection = combinedSelections.find((s) => s.validatorIndex === validatorIndex && s.slot === slot);
482+
const combinedSelection = combinedSelections.get(validatorIndex);
480483

481484
if (!combinedSelection) {
482485
this.logger.debug("Did not receive combined beacon committee selection proof", logCtxValidator);
483486
continue;
484487
}
485488

489+
if (combinedSelection.slot !== slot) {
490+
this.logger.debug("Received combined beacon committee selection proof for different slot", {
491+
expected: slot,
492+
actual: combinedSelection.slot,
493+
index: committeeIndex,
494+
validatorIndex,
495+
});
496+
continue;
497+
}
498+
486499
const isAggregator = isAggregatorFromCommitteeLength(committeeLength, combinedSelection.selectionProof);
487500

488501
if (isAggregator) {

0 commit comments

Comments
 (0)