Skip to content

Commit

Permalink
fix: validate gossip attestation perf test
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jul 5, 2023
1 parent 256cd4a commit a830c42
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions packages/beacon-node/test/perf/chain/validation/attestation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {ssz} from "@lodestar/types";
import {validateAttestation, validateGossipAttestationsSameAttData} from "../../../../src/chain/validation/index.js";
import {generateTestCachedBeaconStateOnlyValidators} from "../../../../../state-transition/test/perf/util.js";
import {getAttestationValidData} from "../../../utils/validationData/attestation.js";
import {getAttDataBase64FromAttestationSerialized} from "../../../../src/util/sszBytes.js";

describe("validate gossip attestation", () => {
setBenchOpts({
Expand All @@ -14,7 +15,6 @@ describe("validate gossip attestation", () => {
const stateSlot = 100;
const state = generateTestCachedBeaconStateOnlyValidators({vc, slot: stateSlot});

const chunkSize = 64;
const {
chain,
attestation: attestation0,
Expand All @@ -26,16 +26,6 @@ describe("validate gossip attestation", () => {
// enable this in local environment to match production
// blsVerifyAllMainThread: false,
});
const attestations = [attestation0];
for (let i = 1; i < chunkSize; i++) {
const {attestation, subnet} = getAttestationValidData({
currentSlot: stateSlot,
state,
bitIndex: i,
});
expect(subnet).to.be.equal(subnet0);
attestations.push(attestation);
}

const attSlot = attestation0.data.slot;
const serializedData = ssz.phase0.Attestation.serialize(attestation0);
Expand All @@ -44,24 +34,48 @@ describe("validate gossip attestation", () => {
id: `validate gossip attestation - vc ${vc}`,
beforeEach: () => chain.seenAttesters["validatorIndexesByEpoch"].clear(),
fn: async () => {
await validateAttestation(chain, {attestation: null, serializedData, attSlot}, subnet0);
await validateAttestation(
chain,
{
attestation: null,
serializedData,
attSlot,
attDataBase64: getAttDataBase64FromAttestationSerialized(serializedData),
},
subnet0
);
},
});

const attestationOrBytesArr = attestations.map((att) => {
return {
attestation: null,
serializedData: ssz.phase0.Attestation.serialize(att),
attSlot,
};
});
for (const chunkSize of [32, 64, 128, 256]) {
const attestations = [attestation0];
for (let i = 1; i < chunkSize; i++) {
const {attestation, subnet} = getAttestationValidData({
currentSlot: stateSlot,
state,
bitIndex: i,
});
expect(subnet).to.be.equal(subnet0);
attestations.push(attestation);
}

itBench({
id: `batch validate gossip attestation - vc ${vc} - chunk ${chunkSize}`,
beforeEach: () => chain.seenAttesters["validatorIndexesByEpoch"].clear(),
fn: async () => {
await validateGossipAttestationsSameAttData(chain, attestationOrBytesArr, subnet0);
},
runsFactor: chunkSize,
});
const attestationOrBytesArr = attestations.map((att) => {
const serializedData = ssz.phase0.Attestation.serialize(att);
return {
attestation: null,
serializedData,
attSlot,
attDataBase64: getAttDataBase64FromAttestationSerialized(serializedData)
};
});

itBench({
id: `batch validate gossip attestation - vc ${vc} - chunk ${chunkSize}`,
beforeEach: () => chain.seenAttesters["validatorIndexesByEpoch"].clear(),
fn: async () => {
await validateGossipAttestationsSameAttData(chain, attestationOrBytesArr, subnet0);
},
runsFactor: chunkSize,
});
}
});

0 comments on commit a830c42

Please sign in to comment.