Skip to content

Commit

Permalink
Add assertions for the head and finality (#4573)
Browse files Browse the repository at this point in the history
* Add assertions for the head and finality

* Remove duplicate tests form beacon-node package

* Fix the order of assertions

* Remove a debug logging

* Fix assertions

* Fix attestation issue for slot 16

* Update number of epochs for tests

* Remove debug logging

* Update the attestation validity condition
  • Loading branch information
nazarhussain committed Sep 23, 2022
1 parent fd8e335 commit bfeb48a
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ export function isValidAttestationData(
if (!ssz.phase0.Checkpoint.equals(data.source, justifiedCheckpoint)) return false;

// Shuffling can't have changed if we're in the first few epochs
if (stateEpoch < 2) {
// Also we can't look back 2 epochs if target epoch is 1 or less
if (stateEpoch < 2 || targetEpoch < 2) {
return true;
}
// Otherwise the shuffling is determined by the block at the end of the target epoch
Expand Down
154 changes: 0 additions & 154 deletions packages/beacon-node/test/sim/multiNodeMultiThread.test.ts

This file was deleted.

95 changes: 0 additions & 95 deletions packages/beacon-node/test/sim/threaded/noEth1SimWorker.ts

This file was deleted.

29 changes: 0 additions & 29 deletions packages/beacon-node/test/sim/threaded/types.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/beacon-node/test/sim/threaded/worker.js

This file was deleted.

33 changes: 30 additions & 3 deletions packages/cli/test/simulation/simulation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import {join} from "node:path";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import {Epoch} from "@lodestar/types";
import {SLOTS_PER_EPOCH} from "@lodestar/params";
import {logFilesDir, SimulationEnvironment} from "../utils/simulation/index.js";
import {
missedBlocksAssertions,
attestationParticipationAssertions,
nodeAssertions,
inclusionDelayAssertions,
attestationPerSlotAssertions,
finalityAssertions,
headsAssertions,
} from "../utils/simulation/assertions.js";

chai.use(chaiAsPromised);
Expand All @@ -30,9 +35,12 @@ const forksCases: {
},
// {
// title: "mixed forks with remote signer",
// params: {altairEpoch: 2, bellatrixEpoch: 4, withExternalSigner: true, runTill: 6},
// params: {altairEpoch: 1, bellatrixEpoch: 2, withExternalSigner: true, runTill: 3},
// },
];

let testCases = 0;

for (const {beaconNodes, validatorClients, validatorsPerClient} of nodeCases) {
for (const {
title,
Expand Down Expand Up @@ -62,10 +70,13 @@ for (const {beaconNodes, validatorClients, validatorsPerClient} of nodeCases) {
validatorClients,
validatorsPerClient,
altairEpoch,
// TODO: Use extra delay until env.clock is based on absolute time
genesisSlotsDelay: (SLOTS_PER_EPOCH * runTill + 50) * testCases + 30,
bellatrixEpoch,
logFilesDir: join(logFilesDir, testIdStr),
externalSigner: withExternalSigner,
});
testCases += 1;

describe(`simulation test - ${testIdStr}`, function () {
this.timeout("5m");
Expand All @@ -77,8 +88,8 @@ for (const {beaconNodes, validatorClients, validatorsPerClient} of nodeCases) {
});

after("stop env", async () => {
env.resetCounter();
await env.stop();
env.tracker.printNoesInfo();
});

describe("nodes env", () => {
Expand All @@ -95,7 +106,23 @@ for (const {beaconNodes, validatorClients, validatorsPerClient} of nodeCases) {
});

describe("missed blocks", () => {
missedBlocksAssertions(env);
missedBlocksAssertions(env, epoch);
});

describe("finality", () => {
finalityAssertions(env, epoch);
});

describe("heads", () => {
headsAssertions(env, epoch);
});

describe("inclusion delay", () => {
inclusionDelayAssertions(env, epoch);
});

describe("attestation count per slot", () => {
attestationPerSlotAssertions(env, epoch);
});

describe("attestation participation", () => {
Expand Down

0 comments on commit bfeb48a

Please sign in to comment.