Skip to content

Commit

Permalink
Add support for EL Clients to sim tests (#4710)
Browse files Browse the repository at this point in the history
* Update sim tests structure to add new nodes

* Add new node to work to test sync

* Add sim test for checkpoint sync

* Update the checkpoint sync root

* Update seconds per slot for the simulation tests

* Update the assertion for attestaion count

* Update expectedMinParticipationRate and expectedMinSyncParticipationRate to 90%

* Update genesis delay

* Increase genesisSlotsDelay for ci

* Increase genesisSlotsDelay for ci

* Update test timeout

* Add support for EL

* Update support for multiple nodes

* Increase tcp inactivity timeout for sim tests

* Add sync assertions for range and checkpoint

* Add an estimated timeout for the sim tests

* Add support to pull geth in CI

* Update the CI for geth image

* Update the geth working directory path

* Fix sync configuration

* Fix linter warnings

* Revert "Increase tcp inactivity timeout for sim tests"

This reverts commit 3b10de8.

* Add deterministic TTD for bellatrix

* Fix geth peer connection

* Add new structure for the sim assertions

* Add new sim assertion framework

* Update error logging

* Add range sync and checkpoint sync to new structure

* Update error message logging

* Fix finality assertion check

* Fix lint error

* Rename few variable names

* Fix linter errors
  • Loading branch information
nazarhussain authored Nov 7, 2022
1 parent e1d4b1a commit 1d0b7d5
Show file tree
Hide file tree
Showing 30 changed files with 1,822 additions and 1,143 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/test-sim.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
name: Sim tests

on:
on:
push:
# We intentionally don't run push on feature branches. See PR for rational.
# We intentionally don't run push on feature branches. See PR for rational.
branches: [unstable, stable]
pull_request:
workflow_dispatch:

env:
GETH_IMAGE: https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.10.25-69568c55.tar.gz

jobs:
tests-sim:
name: Sim tests
Expand Down Expand Up @@ -36,9 +39,20 @@ jobs:
if: steps.cache-deps.outputs.cache-hit == 'true'
# </common-build>

- name: Pull Geth
run: |
TAR_NAME=$(basename $GETH_IMAGE)
BINARY_FOLDER="${TAR_NAME%.*.*}"
curl -sS $GETH_IMAGE > $TAR_NAME
tar -xvzf $TAR_NAME
echo "GETH_BINARY_DIR=$GITHUB_WORKSPACE/$BINARY_FOLDER" >> $GITHUB_ENV
- name: Simulation tests for CLI
run: yarn test:sim
working-directory: packages/cli
env:
GETH_BINARY_DIR: ${{ env.GETH_BINARY_DIR }}

- name: Upload debug log test files for "packages/cli"
if: ${{ always() }}
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"pretest": "yarn run check-types",
"test:unit": "nyc --cache-dir .nyc_output/.cache -e .ts mocha 'test/unit/**/*.test.ts'",
"test:e2e": "mocha --timeout 30000 'test/e2e/**/*.test.ts'",
"test:sim": "LODESTAR_PRESET=minimal mocha 'test/simulation/**/*.test.ts' --reporter dot",
"test:sim": "LODESTAR_PRESET=minimal ts-node --esm test/simulation/multi_fork.test.ts",
"test": "yarn test:unit && yarn test:e2e",
"coverage": "codecov -F lodestar",
"check-readme": "typescript-docs-verifier"
Expand Down
92 changes: 92 additions & 0 deletions packages/cli/test/simulation/multi_fork.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {join} from "node:path";
import {SIM_TESTS_SECONDS_PER_SLOT} from "../utils/simulation/constants.js";
import {CLClient, ELClient} from "../utils/simulation/interfaces.js";
import {SimulationEnvironment} from "../utils/simulation/SimulationEnvironment.js";
import {getEstimatedTimeInSecForRun, logFilesDir} from "../utils/simulation/utils/index.js";
import {connectAllNodes, connectNewNode} from "../utils/simulation/utils/network.js";
import {nodeAssertion} from "../utils/simulation/assertions/nodeAssertion.js";
import {mergeAssertion} from "../utils/simulation/assertions/mergeAssertion.js";

const genesisSlotsDelay = 10;
const altairForkEpoch = 2;
const bellatrixForkEpoch = 4;
const runTillEpoch = 6;
const syncWaitEpoch = 2;

const timeout =
getEstimatedTimeInSecForRun({
genesisSlotDelay: genesisSlotsDelay,
secondsPerSlot: SIM_TESTS_SECONDS_PER_SLOT,
runTill: runTillEpoch + syncWaitEpoch,
graceExtraTimeFraction: 0.1, // 10% extra time
}) * 1000;

const env = SimulationEnvironment.initWithDefaults(
{
id: "multi-fork",
logsDir: join(logFilesDir, "multi-fork"),
chainConfig: {
ALTAIR_FORK_EPOCH: altairForkEpoch,
BELLATRIX_FORK_EPOCH: bellatrixForkEpoch,
GENESIS_DELAY: genesisSlotsDelay,
},
},
[
{id: "node-1", cl: CLClient.Lodestar, el: ELClient.Geth, keysCount: 32},
{id: "node-2", cl: CLClient.Lodestar, el: ELClient.Geth, keysCount: 32},
{id: "node-3", cl: CLClient.Lodestar, el: ELClient.Geth, keysCount: 32},
{id: "node-4", cl: CLClient.Lodestar, el: ELClient.Geth, keysCount: 32},
]
);

env.tracker.register({
...nodeAssertion,
match: ({slot}) => {
return slot === 1 ? {match: true, remove: true} : false;
},
});

env.tracker.register({
...mergeAssertion,
match: ({slot}) => {
// Check at the end of bellatrix fork, merge should happen by then
return slot === env.clock.getLastSlotOfEpoch(bellatrixForkEpoch) - 1 ? {match: true, remove: true} : false;
},
});

await env.start(timeout);
await connectAllNodes(env.nodes);
await env.waitForSlot(env.clock.getLastSlotOfEpoch(bellatrixForkEpoch), env.nodes, true);

const {
data: {finalized},
} = await env.nodes[0].cl.api.beacon.getStateFinalityCheckpoints("head");

const rangeSync = env.createNodePair({
id: "range-sync-node",
cl: CLClient.Lodestar,
el: ELClient.Geth,
keysCount: 0,
});

const checkpointSync = env.createNodePair({
id: "checkpoint-sync-node",
cl: CLClient.Lodestar,
el: ELClient.Geth,
keysCount: 0,
wssCheckpoint: `${finalized.root}:${finalized.epoch}`,
});

await rangeSync.jobs.el.start();
await rangeSync.jobs.cl.start();
await connectNewNode(rangeSync.nodePair, env.nodes);

await checkpointSync.jobs.el.start();
await checkpointSync.jobs.cl.start();
await connectNewNode(checkpointSync.nodePair, env.nodes);

await env.waitForNodeSync(rangeSync.nodePair);
await env.waitForNodeSync(checkpointSync.nodePair);

await env.stop();
213 changes: 0 additions & 213 deletions packages/cli/test/simulation/simulation.test.ts

This file was deleted.

Loading

0 comments on commit 1d0b7d5

Please sign in to comment.