From 3d8defc498cd176750cb4948ec9416e0bcd36767 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 30 Nov 2023 18:37:10 +0100 Subject: [PATCH] Add benchmark for empty block body --- .../produceBlock/produceBlockBody.test.ts | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 packages/beacon-node/test/perf/chain/produceBlock/produceBlockBody.test.ts diff --git a/packages/beacon-node/test/perf/chain/produceBlock/produceBlockBody.test.ts b/packages/beacon-node/test/perf/chain/produceBlock/produceBlockBody.test.ts new file mode 100644 index 000000000000..1892281cfe7c --- /dev/null +++ b/packages/beacon-node/test/perf/chain/produceBlock/produceBlockBody.test.ts @@ -0,0 +1,87 @@ +import {fromHexString} from "@chainsafe/ssz"; +import {itBench} from "@dapplion/benchmark"; +import {config} from "@lodestar/config/default"; +import {LevelDbController} from "@lodestar/db"; +import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params"; +import {defaultOptions as defaultValidatorOptions} from "@lodestar/validator"; +import {CachedBeaconStateAltair} from "@lodestar/state-transition"; +// eslint-disable-next-line import/no-relative-packages +import {generatePerfTestCachedStateAltair} from "../../../../../state-transition/test/perf/util.js"; +import {BeaconChain} from "../../../../src/chain/index.js"; +import {BlockType, produceBlockBody} from "../../../../src/chain/produceBlock/produceBlockBody.js"; +import {Eth1ForBlockProductionDisabled} from "../../../../src/eth1/index.js"; +import {ExecutionEngineDisabled} from "../../../../src/execution/engine/index.js"; +import {BeaconDb} from "../../../../src/index.js"; +import {testLogger} from "../../../utils/logger.js"; + +const logger = testLogger(); +const numberOfValidators = 1024; + +describe("produceBlockBody", () => { + const stateOg = generatePerfTestCachedStateAltair({goBackOneSlot: false, vc: numberOfValidators}); + + let db: BeaconDb; + let chain: BeaconChain; + let state: CachedBeaconStateAltair; + + before(async () => { + db = new BeaconDb(config, await LevelDbController.create({name: ".tmpdb"}, {logger})); + state = stateOg.clone(); + chain = new BeaconChain( + { + proposerBoostEnabled: true, + computeUnrealized: false, + safeSlotsToImportOptimistically: SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY, + disableArchiveOnCheckpoint: true, + suggestedFeeRecipient: defaultValidatorOptions.suggestedFeeRecipient, + skipCreateStateCacheIfAvailable: true, + archiveStateEpochFrequency: 1024, + minSameMessageSignatureSetsToBatch: 32, + }, + { + config: state.config, + db, + logger, + // eslint-disable-next-line @typescript-eslint/no-empty-function + processShutdownCallback: () => {}, + metrics: null, + anchorState: state, + eth1: new Eth1ForBlockProductionDisabled(), + executionEngine: new ExecutionEngineDisabled(), + } + ); + }); + + after(async () => { + // If before blocks fail, db won't be declared + if (db !== undefined) await db.close(); + if (chain !== undefined) await chain.close(); + }); + + itBench({ + id: "proposeBlockBody type=full, size=empty", + minRuns: 5, + maxMs: Infinity, + timeoutBench: 60 * 1000, + beforeEach: async () => { + const head = chain.forkChoice.getHead(); + const proposerIndex = state.epochCtx.getBeaconProposer(state.slot); + const proposerPubKey = state.epochCtx.index2pubkey[proposerIndex].toBytes(); + + return {chain, state, head, proposerIndex, proposerPubKey}; + }, + fn: async ({chain, state, head, proposerIndex, proposerPubKey}) => { + const slot = state.slot; + + await produceBlockBody.call(chain, BlockType.Full, state, { + parentSlot: slot, + slot: slot + 1, + graffiti: Buffer.alloc(32), + randaoReveal: Buffer.alloc(96), + parentBlockRoot: fromHexString(head.blockRoot), + proposerIndex, + proposerPubKey, + }); + }, + }); +});