From e5af6a4856fd62d42208b2507afd81fbeb761c23 Mon Sep 17 00:00:00 2001 From: Lion - dapplion <35266934+dapplion@users.noreply.github.com> Date: Tue, 31 Aug 2021 13:14:01 +0200 Subject: [PATCH] Add shufflings test (#3050) --- .../perf/allForks/util/shufflings.test.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 packages/beacon-state-transition/test/perf/allForks/util/shufflings.test.ts diff --git a/packages/beacon-state-transition/test/perf/allForks/util/shufflings.test.ts b/packages/beacon-state-transition/test/perf/allForks/util/shufflings.test.ts new file mode 100644 index 000000000000..e6d933a938d3 --- /dev/null +++ b/packages/beacon-state-transition/test/perf/allForks/util/shufflings.test.ts @@ -0,0 +1,41 @@ +import {itBench} from "@dapplion/benchmark"; +import {Epoch} from "@chainsafe/lodestar-types"; +import {allForks, computeEpochAtSlot} from "../../../../src"; +import {computeEpochShuffling, computeProposers} from "../../../../src/allForks"; +import {generatePerfTestCachedStatePhase0, numValidators} from "../../util"; +import {getNextSyncCommittee} from "../../../../src/altair/util/syncCommittee"; + +describe("epoch shufflings", () => { + let state: allForks.CachedBeaconState; + let nextEpoch: Epoch; + + before(function () { + this.timeout(60 * 1000); + state = generatePerfTestCachedStatePhase0() as allForks.CachedBeaconState; + nextEpoch = computeEpochAtSlot(state.slot) + 1; + + // Sanity check to ensure numValidators doesn't go stale + if (state.validators.length !== numValidators) throw Error("constant numValidators is wrong"); + }); + + itBench({ + id: `computeProposers - vc ${numValidators}`, + fn: () => { + computeProposers(state, state.epochCtx.nextShuffling); + }, + }); + + itBench({ + id: `computeEpochShuffling - vc ${numValidators}`, + fn: () => { + computeEpochShuffling(state, state.epochCtx.nextShuffling.activeIndices, nextEpoch); + }, + }); + + itBench({ + id: `getNextSyncCommittee - vc ${numValidators}`, + fn: () => { + getNextSyncCommittee(state, state.epochCtx.nextShuffling.activeIndices); + }, + }); +});