-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update computeDeltas perf test
- Loading branch information
Showing
1 changed file
with
43 additions
and
79 deletions.
There are no files selected for viewing
122 changes: 43 additions & 79 deletions
122
packages/fork-choice/test/perf/protoArray/computeDeltas.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,62 @@ | ||
import {itBench, setBenchOpts} from "@dapplion/benchmark"; | ||
import {expect} from "chai"; | ||
import { | ||
CachedBeaconStateAltair, | ||
computeStartSlotAtEpoch, | ||
EffectiveBalanceIncrements, | ||
getEffectiveBalanceIncrementsZeroed, | ||
} from "@lodestar/state-transition"; | ||
import {TIMELY_SOURCE_FLAG_INDEX} from "@lodestar/params"; | ||
// eslint-disable-next-line import/no-relative-packages | ||
import {generatePerfTestCachedStateAltair} from "../../../../state-transition/test/perf/util.js"; | ||
import {EffectiveBalanceIncrements, getEffectiveBalanceIncrementsZeroed} from "@lodestar/state-transition"; | ||
import {VoteTracker} from "../../../src/protoArray/interface.js"; | ||
import {computeDeltas} from "../../../src/protoArray/computeDeltas.js"; | ||
import {computeProposerBoostScoreFromBalances} from "../../../src/forkChoice/forkChoice.js"; | ||
|
||
/** Same to https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.5/specs/altair/beacon-chain.md#has_flag */ | ||
const TIMELY_SOURCE = 1 << TIMELY_SOURCE_FLAG_INDEX; | ||
function flagIsTimelySource(flag: number): boolean { | ||
return (flag & TIMELY_SOURCE) === TIMELY_SOURCE; | ||
} | ||
|
||
describe("computeDeltas", () => { | ||
let originalState: CachedBeaconStateAltair; | ||
const indices: Map<string, number> = new Map<string, number>(); | ||
let oldBalances: EffectiveBalanceIncrements; | ||
let newBalances: EffectiveBalanceIncrements; | ||
|
||
const oldRoot = "0x32dec344944029ba183ac387a7aa1f2068591c00e9bfadcfb238e50fbe9ea38e"; | ||
const newRoot = "0xb59f3a209f639dd6b5645ea9fad8d441df44c3be93bd1bbf50ef90bf124d1238"; | ||
|
||
before(function () { | ||
this.timeout(2 * 60 * 1000); // Generating the states for the first time is very slow | ||
|
||
originalState = generatePerfTestCachedStateAltair({goBackOneSlot: true}); | ||
|
||
const previousEpochParticipationArr = originalState.previousEpochParticipation.getAll(); | ||
const currentEpochParticipationArr = originalState.currentEpochParticipation.getAll(); | ||
|
||
const numPreviousEpochParticipation = previousEpochParticipationArr.filter(flagIsTimelySource).length; | ||
const numCurrentEpochParticipation = currentEpochParticipationArr.filter(flagIsTimelySource).length; | ||
|
||
expect(numPreviousEpochParticipation).to.equal(250000, "Wrong numPreviousEpochParticipation"); | ||
expect(numCurrentEpochParticipation).to.equal(250000, "Wrong numCurrentEpochParticipation"); | ||
|
||
oldBalances = getEffectiveBalanceIncrementsZeroed(numPreviousEpochParticipation); | ||
newBalances = getEffectiveBalanceIncrementsZeroed(numPreviousEpochParticipation); | ||
|
||
for (let i = 0; i < numPreviousEpochParticipation; i++) { | ||
oldBalances[i] = 32; | ||
newBalances[i] = 32; | ||
} | ||
for (let i = 0; i < 10000; i++) { | ||
indices.set("" + i, i); | ||
} | ||
indices.set(oldRoot, 1001); | ||
indices.set(newRoot, 1001); | ||
}); | ||
|
||
setBenchOpts({ | ||
minMs: 30 * 1000, | ||
maxMs: 40 * 1000, | ||
}); | ||
|
||
itBench({ | ||
id: "computeDeltas", | ||
beforeEach: () => { | ||
const votes: VoteTracker[] = []; | ||
const epoch = originalState.epochCtx.currentShuffling.epoch; | ||
const committee = originalState.epochCtx.getBeaconCommittee(computeStartSlotAtEpoch(epoch), 0); | ||
for (let i = 0; i < 250000; i++) { | ||
if (committee.includes(i)) { | ||
for (const numValidator of [800_000, 2_100_100]) { | ||
before(function () { | ||
this.timeout(2 * 60 * 1000); | ||
oldBalances = getEffectiveBalanceIncrementsZeroed(numValidator); | ||
newBalances = getEffectiveBalanceIncrementsZeroed(numValidator); | ||
|
||
for (let i = 0; i < numValidator; i++) { | ||
oldBalances[i] = 32; | ||
newBalances[i] = 32; | ||
} | ||
for (let i = 0; i < 10000; i++) { | ||
indices.set("" + i, i); | ||
} | ||
indices.set(oldRoot, 1001); | ||
indices.set(newRoot, 1002); | ||
}); | ||
|
||
setBenchOpts({ | ||
minMs: 30 * 1000, | ||
maxMs: 40 * 1000, | ||
}); | ||
|
||
itBench({ | ||
id: `computeDeltas ${numValidator} validators`, | ||
beforeEach: () => { | ||
const votes: VoteTracker[] = []; | ||
const epoch = 100_000; | ||
for (let i = 0; i < numValidator; i++) { | ||
votes.push({ | ||
currentRoot: oldRoot, | ||
nextRoot: newRoot, | ||
nextEpoch: epoch, | ||
}); | ||
} else { | ||
votes.push({ | ||
currentRoot: oldRoot, | ||
nextRoot: oldRoot, | ||
nextEpoch: epoch - 1, | ||
}); | ||
} | ||
} | ||
return votes; | ||
}, | ||
fn: (votes) => { | ||
computeDeltas(indices, votes, oldBalances, newBalances, new Set()); | ||
}, | ||
}); | ||
|
||
itBench({ | ||
id: "computeProposerBoostScoreFromBalances", | ||
fn: () => { | ||
computeProposerBoostScoreFromBalances(newBalances, {slotsPerEpoch: 32, proposerScoreBoost: 70}); | ||
}, | ||
}); | ||
return votes; | ||
}, | ||
fn: (votes) => { | ||
computeDeltas(indices, votes, oldBalances, newBalances, new Set()); | ||
}, | ||
}); | ||
|
||
itBench({ | ||
id: `computeProposerBoostScoreFromBalances ${numValidator} validators`, | ||
fn: () => { | ||
computeProposerBoostScoreFromBalances(newBalances, {slotsPerEpoch: 32, proposerScoreBoost: 70}); | ||
}, | ||
}); | ||
} | ||
}); |