Skip to content

Commit

Permalink
Add benchmark for empty block body
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Nov 30, 2023
1 parent 2ea45a3 commit 3d8defc
Showing 1 changed file with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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,
});
},
});
});

0 comments on commit 3d8defc

Please sign in to comment.