diff --git a/packages/lodestar/src/api/impl/beacon/pool/index.ts b/packages/lodestar/src/api/impl/beacon/pool/index.ts index da5cb15836c2..7c15c4d38a2b 100644 --- a/packages/lodestar/src/api/impl/beacon/pool/index.ts +++ b/packages/lodestar/src/api/impl/beacon/pool/index.ts @@ -2,7 +2,7 @@ import {Api as IBeaconPoolApi} from "@chainsafe/lodestar-api/lib/routes/beacon/pool"; import {Epoch, ssz} from "@chainsafe/lodestar-types"; import {allForks} from "@chainsafe/lodestar-beacon-state-transition"; -import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_COUNT} from "@chainsafe/lodestar-params"; +import {SYNC_COMMITTEE_SUBNET_SIZE} from "@chainsafe/lodestar-params"; import {validateGossipAttestation} from "../../../../chain/validation"; import {validateGossipAttesterSlashing} from "../../../../chain/validation/attesterSlashing"; import {validateGossipProposerSlashing} from "../../../../chain/validation/proposerSlashing"; @@ -122,9 +122,6 @@ export function getBeaconPoolApi({ // TODO: Fetch states at signature slots const state = chain.getHeadState(); - // TODO: Cache this value - const SYNC_COMMITTEE_SUBNET_SIZE = Math.floor(SYNC_COMMITTEE_SIZE / SYNC_COMMITTEE_SUBNET_COUNT); - const errors: Error[] = []; await Promise.all( diff --git a/packages/lodestar/src/api/impl/validator/index.ts b/packages/lodestar/src/api/impl/validator/index.ts index 452e3b9984f8..93307e4103b7 100644 --- a/packages/lodestar/src/api/impl/validator/index.ts +++ b/packages/lodestar/src/api/impl/validator/index.ts @@ -11,8 +11,7 @@ import { GENESIS_SLOT, SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT, - SYNC_COMMITTEE_SIZE, - SYNC_COMMITTEE_SUBNET_COUNT, + SYNC_COMMITTEE_SUBNET_SIZE, } from "@chainsafe/lodestar-params"; import {Root, Slot, ValidatorIndex, ssz} from "@chainsafe/lodestar-types"; import {ExecutionStatus} from "@chainsafe/lodestar-fork-choice"; @@ -569,9 +568,6 @@ export function getValidatorApi({chain, config, logger, metrics, network, sync}: async prepareSyncCommitteeSubnets(subscriptions) { notWhileSyncing(); - // TODO: Cache this value - const SYNC_COMMITTEE_SUBNET_SIZE = Math.floor(SYNC_COMMITTEE_SIZE / SYNC_COMMITTEE_SUBNET_COUNT); - // A `validatorIndex` can be in multiple subnets, so compute the CommitteeSubscription with double for loop const subs: CommitteeSubscription[] = []; for (const sub of subscriptions) { diff --git a/packages/lodestar/src/chain/validation/syncCommittee.ts b/packages/lodestar/src/chain/validation/syncCommittee.ts index f88b285ed5f8..43edbef205c3 100644 --- a/packages/lodestar/src/chain/validation/syncCommittee.ts +++ b/packages/lodestar/src/chain/validation/syncCommittee.ts @@ -1,5 +1,5 @@ import {CachedBeaconStateAllForks, allForks} from "@chainsafe/lodestar-beacon-state-transition"; -import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_COUNT} from "@chainsafe/lodestar-params"; +import {SYNC_COMMITTEE_SUBNET_SIZE, SYNC_COMMITTEE_SUBNET_COUNT} from "@chainsafe/lodestar-params"; import {altair} from "@chainsafe/lodestar-types"; import {GossipAction, SyncCommitteeError, SyncCommitteeErrorCode} from "../errors"; import {IBeaconChain} from "../interface"; @@ -122,9 +122,6 @@ function getIndexInSubcommittee( return null; } - // TODO: Cache this value - const SYNC_COMMITTEE_SUBNET_SIZE = Math.floor(SYNC_COMMITTEE_SIZE / SYNC_COMMITTEE_SUBNET_COUNT); - for (const indexInCommittee of indexesInCommittee) { if (Math.floor(indexInCommittee / SYNC_COMMITTEE_SUBNET_SIZE) === subnet) { return indexInCommittee % SYNC_COMMITTEE_SUBNET_SIZE; diff --git a/packages/params/src/index.ts b/packages/params/src/index.ts index faf11b592517..6d86f034ad4b 100644 --- a/packages/params/src/index.ts +++ b/packages/params/src/index.ts @@ -147,6 +147,7 @@ export const ATTESTATION_SUBNET_COUNT = 64; export const TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE = 16; export const SYNC_COMMITTEE_SUBNET_COUNT = 4; +export const SYNC_COMMITTEE_SUBNET_SIZE = Math.floor(SYNC_COMMITTEE_SIZE / SYNC_COMMITTEE_SUBNET_COUNT); export const MAX_REQUEST_BLOCKS = 2 ** 10; // 1024 diff --git a/packages/validator/src/services/syncCommitteeDuties.ts b/packages/validator/src/services/syncCommitteeDuties.ts index 86f663d1d3d9..78ce21d16e49 100644 --- a/packages/validator/src/services/syncCommitteeDuties.ts +++ b/packages/validator/src/services/syncCommitteeDuties.ts @@ -1,8 +1,4 @@ -import { - EPOCHS_PER_SYNC_COMMITTEE_PERIOD, - SYNC_COMMITTEE_SIZE, - SYNC_COMMITTEE_SUBNET_COUNT, -} from "@chainsafe/lodestar-params"; +import {EPOCHS_PER_SYNC_COMMITTEE_PERIOD, SYNC_COMMITTEE_SUBNET_SIZE} from "@chainsafe/lodestar-params"; import { computeSyncPeriodAtEpoch, computeSyncPeriodAtSlot, @@ -223,8 +219,6 @@ export class SyncCommitteeDutiesService { } private async getSelectionProofs(slot: Slot, duty: routes.validator.SyncDuty): Promise { - // TODO: Cache this value - const SYNC_COMMITTEE_SUBNET_SIZE = Math.floor(SYNC_COMMITTEE_SIZE / SYNC_COMMITTEE_SUBNET_COUNT); // Fast indexing with precomputed pubkeyHex. Fallback to toHexString(duty.pubkey) const pubkey = this.indicesService.index2pubkey.get(duty.validatorIndex) ?? duty.pubkey;