Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/validation/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export async function validateGossipAttestationsSameAttData(
chain.seenAttesters.add(targetEpoch, validatorIndex);
} else {
step0ResultOrErrors[oldIndex] = {
err: new AttestationError(GossipAction.IGNORE, {
err: new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.INVALID_SIGNATURE,
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
assertValidAttesterSlashing,
getAttesterSlashableIndices,
getAttesterSlashingSignatureSets,
isSlashableValidator,
} from "@lodestar/state-transition";
import {AttesterSlashing} from "@lodestar/types";
import {AttesterSlashingError, AttesterSlashingErrorCode, GossipAction} from "../errors/index.js";
Expand Down Expand Up @@ -58,6 +59,14 @@ export async function validateAttesterSlashing(
});
}

const currentEpoch = state.epochCtx.epoch;
if (!intersectingIndices.some((index) => isSlashableValidator(state.validators.getReadonly(index), currentEpoch))) {
throw new AttesterSlashingError(GossipAction.REJECT, {
code: AttesterSlashingErrorCode.INVALID,
error: Error("AttesterSlashing has no slashable validators"),
});
}

const signatureSets = getAttesterSlashingSignatureSets(chain.config, state.slot, attesterSlashing);
if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
throw new AttesterSlashingError(GossipAction.REJECT, {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/validation/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function validateGossipBlock(

// [REJECT] The block is from a higher slot than its parent.
if (parentBlock.slot >= blockSlot) {
throw new BlockGossipError(GossipAction.IGNORE, {
throw new BlockGossipError(GossipAction.REJECT, {
code: BlockErrorCode.NOT_LATER_THAN_PARENT,
parentSlot: parentBlock.slot,
slot: blockSlot,
Expand Down
68 changes: 45 additions & 23 deletions packages/beacon-node/test/spec/presets/networking.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import fs from "node:fs";
import path from "node:path";
import {expect, it} from "vitest";
import {config} from "@lodestar/config/default";
import {ACTIVE_PRESET} from "@lodestar/params";
import {InputType} from "@lodestar/spec-test-util";
import {bigIntToBytes} from "@lodestar/utils";
import {bigIntToBytes, loadYaml} from "@lodestar/utils";
import {computeColumnsForCustodyGroup, getCustodyGroups} from "../../../src/util/dataColumns.js";
import {ethereumConsensusSpecsTests} from "../specTestVersioning.js";
import {specTestIterator} from "../utils/specTestIterator.js";
import {RunnerType, TestRunnerFn} from "../utils/types.js";
import {isGossipValidationHandler, runGossipValidationTest} from "../utils/gossipValidation.js";
import {readdirSyncSpec, specTestIterator} from "../utils/specTestIterator.js";
import {RunnerType, TestRunnerCustom} from "../utils/types.js";

type ComputeColumnForCustodyGroupInput = {
custody_group: number;
Expand All @@ -28,30 +30,50 @@ const networkingFns: Record<string, NetworkFn> = {
},
};

const networking: TestRunnerFn<NetworkingTestCase, unknown> = (_fork, testName) => {
return {
testFunction: (testcase) => {
const networkingFn = networkingFns[testName];
if (networkingFn === undefined) {
throw Error(`No networkingFn for ${testName}`);
}

return networkingFn(testcase.meta);
},
options: {
inputTypes: {meta: InputType.YAML},
getExpected: (testCase) => testCase.meta.result.map(Number),
// Do not manually skip tests here, do it in packages/beacon-node/test/spec/presets/index.test.ts
},
};
};

type NetworkingTestCase = {
meta: {
result: number[];
};
};

function loadNetworkingTestMeta(testCaseDir: string): NetworkingTestCase["meta"] {
return loadYaml<NetworkingTestCase["meta"]>(fs.readFileSync(path.join(testCaseDir, "meta.yaml"), "utf8"));
}

function runNetworkingFnTests(testHandler: string, testSuite: string, testSuiteDirpath: string): void {
const networkingFn = networkingFns[testHandler];
if (networkingFn === undefined) {
throw Error(`No networkingFn for ${testHandler}`);
}

for (const testCaseName of readdirSyncSpec(testSuiteDirpath)) {
const testCaseDir = path.join(testSuiteDirpath, testCaseName);
it(testCaseName, () => {
const meta = loadNetworkingTestMeta(testCaseDir);
const actual = networkingFn(meta);
expect(actual).toEqualWithMessage(
meta.result.map(Number),
`Unexpected networking result for ${testHandler}/${testSuite}/${testCaseName}`
);
});
}
}

const networking: TestRunnerCustom = (fork, testHandler, testSuite, testSuiteDirpath) => {
if (isGossipValidationHandler(testHandler)) {
for (const testCaseName of readdirSyncSpec(testSuiteDirpath)) {
const testCaseDir = path.join(testSuiteDirpath, testCaseName);
it(testCaseName, async () => {
await runGossipValidationTest(fork, testHandler, testCaseDir);
}, 30_000);
}
} else if (networkingFns[testHandler] !== undefined) {
runNetworkingFnTests(testHandler, testSuite, testSuiteDirpath);
} else {
throw new Error(`No runner for networking handler ${testHandler}`);
}
};

specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), {
networking: {type: RunnerType.default, fn: networking},
networking: {type: RunnerType.custom, fn: networking},
});
Loading
Loading