refactor: use map to lookup combined beacon committee selection for duty (#8710)

https://github.com/ChainSafe/lodestar/pull/8669#discussion_r2636951039
This commit is contained in:
Nico Flaig
2025-12-31 16:11:31 +01:00
committed by GitHub
parent ae3f082e01
commit 075956b855

View File

@@ -469,20 +469,33 @@ export class AttestationDutiesService {
const res = await this.api.validator.submitBeaconCommitteeSelections({selections: partialSelections});
const combinedSelections = res.value();
this.logger.debug("Received combined beacon committee selection proofs", {epoch, count: combinedSelections.length});
const combinedSelections = new Map<ValidatorIndex, routes.validator.BeaconCommitteeSelection>();
for (const selection of res.value()) {
combinedSelections.set(selection.validatorIndex, selection);
}
this.logger.debug("Received combined beacon committee selection proofs", {epoch, count: combinedSelections.size});
for (const dutyAndProof of duties) {
const {slot, validatorIndex, committeeIndex, committeeLength} = dutyAndProof.duty;
const logCtxValidator = {slot, index: committeeIndex, validatorIndex};
const combinedSelection = combinedSelections.find((s) => s.validatorIndex === validatorIndex && s.slot === slot);
const combinedSelection = combinedSelections.get(validatorIndex);
if (!combinedSelection) {
this.logger.debug("Did not receive combined beacon committee selection proof", logCtxValidator);
continue;
}
if (combinedSelection.slot !== slot) {
this.logger.debug("Received combined beacon committee selection proof for different slot", {
expected: slot,
actual: combinedSelection.slot,
index: committeeIndex,
validatorIndex,
});
continue;
}
const isAggregator = isAggregatorFromCommitteeLength(committeeLength, combinedSelection.selectionProof);
if (isAggregator) {