From c4bf38576e0cba5880697de3a5ca4956162ede5e Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Tue, 6 Feb 2024 09:37:14 +0100 Subject: [PATCH] chore: fix failing sim tests (#6389) * Disable /ipfs/id/push/1.0.0 * Fix the peer disconnect errors * Align genesis time for logging * Fix genesis state issue * Increase timeotu for keystore unit test * Remove unintended protocol * Fix the test timeout * Update stopChildProcess * Update the @chainsafe/libp2p-identify * Compute effective genesis delay * Update workflow file to make it consistent * Increase the genesis delay calculation --- .github/workflows/test-sim.yml | 20 +++++++-- packages/beacon-node/package.json | 1 + .../beacon-node/src/network/libp2p/index.ts | 3 +- .../cli/test/sim/backup_eth_provider.test.ts | 1 + packages/cli/test/sim/deneb.test.ts | 5 ++- packages/cli/test/sim/endpoints.test.ts | 1 + packages/cli/test/sim/mixed_client.test.ts | 1 + packages/cli/test/sim/multi_fork.test.ts | 1 + .../keymanager/keystoreCache.test.ts | 5 ++- .../cli/test/utils/simulation/utils/index.ts | 30 ++++++++++++- .../simulation/validator_clients/index.ts | 4 +- .../validator_clients/lighthouse.ts | 1 - .../simulation/validator_clients/lodestar.ts | 2 +- packages/test-utils/src/childProcess.ts | 26 +++++++++++- yarn.lock | 42 +++++++++++++++++++ 15 files changed, 127 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test-sim.yml b/.github/workflows/test-sim.yml index 65260fc38937..a90152d4ee3b 100644 --- a/.github/workflows/test-sim.yml +++ b/.github/workflows/test-sim.yml @@ -58,6 +58,12 @@ jobs: if: steps.cache-deps.outputs.cache-hit == 'true' # + - name: Download required docker images before running tests + run: | + docker pull ${{env.GETH_DOCKER_IMAGE}} + docker pull ${{env.LIGHTHOUSE_DOCKER_IMAGE}} + docker pull ${{env.NETHERMIND_DOCKER_IMAGE}} + - name: Sim tests multifork run: DEBUG='${{github.event.inputs.debug}}' yarn test:sim:multifork working-directory: packages/cli @@ -65,20 +71,28 @@ jobs: GENESIS_DELAY_SLOTS: ${{github.event.inputs.genesisDelaySlots}} - name: Sim tests endpoints - run: yarn test:sim:endpoints + run: DEBUG='${{github.event.inputs.debug}}' yarn test:sim:endpoints working-directory: packages/cli + env: + GENESIS_DELAY_SLOTS: ${{github.event.inputs.genesisDelaySlots}} - name: Sim tests deneb - run: yarn test:sim:deneb + run: DEBUG='${{github.event.inputs.debug}}' yarn test:sim:deneb working-directory: packages/cli + env: + GENESIS_DELAY_SLOTS: ${{github.event.inputs.genesisDelaySlots}} - name: Sim tests backup eth provider - run: yarn test:sim:backup_eth_provider + run: DEBUG='${{github.event.inputs.debug}}' yarn test:sim:backup_eth_provider working-directory: packages/cli + env: + GENESIS_DELAY_SLOTS: ${{github.event.inputs.genesisDelaySlots}} - name: Sim tests mixed client run: DEBUG='${{github.event.inputs.debug}}' yarn test:sim:mixedclient working-directory: packages/cli + env: + GENESIS_DELAY_SLOTS: ${{github.event.inputs.genesisDelaySlots}} - name: Upload debug log test files for "packages/cli" if: ${{ always() }} diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 90f2026e1873..f24963622d93 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -102,6 +102,7 @@ "@chainsafe/enr": "^3.0.0", "@chainsafe/libp2p-gossipsub": "^11.2.0", "@chainsafe/libp2p-noise": "^14.1.0", + "@chainsafe/libp2p-identify": "^1.0.0", "@chainsafe/persistent-merkle-tree": "^0.6.1", "@chainsafe/prometheus-gc-stats": "^1.0.0", "@chainsafe/ssz": "^0.14.0", diff --git a/packages/beacon-node/src/network/libp2p/index.ts b/packages/beacon-node/src/network/libp2p/index.ts index ccbd07355c32..8a8cca38c167 100644 --- a/packages/beacon-node/src/network/libp2p/index.ts +++ b/packages/beacon-node/src/network/libp2p/index.ts @@ -1,7 +1,8 @@ import {PeerId} from "@libp2p/interface"; import {Registry} from "prom-client"; import {ENR} from "@chainsafe/enr"; -import {identify} from "@libp2p/identify"; +// TODO: We should use this fork until https://github.com/libp2p/js-libp2p/pull/2387 +import {identify} from "@chainsafe/libp2p-identify"; import {bootstrap} from "@libp2p/bootstrap"; import {mdns} from "@libp2p/mdns"; import {createLibp2p} from "libp2p"; diff --git a/packages/cli/test/sim/backup_eth_provider.test.ts b/packages/cli/test/sim/backup_eth_provider.test.ts index 40ad7d4661de..5a38a27dc8f0 100644 --- a/packages/cli/test/sim/backup_eth_provider.test.ts +++ b/packages/cli/test/sim/backup_eth_provider.test.ts @@ -16,6 +16,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({ ALTAIR_FORK_EPOCH: altairForkEpoch, BELLATRIX_FORK_EPOCH: bellatrixForkEpoch, runTillEpoch: runTillEpoch + syncWaitEpoch, + initialNodes: 3, }); const env = await SimulationEnvironment.initWithDefaults( diff --git a/packages/cli/test/sim/deneb.test.ts b/packages/cli/test/sim/deneb.test.ts index 5ed84d3d2792..b66252b06892 100644 --- a/packages/cli/test/sim/deneb.test.ts +++ b/packages/cli/test/sim/deneb.test.ts @@ -18,12 +18,13 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({ ALTAIR_FORK_EPOCH: altairForkEpoch, BELLATRIX_FORK_EPOCH: bellatrixForkEpoch, runTillEpoch: runTillEpoch + syncWaitEpoch, + initialNodes: 2, }); const env = await SimulationEnvironment.initWithDefaults( { - id: "multi-fork", - logsDir: path.join(logFilesDir, "multi-fork"), + id: "deneb", + logsDir: path.join(logFilesDir, "deneb"), forkConfig, }, [ diff --git a/packages/cli/test/sim/endpoints.test.ts b/packages/cli/test/sim/endpoints.test.ts index ea55b70e26c1..a31b561e0578 100644 --- a/packages/cli/test/sim/endpoints.test.ts +++ b/packages/cli/test/sim/endpoints.test.ts @@ -16,6 +16,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({ ALTAIR_FORK_EPOCH: altairForkEpoch, BELLATRIX_FORK_EPOCH: bellatrixForkEpoch, runTillEpoch: 2, + initialNodes: 1, }); const env = await SimulationEnvironment.initWithDefaults( diff --git a/packages/cli/test/sim/mixed_client.test.ts b/packages/cli/test/sim/mixed_client.test.ts index ad2095f8c378..80c20471ede5 100644 --- a/packages/cli/test/sim/mixed_client.test.ts +++ b/packages/cli/test/sim/mixed_client.test.ts @@ -17,6 +17,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({ BELLATRIX_FORK_EPOCH: bellatrixForkEpoch, CAPELLA_FORK_EPOCH: capellaForkEpoch, runTillEpoch: runTillEpoch + syncWaitEpoch, + initialNodes: 2, }); const env = await SimulationEnvironment.initWithDefaults( diff --git a/packages/cli/test/sim/multi_fork.test.ts b/packages/cli/test/sim/multi_fork.test.ts index 24f42498c638..70f119609454 100644 --- a/packages/cli/test/sim/multi_fork.test.ts +++ b/packages/cli/test/sim/multi_fork.test.ts @@ -27,6 +27,7 @@ const {estimatedTimeoutMs, forkConfig} = defineSimTestConfig({ BELLATRIX_FORK_EPOCH: bellatrixForkEpoch, CAPELLA_FORK_EPOCH: capellaForkEpoch, runTillEpoch: runTillEpoch + syncWaitEpoch, + initialNodes: 5, }); const env = await SimulationEnvironment.initWithDefaults( diff --git a/packages/cli/test/unit/cmds/validator/keymanager/keystoreCache.test.ts b/packages/cli/test/unit/cmds/validator/keymanager/keystoreCache.test.ts index ee0fedf301b6..40964a0a7b7d 100644 --- a/packages/cli/test/unit/cmds/validator/keymanager/keystoreCache.test.ts +++ b/packages/cli/test/unit/cmds/validator/keymanager/keystoreCache.test.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; import {randomBytes} from "node:crypto"; -import {describe, it, expect, beforeEach} from "vitest"; +import {describe, it, expect, beforeEach, vi} from "vitest"; import tmp from "tmp"; import {Keystore} from "@chainsafe/bls-keystore"; import bls from "@chainsafe/bls"; @@ -12,6 +12,7 @@ import {LocalKeystoreDefinition} from "../../../../../src/cmds/validator/keymana const numberOfSigners = 10; describe("keystoreCache", () => { + vi.setConfig({testTimeout: 10000, hookTimeout: 50000}); let definitions: LocalKeystoreDefinition[]; let signers: SignerLocal[]; let secretKeys: Uint8Array[]; @@ -50,7 +51,7 @@ describe("keystoreCache", () => { passwords.push(password); secretKeys.push(secretKey.toBytes()); } - }, 50000); + }); describe("writeKeystoreCache", () => { it("should write a valid keystore cache file", async () => { diff --git a/packages/cli/test/utils/simulation/utils/index.ts b/packages/cli/test/utils/simulation/utils/index.ts index dfa66bed6580..bc0a4ee98d6f 100644 --- a/packages/cli/test/utils/simulation/utils/index.ts +++ b/packages/cli/test/utils/simulation/utils/index.ts @@ -17,18 +17,44 @@ export const avg = (arr: number[]): number => { return arr.length === 0 ? 0 : arr.reduce((p, c) => p + c, 0) / arr.length; }; +function getGenesisDelaySlots(initialNodes?: number): number { + if (process.env.GENESIS_DELAY_SLOTS) { + const genesisDelaySlots = parseInt(process.env.GENESIS_DELAY_SLOTS); + // If custom job is invoked and want to use default genesis delay then provider -1 as value + if (genesisDelaySlots >= 0) return genesisDelaySlots; + } + + if (initialNodes == null) return 40; + // Considering each node consists of EN, BN, VC and KM + // EN - Execution Node - 15s + const execution = 15; + // BN - Beacon Node - 15s + const beacon = 15; + // VC - Validator Client - 10s + const validator = 10; + // KM - Key Manager - 3s + const keyManager = 3; + // Initial script launch time - 10s + const initialLaunchScript = 10; + + return Math.ceil( + ((execution + beacon + validator + keyManager) * initialNodes + initialLaunchScript) / SIM_TESTS_SECONDS_PER_SLOT + ); +} + export function defineSimTestConfig( opts: Partial & { cliqueSealingPeriod?: number; additionalSlotsForTTD?: number; runTillEpoch: number; + // Used to calculate genesis delay + initialNodes?: number; } ): { estimatedTimeoutMs: number; forkConfig: ChainForkConfig; } { - const genesisDelaySeconds = - (process.env.GENESIS_DELAY_SLOTS ? parseInt(process.env.GENESIS_DELAY_SLOTS) : 40) * SIM_TESTS_SECONDS_PER_SLOT; + const genesisDelaySeconds = getGenesisDelaySlots(opts.initialNodes) * SIM_TESTS_SECONDS_PER_SLOT; const estimatedTimeoutMs = getEstimatedTimeInSecForRun({ diff --git a/packages/cli/test/utils/simulation/validator_clients/index.ts b/packages/cli/test/utils/simulation/validator_clients/index.ts index 1334382407e8..a75cbf6b1660 100644 --- a/packages/cli/test/utils/simulation/validator_clients/index.ts +++ b/packages/cli/test/utils/simulation/validator_clients/index.ts @@ -14,14 +14,14 @@ export async function createValidatorNode( "id" | "paths" | "forkConfig" | "nodeIndex" | "genesisTime" | "runner" | "beaconUrls" > ): Promise { - const {runner, forkConfig} = options; + const {runner} = options; const clId = `${options.id}-${client}`; const opts: ValidatorGeneratorOptions = { ...options, id: clId, keys: options.keys ?? {type: "no-keys"}, - genesisTime: options.genesisTime + forkConfig.GENESIS_DELAY, + genesisTime: options.genesisTime, clientOptions: options.clientOptions ?? {}, address: "127.0.0.1", }; diff --git a/packages/cli/test/utils/simulation/validator_clients/lighthouse.ts b/packages/cli/test/utils/simulation/validator_clients/lighthouse.ts index 27b2f485588d..a663fd0026c6 100644 --- a/packages/cli/test/utils/simulation/validator_clients/lighthouse.ts +++ b/packages/cli/test/utils/simulation/validator_clients/lighthouse.ts @@ -39,7 +39,6 @@ export const generateLighthouseValidatorNode: ValidatorNodeGenerator { + const pid = childProcess.pid; + + await new Promise((resolve, reject) => { childProcess.once("error", reject); - childProcess.once("close", resolve); + // We use `exit` instead of `close` as multiple processes can share same `stdio` + childProcess.once("exit", resolve); childProcess.kill(signal); }); + + if (pid != null && isPidRunning(pid)) { + // Wait for sometime and try to kill this time + await sleep(500); + await stopChildProcess(childProcess, "SIGKILL"); + } }; /** diff --git a/yarn.lock b/yarn.lock index 839c0dce5e90..0780e0bc2ef8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -385,6 +385,23 @@ uint8arraylist "^2.4.8" uint8arrays "^5.0.1" +"@chainsafe/libp2p-identify@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@chainsafe/libp2p-identify/-/libp2p-identify-1.0.0.tgz#28191e619715a87c140d8b516ee85cb7d39e41e0" + integrity sha512-X+VWUC0xeCFIulE4BU5M8FmTxZ/OKzku+9/1UaX2EG1LcqQkCDrPi6CCODbE0SraqImG4aVHRbiCFWxKEfE8wQ== + dependencies: + "@libp2p/interface" "^1.1.2" + "@libp2p/interface-internal" "^1.0.7" + "@libp2p/peer-id" "^4.0.5" + "@libp2p/peer-record" "^7.0.7" + "@multiformats/multiaddr" "^12.1.10" + "@multiformats/multiaddr-matcher" "^1.1.0" + it-protobuf-stream "^1.1.1" + protons-runtime "^5.0.0" + uint8arraylist "^2.4.7" + uint8arrays "^5.0.0" + wherearewe "^2.0.1" + "@chainsafe/libp2p-noise@^14.1.0": version "14.1.0" resolved "https://registry.yarnpkg.com/@chainsafe/libp2p-noise/-/libp2p-noise-14.1.0.tgz#4084a448cec73a941fddfc94751f6ce2e23c07cd" @@ -1629,6 +1646,21 @@ uint8arraylist "^2.4.3" uint8arrays "^5.0.0" +"@libp2p/peer-record@^7.0.7": + version "7.0.7" + resolved "https://registry.yarnpkg.com/@libp2p/peer-record/-/peer-record-7.0.7.tgz#e55145b2509592696f42ff73c38f813efbbbc688" + integrity sha512-RsggFJVAWQBA2z+ZJsK5nKHDKLmSd89IhFiE5GyImedQFiMkJz/gDFROzfNF2NdOyEBNdRy5SmC9scNFRQQD9A== + dependencies: + "@libp2p/crypto" "^4.0.1" + "@libp2p/interface" "^1.1.2" + "@libp2p/peer-id" "^4.0.5" + "@libp2p/utils" "^5.2.3" + "@multiformats/multiaddr" "^12.1.10" + protons-runtime "^5.0.0" + uint8-varint "^2.0.2" + uint8arraylist "^2.4.7" + uint8arrays "^5.0.0" + "@libp2p/peer-store@^10.0.5": version "10.0.5" resolved "https://registry.yarnpkg.com/@libp2p/peer-store/-/peer-store-10.0.5.tgz#b969d1707f5dcbf4d110e099270de285b075aa02" @@ -8054,6 +8086,16 @@ it-protobuf-stream@^1.0.2: protons-runtime "^5.0.0" uint8arraylist "^2.4.1" +it-protobuf-stream@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/it-protobuf-stream/-/it-protobuf-stream-1.1.2.tgz#4444d78fcae0fce949b4cbea622bf1d92667e64f" + integrity sha512-epZBuG+7cPaTxCR/Lf3ApshBdA9qfflGPQLfLLrp9VQ0w67Z2xo4H+SLLetav57/29oPtAXwVaoyemg99JOWzA== + dependencies: + it-length-prefixed-stream "^1.0.0" + it-stream-types "^2.0.1" + protons-runtime "^5.0.0" + uint8arraylist "^2.4.1" + it-pushable@^3.0.0, it-pushable@^3.1.2, it-pushable@^3.2.0, it-pushable@^3.2.1, it-pushable@^3.2.3: version "3.2.3" resolved "https://registry.yarnpkg.com/it-pushable/-/it-pushable-3.2.3.tgz#e2b80aed90cfbcd54b620c0a0785e546d4e5f334"