Skip to content

Commit

Permalink
Add SYNC_COMMITTEE_SUBNET_SIZE constant (#3723)
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion authored Feb 7, 2022
1 parent 7673134 commit cd2edf2
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 20 deletions.
5 changes: 1 addition & 4 deletions packages/lodestar/src/api/impl/beacon/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 1 addition & 5 deletions packages/lodestar/src/api/impl/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions packages/lodestar/src/chain/validation/syncCommittee.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 1 addition & 7 deletions packages/validator/src/services/syncCommitteeDuties.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -223,8 +219,6 @@ export class SyncCommitteeDutiesService {
}

private async getSelectionProofs(slot: Slot, duty: routes.validator.SyncDuty): Promise<SyncSelectionProof[]> {
// 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;

Expand Down

0 comments on commit cd2edf2

Please sign in to comment.