From ef0641dc762569fa8b3eb262955a67b42c613846 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 8 Apr 2024 05:50:44 +0200 Subject: [PATCH 1/6] test: rename all sim test files to camelCase (#6643) * Rename all files to camelCase * Rename files * Rename files * Fix file paths * Rename files --- packages/cli/package.json | 6 +++--- packages/cli/test/scripts/e2e_test_env.ts | 2 +- ...th_provider.test.ts => backupEthProvider.test.ts} | 2 +- packages/cli/test/sim/deneb.test.ts | 2 +- packages/cli/test/sim/endpoints.test.ts | 2 +- .../{mixed_client.test.ts => mixedClient.test.ts} | 2 +- .../sim/{multi_fork.test.ts => multiFork.test.ts} | 2 +- .../{beacon_clients => clients/beacon}/index.ts | 8 ++++---- .../{beacon_clients => clients/beacon}/lighthouse.ts | 6 +++--- .../{beacon_clients => clients/beacon}/lodestar.ts | 10 +++++----- .../{execution_clients => clients/execution}/geth.ts | 10 +++++----- .../execution}/index.ts | 10 +++++----- .../{execution_clients => clients/execution}/mock.ts | 6 +++--- .../execution}/nethermind.ts | 12 ++++++------ .../validator}/index.ts | 10 +++++----- .../validator}/lighthouse.ts | 8 ++++---- .../validator}/lodestar.ts | 10 +++++----- .../simulation/{EpochClock.ts => epochClock.ts} | 0 ...ProviderWithAdmin.ts => eth1ProviderWithAdmin.ts} | 0 ...ternalSignerServer.ts => externalSignerServer.ts} | 0 packages/cli/test/utils/simulation/interfaces.ts | 4 ++-- .../{ChildProcessRunner.ts => childProcessRunner.ts} | 0 .../runner/{DockerRunner.ts => dockerRunner.ts} | 0 packages/cli/test/utils/simulation/runner/index.ts | 4 ++-- ...lationEnvironment.ts => simulationEnvironment.ts} | 12 ++++++------ .../{SimulationTracker.ts => simulationTracker.ts} | 4 ++-- .../{TableRenderer.ts => tableRenderer.ts} | 0 .../{TableReporter.ts => tableReporter.ts} | 2 +- .../{execution_genesis.ts => executionGenesis.ts} | 0 packages/cli/test/utils/simulation/utils/index.ts | 2 +- packages/cli/test/utils/simulation/utils/network.ts | 4 ++-- packages/cli/test/utils/simulation/utils/syncing.ts | 2 +- 32 files changed, 71 insertions(+), 71 deletions(-) rename packages/cli/test/sim/{backup_eth_provider.test.ts => backupEthProvider.test.ts} (97%) rename packages/cli/test/sim/{mixed_client.test.ts => mixedClient.test.ts} (97%) rename packages/cli/test/sim/{multi_fork.test.ts => multiFork.test.ts} (98%) rename packages/cli/test/utils/simulation/{beacon_clients => clients/beacon}/index.ts (92%) rename packages/cli/test/utils/simulation/{beacon_clients => clients/beacon}/lighthouse.ts (96%) rename packages/cli/test/utils/simulation/{beacon_clients => clients/beacon}/lodestar.ts (92%) rename packages/cli/test/utils/simulation/{execution_clients => clients/execution}/geth.ts (95%) rename packages/cli/test/utils/simulation/{execution_clients => clients/execution}/index.ts (89%) rename packages/cli/test/utils/simulation/{execution_clients => clients/execution}/mock.ts (79%) rename packages/cli/test/utils/simulation/{execution_clients => clients/execution}/nethermind.ts (92%) rename packages/cli/test/utils/simulation/{validator_clients => clients/validator}/index.ts (91%) rename packages/cli/test/utils/simulation/{validator_clients => clients/validator}/lighthouse.ts (94%) rename packages/cli/test/utils/simulation/{validator_clients => clients/validator}/lodestar.ts (91%) rename packages/cli/test/utils/simulation/{EpochClock.ts => epochClock.ts} (100%) rename packages/cli/test/utils/simulation/{Eth1ProviderWithAdmin.ts => eth1ProviderWithAdmin.ts} (100%) rename packages/cli/test/utils/simulation/{ExternalSignerServer.ts => externalSignerServer.ts} (100%) rename packages/cli/test/utils/simulation/runner/{ChildProcessRunner.ts => childProcessRunner.ts} (100%) rename packages/cli/test/utils/simulation/runner/{DockerRunner.ts => dockerRunner.ts} (100%) rename packages/cli/test/utils/simulation/{SimulationEnvironment.ts => simulationEnvironment.ts} (97%) rename packages/cli/test/utils/simulation/{SimulationTracker.ts => simulationTracker.ts} (99%) rename packages/cli/test/utils/simulation/{TableRenderer.ts => tableRenderer.ts} (100%) rename packages/cli/test/utils/simulation/{TableReporter.ts => tableReporter.ts} (99%) rename packages/cli/test/utils/simulation/utils/{execution_genesis.ts => executionGenesis.ts} (100%) diff --git a/packages/cli/package.json b/packages/cli/package.json index cc76610cf60..f068c2c2944 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -32,11 +32,11 @@ "lint:fix": "yarn run lint --fix", "test:unit": "vitest --run --dir test/unit/", "test:e2e": "vitest --run --config vitest.e2e.config.ts --dir test/e2e/", - "test:sim:multifork": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/multi_fork.test.ts", - "test:sim:mixedclient": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/mixed_client.test.ts", + "test:sim:multifork": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/multiFork.test.ts", + "test:sim:mixedclient": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/mixedClient.test.ts", "test:sim:endpoints": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/endpoints.test.ts", "test:sim:deneb": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/deneb.test.ts", - "test:sim:backup_eth_provider": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/backup_eth_provider.test.ts", + "test:sim:backup_eth_provider": "LODESTAR_PRESET=minimal DOTENV_CONFIG_PATH=../../.env.test node -r dotenv/config --loader ts-node/esm test/sim/backupEthProvider.test.ts", "test": "yarn test:unit && yarn test:e2e", "check-readme": "typescript-docs-verifier" }, diff --git a/packages/cli/test/scripts/e2e_test_env.ts b/packages/cli/test/scripts/e2e_test_env.ts index 9884a5a8337..8e564c577f6 100644 --- a/packages/cli/test/scripts/e2e_test_env.ts +++ b/packages/cli/test/scripts/e2e_test_env.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import path from "node:path"; import {BeaconClient, ExecutionClient} from "../utils/simulation/interfaces.js"; -import {SimulationEnvironment} from "../utils/simulation/SimulationEnvironment.js"; +import {SimulationEnvironment} from "../utils/simulation/simulationEnvironment.js"; import {defineSimTestConfig, logFilesDir} from "../utils/simulation/utils/index.js"; import {connectAllNodes} from "../utils/simulation/utils/network.js"; diff --git a/packages/cli/test/sim/backup_eth_provider.test.ts b/packages/cli/test/sim/backupEthProvider.test.ts similarity index 97% rename from packages/cli/test/sim/backup_eth_provider.test.ts rename to packages/cli/test/sim/backupEthProvider.test.ts index aa93bb88471..b44de0afa54 100644 --- a/packages/cli/test/sim/backup_eth_provider.test.ts +++ b/packages/cli/test/sim/backupEthProvider.test.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import path from "node:path"; import {activePreset} from "@lodestar/params"; -import {SimulationEnvironment} from "../utils/simulation/SimulationEnvironment.js"; +import {SimulationEnvironment} from "../utils/simulation/simulationEnvironment.js"; import {nodeAssertion} from "../utils/simulation/assertions/nodeAssertion.js"; import {AssertionMatch, BeaconClient, ExecutionClient} from "../utils/simulation/interfaces.js"; import {defineSimTestConfig, logFilesDir, replaceIpFromUrl} from "../utils/simulation/utils/index.js"; diff --git a/packages/cli/test/sim/deneb.test.ts b/packages/cli/test/sim/deneb.test.ts index e9e14236df0..feac8cedc20 100644 --- a/packages/cli/test/sim/deneb.test.ts +++ b/packages/cli/test/sim/deneb.test.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import path from "node:path"; import {activePreset} from "@lodestar/params"; -import {SimulationEnvironment} from "../utils/simulation/SimulationEnvironment.js"; +import {SimulationEnvironment} from "../utils/simulation/simulationEnvironment.js"; import {nodeAssertion} from "../utils/simulation/assertions/nodeAssertion.js"; import {AssertionMatch, BeaconClient, ExecutionClient} from "../utils/simulation/interfaces.js"; import {defineSimTestConfig, logFilesDir} from "../utils/simulation/utils/index.js"; diff --git a/packages/cli/test/sim/endpoints.test.ts b/packages/cli/test/sim/endpoints.test.ts index 0455de12306..9b20ac887fe 100644 --- a/packages/cli/test/sim/endpoints.test.ts +++ b/packages/cli/test/sim/endpoints.test.ts @@ -3,7 +3,7 @@ import path from "node:path"; import assert from "node:assert"; import {toHexString} from "@chainsafe/ssz"; import {ApiError, routes} from "@lodestar/api"; -import {SimulationEnvironment} from "../utils/simulation/SimulationEnvironment.js"; +import {SimulationEnvironment} from "../utils/simulation/simulationEnvironment.js"; import {BeaconClient, ExecutionClient} from "../utils/simulation/interfaces.js"; import {defineSimTestConfig, logFilesDir} from "../utils/simulation/utils/index.js"; import {waitForSlot} from "../utils/simulation/utils/network.js"; diff --git a/packages/cli/test/sim/mixed_client.test.ts b/packages/cli/test/sim/mixedClient.test.ts similarity index 97% rename from packages/cli/test/sim/mixed_client.test.ts rename to packages/cli/test/sim/mixedClient.test.ts index b284ba45726..85a7ad0eeea 100644 --- a/packages/cli/test/sim/mixed_client.test.ts +++ b/packages/cli/test/sim/mixedClient.test.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import path from "node:path"; -import {SimulationEnvironment} from "../utils/simulation/SimulationEnvironment.js"; +import {SimulationEnvironment} from "../utils/simulation/simulationEnvironment.js"; import {nodeAssertion} from "../utils/simulation/assertions/nodeAssertion.js"; import {AssertionMatch, BeaconClient, ExecutionClient, ValidatorClient} from "../utils/simulation/interfaces.js"; import {defineSimTestConfig, logFilesDir} from "../utils/simulation/utils/index.js"; diff --git a/packages/cli/test/sim/multi_fork.test.ts b/packages/cli/test/sim/multiFork.test.ts similarity index 98% rename from packages/cli/test/sim/multi_fork.test.ts rename to packages/cli/test/sim/multiFork.test.ts index 2bce220e58d..371201a4045 100644 --- a/packages/cli/test/sim/multi_fork.test.ts +++ b/packages/cli/test/sim/multiFork.test.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import path from "node:path"; import {AssertionMatch, BeaconClient, ExecutionClient, ValidatorClient} from "../utils/simulation/interfaces.js"; -import {SimulationEnvironment} from "../utils/simulation/SimulationEnvironment.js"; +import {SimulationEnvironment} from "../utils/simulation/simulationEnvironment.js"; import {defineSimTestConfig, logFilesDir} from "../utils/simulation/utils/index.js"; import {connectAllNodes, waitForSlot} from "../utils/simulation/utils/network.js"; import {nodeAssertion} from "../utils/simulation/assertions/nodeAssertion.js"; diff --git a/packages/cli/test/utils/simulation/beacon_clients/index.ts b/packages/cli/test/utils/simulation/clients/beacon/index.ts similarity index 92% rename from packages/cli/test/utils/simulation/beacon_clients/index.ts rename to packages/cli/test/utils/simulation/clients/beacon/index.ts index 094ca1e9c58..edd24e3f106 100644 --- a/packages/cli/test/utils/simulation/beacon_clients/index.ts +++ b/packages/cli/test/utils/simulation/clients/beacon/index.ts @@ -1,9 +1,9 @@ import {writeFile} from "node:fs/promises"; import {BeaconStateAllForks} from "@lodestar/state-transition"; -import {EL_ENGINE_BASE_PORT, SHARED_JWT_SECRET} from "../constants.js"; -import {AtLeast, BeaconClient, BeaconGeneratorOptions, BeaconNode} from "../interfaces.js"; -import {makeUniqueArray} from "../utils/index.js"; -import {ensureDirectories} from "../utils/paths.js"; +import {EL_ENGINE_BASE_PORT, SHARED_JWT_SECRET} from "../../constants.js"; +import {AtLeast, BeaconClient, BeaconGeneratorOptions, BeaconNode} from "../../interfaces.js"; +import {makeUniqueArray} from "../../utils/index.js"; +import {ensureDirectories} from "../../utils/paths.js"; import {generateLighthouseBeaconNode} from "./lighthouse.js"; import {generateLodestarBeaconNode} from "./lodestar.js"; diff --git a/packages/cli/test/utils/simulation/beacon_clients/lighthouse.ts b/packages/cli/test/utils/simulation/clients/beacon/lighthouse.ts similarity index 96% rename from packages/cli/test/utils/simulation/beacon_clients/lighthouse.ts rename to packages/cli/test/utils/simulation/clients/beacon/lighthouse.ts index 4b994c63a83..3e737416ddc 100644 --- a/packages/cli/test/utils/simulation/beacon_clients/lighthouse.ts +++ b/packages/cli/test/utils/simulation/clients/beacon/lighthouse.ts @@ -5,9 +5,9 @@ import yaml from "js-yaml"; import {HttpClient} from "@lodestar/api"; import {getClient} from "@lodestar/api/beacon"; import {chainConfigToJson} from "@lodestar/config"; -import {BeaconClient, BeaconNodeGenerator, LighthouseAPI, RunnerType} from "../interfaces.js"; -import {getNodeMountedPaths} from "../utils/paths.js"; -import {getNodePorts} from "../utils/ports.js"; +import {BeaconClient, BeaconNodeGenerator, LighthouseAPI, RunnerType} from "../../interfaces.js"; +import {getNodeMountedPaths} from "../../utils/paths.js"; +import {getNodePorts} from "../../utils/ports.js"; export const generateLighthouseBeaconNode: BeaconNodeGenerator = (opts, runner) => { if (!process.env.LIGHTHOUSE_BINARY_PATH && !process.env.LIGHTHOUSE_DOCKER_IMAGE) { diff --git a/packages/cli/test/utils/simulation/beacon_clients/lodestar.ts b/packages/cli/test/utils/simulation/clients/beacon/lodestar.ts similarity index 92% rename from packages/cli/test/utils/simulation/beacon_clients/lodestar.ts rename to packages/cli/test/utils/simulation/clients/beacon/lodestar.ts index 3faa0bdb0ac..0c881b5b340 100644 --- a/packages/cli/test/utils/simulation/beacon_clients/lodestar.ts +++ b/packages/cli/test/utils/simulation/clients/beacon/lodestar.ts @@ -5,11 +5,11 @@ import got from "got"; import {getClient} from "@lodestar/api/beacon"; import {chainConfigToJson} from "@lodestar/config"; import {LogLevel} from "@lodestar/utils"; -import {BeaconArgs} from "../../../../src/cmds/beacon/options.js"; -import {GlobalArgs} from "../../../../src/options/globalOptions.js"; -import {LODESTAR_BINARY_PATH} from "../constants.js"; -import {BeaconClient, BeaconNodeGenerator, RunnerType} from "../interfaces.js"; -import {getNodePorts} from "../utils/ports.js"; +import {BeaconArgs} from "../../../../../src/cmds/beacon/options.js"; +import {GlobalArgs} from "../../../../../src/options/globalOptions.js"; +import {LODESTAR_BINARY_PATH} from "../../constants.js"; +import {BeaconClient, BeaconNodeGenerator, RunnerType} from "../../interfaces.js"; +import {getNodePorts} from "../../utils/ports.js"; export const generateLodestarBeaconNode: BeaconNodeGenerator = (opts, runner) => { const { diff --git a/packages/cli/test/utils/simulation/execution_clients/geth.ts b/packages/cli/test/utils/simulation/clients/execution/geth.ts similarity index 95% rename from packages/cli/test/utils/simulation/execution_clients/geth.ts rename to packages/cli/test/utils/simulation/clients/execution/geth.ts index 18e73ddba19..91ed754c285 100644 --- a/packages/cli/test/utils/simulation/execution_clients/geth.ts +++ b/packages/cli/test/utils/simulation/clients/execution/geth.ts @@ -9,11 +9,11 @@ import { EL_GENESIS_SECRET_KEY, SHARED_JWT_SECRET, SIM_ENV_NETWORK_ID, -} from "../constants.js"; -import {Eth1ProviderWithAdmin} from "../Eth1ProviderWithAdmin.js"; -import {ExecutionClient, ExecutionNodeGenerator, ExecutionStartMode, JobOptions, RunnerType} from "../interfaces.js"; -import {getNodeMountedPaths} from "../utils/paths.js"; -import {getNodePorts} from "../utils/ports.js"; +} from "../../constants.js"; +import {Eth1ProviderWithAdmin} from "../../eth1ProviderWithAdmin.js"; +import {ExecutionClient, ExecutionNodeGenerator, ExecutionStartMode, JobOptions, RunnerType} from "../../interfaces.js"; +import {getNodeMountedPaths} from "../../utils/paths.js"; +import {getNodePorts} from "../../utils/ports.js"; export const generateGethNode: ExecutionNodeGenerator = (opts, runner) => { if (!process.env.GETH_BINARY_DIR && !process.env.GETH_DOCKER_IMAGE) { diff --git a/packages/cli/test/utils/simulation/execution_clients/index.ts b/packages/cli/test/utils/simulation/clients/execution/index.ts similarity index 89% rename from packages/cli/test/utils/simulation/execution_clients/index.ts rename to packages/cli/test/utils/simulation/clients/execution/index.ts index 0bc28ca32db..db6510a7a7d 100644 --- a/packages/cli/test/utils/simulation/execution_clients/index.ts +++ b/packages/cli/test/utils/simulation/clients/execution/index.ts @@ -1,5 +1,5 @@ import {writeFile} from "node:fs/promises"; -import {SHARED_JWT_SECRET, CLIQUE_SEALING_PERIOD} from "../constants.js"; +import {SHARED_JWT_SECRET, CLIQUE_SEALING_PERIOD} from "../../constants.js"; import { AtLeast, ExecutionClient, @@ -7,10 +7,10 @@ import { ExecutionGenesisOptions, ExecutionNode, ExecutionStartMode, -} from "../interfaces.js"; -import {getEstimatedForkTime} from "../utils/index.js"; -import {getGethGenesisBlock} from "../utils/execution_genesis.js"; -import {ensureDirectories} from "../utils/paths.js"; +} from "../../interfaces.js"; +import {getEstimatedForkTime} from "../../utils/index.js"; +import {getGethGenesisBlock} from "../../utils/executionGenesis.js"; +import {ensureDirectories} from "../../utils/paths.js"; import {generateGethNode} from "./geth.js"; import {generateMockNode} from "./mock.js"; import {generateNethermindNode} from "./nethermind.js"; diff --git a/packages/cli/test/utils/simulation/execution_clients/mock.ts b/packages/cli/test/utils/simulation/clients/execution/mock.ts similarity index 79% rename from packages/cli/test/utils/simulation/execution_clients/mock.ts rename to packages/cli/test/utils/simulation/clients/execution/mock.ts index f10897f16d2..fd6512a1663 100644 --- a/packages/cli/test/utils/simulation/execution_clients/mock.ts +++ b/packages/cli/test/utils/simulation/clients/execution/mock.ts @@ -1,6 +1,6 @@ -import {SHARED_JWT_SECRET} from "../constants.js"; -import {ExecutionClient, ExecutionNodeGenerator} from "../interfaces.js"; -import {getNodePorts} from "../utils/ports.js"; +import {SHARED_JWT_SECRET} from "../../constants.js"; +import {ExecutionClient, ExecutionNodeGenerator} from "../../interfaces.js"; +import {getNodePorts} from "../../utils/ports.js"; export const generateMockNode: ExecutionNodeGenerator = (opts, runner) => { const {id, ttd, nodeIndex} = opts; diff --git a/packages/cli/test/utils/simulation/execution_clients/nethermind.ts b/packages/cli/test/utils/simulation/clients/execution/nethermind.ts similarity index 92% rename from packages/cli/test/utils/simulation/execution_clients/nethermind.ts rename to packages/cli/test/utils/simulation/clients/execution/nethermind.ts index 08acfb2fad2..4f864783d8b 100644 --- a/packages/cli/test/utils/simulation/execution_clients/nethermind.ts +++ b/packages/cli/test/utils/simulation/clients/execution/nethermind.ts @@ -3,12 +3,12 @@ import {writeFile} from "node:fs/promises"; import path from "node:path"; import got from "got"; import {ZERO_HASH} from "@lodestar/state-transition"; -import {Eth1ProviderWithAdmin} from "../Eth1ProviderWithAdmin.js"; -import {ExecutionClient, ExecutionNodeGenerator, JobOptions, RunnerType} from "../interfaces.js"; -import {getNethermindChainSpec} from "../utils/execution_genesis.js"; -import {getNodeMountedPaths} from "../utils/paths.js"; -import {SHARED_JWT_SECRET} from "../constants.js"; -import {getNodePorts} from "../utils/ports.js"; +import {Eth1ProviderWithAdmin} from "../../eth1ProviderWithAdmin.js"; +import {ExecutionClient, ExecutionNodeGenerator, JobOptions, RunnerType} from "../../interfaces.js"; +import {getNethermindChainSpec} from "../../utils/executionGenesis.js"; +import {getNodeMountedPaths} from "../../utils/paths.js"; +import {SHARED_JWT_SECRET} from "../../constants.js"; +import {getNodePorts} from "../../utils/ports.js"; export const generateNethermindNode: ExecutionNodeGenerator = (opts, runner) => { if (!process.env.NETHERMIND_DOCKER_IMAGE) { diff --git a/packages/cli/test/utils/simulation/validator_clients/index.ts b/packages/cli/test/utils/simulation/clients/validator/index.ts similarity index 91% rename from packages/cli/test/utils/simulation/validator_clients/index.ts rename to packages/cli/test/utils/simulation/clients/validator/index.ts index a75cbf6b166..677deca23ff 100644 --- a/packages/cli/test/utils/simulation/validator_clients/index.ts +++ b/packages/cli/test/utils/simulation/clients/validator/index.ts @@ -1,9 +1,9 @@ import {writeFile} from "node:fs/promises"; -import {SHARED_JWT_SECRET, SHARED_VALIDATOR_PASSWORD, BN_REST_BASE_PORT} from "../constants.js"; -import {AtLeast, BeaconClient, ValidatorClient, ValidatorGeneratorOptions, ValidatorNode} from "../interfaces.js"; -import {makeUniqueArray} from "../utils/index.js"; -import {createKeystores} from "../utils/keys.js"; -import {ensureDirectories} from "../utils/paths.js"; +import {SHARED_JWT_SECRET, SHARED_VALIDATOR_PASSWORD, BN_REST_BASE_PORT} from "../../constants.js"; +import {AtLeast, BeaconClient, ValidatorClient, ValidatorGeneratorOptions, ValidatorNode} from "../../interfaces.js"; +import {makeUniqueArray} from "../../utils/index.js"; +import {createKeystores} from "../../utils/keys.js"; +import {ensureDirectories} from "../../utils/paths.js"; import {generateLodestarValidatorNode} from "./lodestar.js"; import {generateLighthouseValidatorNode} from "./lighthouse.js"; diff --git a/packages/cli/test/utils/simulation/validator_clients/lighthouse.ts b/packages/cli/test/utils/simulation/clients/validator/lighthouse.ts similarity index 94% rename from packages/cli/test/utils/simulation/validator_clients/lighthouse.ts rename to packages/cli/test/utils/simulation/clients/validator/lighthouse.ts index 8df15a3ec85..b9c70c495ce 100644 --- a/packages/cli/test/utils/simulation/validator_clients/lighthouse.ts +++ b/packages/cli/test/utils/simulation/clients/validator/lighthouse.ts @@ -4,10 +4,10 @@ import got, {RequestError} from "got"; import yaml from "js-yaml"; import {getClient as keyManagerGetClient} from "@lodestar/api/keymanager"; import {chainConfigToJson} from "@lodestar/config"; -import {RunnerType, ValidatorClient, ValidatorNodeGenerator} from "../interfaces.js"; -import {updateKeystoresPath} from "../utils/keys.js"; -import {getNodeMountedPaths} from "../utils/paths.js"; -import {getNodePorts} from "../utils/ports.js"; +import {RunnerType, ValidatorClient, ValidatorNodeGenerator} from "../../interfaces.js"; +import {updateKeystoresPath} from "../../utils/keys.js"; +import {getNodeMountedPaths} from "../../utils/paths.js"; +import {getNodePorts} from "../../utils/ports.js"; export const generateLighthouseValidatorNode: ValidatorNodeGenerator = (opts, runner) => { if (!process.env.LIGHTHOUSE_BINARY_PATH && !process.env.LIGHTHOUSE_DOCKER_IMAGE) { diff --git a/packages/cli/test/utils/simulation/validator_clients/lodestar.ts b/packages/cli/test/utils/simulation/clients/validator/lodestar.ts similarity index 91% rename from packages/cli/test/utils/simulation/validator_clients/lodestar.ts rename to packages/cli/test/utils/simulation/clients/validator/lodestar.ts index 03843796a6b..df91c92e2b7 100644 --- a/packages/cli/test/utils/simulation/validator_clients/lodestar.ts +++ b/packages/cli/test/utils/simulation/clients/validator/lodestar.ts @@ -6,11 +6,11 @@ import {getClient as keyManagerGetClient} from "@lodestar/api/keymanager"; import {chainConfigToJson} from "@lodestar/config"; import {LogLevel} from "@lodestar/utils"; import {defaultOptions} from "@lodestar/validator"; -import {IValidatorCliArgs} from "../../../../src/cmds/validator/options.js"; -import {GlobalArgs} from "../../../../src/options/globalOptions.js"; -import {LODESTAR_BINARY_PATH} from "../constants.js"; -import {RunnerType, ValidatorClient, ValidatorNodeGenerator} from "../interfaces.js"; -import {getNodePorts} from "../utils/ports.js"; +import {IValidatorCliArgs} from "../../../../../src/cmds/validator/options.js"; +import {GlobalArgs} from "../../../../../src/options/globalOptions.js"; +import {LODESTAR_BINARY_PATH} from "../../constants.js"; +import {RunnerType, ValidatorClient, ValidatorNodeGenerator} from "../../interfaces.js"; +import {getNodePorts} from "../../utils/ports.js"; export const generateLodestarValidatorNode: ValidatorNodeGenerator = (opts, runner) => { const {paths, id, keys, forkConfig, genesisTime, nodeIndex, beaconUrls, clientOptions} = opts; diff --git a/packages/cli/test/utils/simulation/EpochClock.ts b/packages/cli/test/utils/simulation/epochClock.ts similarity index 100% rename from packages/cli/test/utils/simulation/EpochClock.ts rename to packages/cli/test/utils/simulation/epochClock.ts diff --git a/packages/cli/test/utils/simulation/Eth1ProviderWithAdmin.ts b/packages/cli/test/utils/simulation/eth1ProviderWithAdmin.ts similarity index 100% rename from packages/cli/test/utils/simulation/Eth1ProviderWithAdmin.ts rename to packages/cli/test/utils/simulation/eth1ProviderWithAdmin.ts diff --git a/packages/cli/test/utils/simulation/ExternalSignerServer.ts b/packages/cli/test/utils/simulation/externalSignerServer.ts similarity index 100% rename from packages/cli/test/utils/simulation/ExternalSignerServer.ts rename to packages/cli/test/utils/simulation/externalSignerServer.ts diff --git a/packages/cli/test/utils/simulation/interfaces.ts b/packages/cli/test/utils/simulation/interfaces.ts index dc2b09a6ed9..1e228b26371 100644 --- a/packages/cli/test/utils/simulation/interfaces.ts +++ b/packages/cli/test/utils/simulation/interfaces.ts @@ -10,8 +10,8 @@ import {Logger} from "@lodestar/logger"; import {BeaconArgs} from "../../../src/cmds/beacon/options.js"; import {IValidatorCliArgs} from "../../../src/cmds/validator/options.js"; import {GlobalArgs} from "../../../src/options/index.js"; -import {EpochClock} from "./EpochClock.js"; -import {Eth1ProviderWithAdmin} from "./Eth1ProviderWithAdmin.js"; +import {EpochClock} from "./epochClock.js"; +import {Eth1ProviderWithAdmin} from "./eth1ProviderWithAdmin.js"; export type NodeId = string; diff --git a/packages/cli/test/utils/simulation/runner/ChildProcessRunner.ts b/packages/cli/test/utils/simulation/runner/childProcessRunner.ts similarity index 100% rename from packages/cli/test/utils/simulation/runner/ChildProcessRunner.ts rename to packages/cli/test/utils/simulation/runner/childProcessRunner.ts diff --git a/packages/cli/test/utils/simulation/runner/DockerRunner.ts b/packages/cli/test/utils/simulation/runner/dockerRunner.ts similarity index 100% rename from packages/cli/test/utils/simulation/runner/DockerRunner.ts rename to packages/cli/test/utils/simulation/runner/dockerRunner.ts diff --git a/packages/cli/test/utils/simulation/runner/index.ts b/packages/cli/test/utils/simulation/runner/index.ts index cedd5c34e6a..7bc7a2872f3 100644 --- a/packages/cli/test/utils/simulation/runner/index.ts +++ b/packages/cli/test/utils/simulation/runner/index.ts @@ -2,8 +2,8 @@ import {EventEmitter} from "node:events"; import path from "node:path"; import {Logger} from "@lodestar/logger"; import {IRunner, Job, JobOptions, RunnerEvent, RunnerType} from "../interfaces.js"; -import {ChildProcessRunner} from "./ChildProcessRunner.js"; -import {DockerRunner} from "./DockerRunner.js"; +import {ChildProcessRunner} from "./childProcessRunner.js"; +import {DockerRunner} from "./dockerRunner.js"; export class Runner implements IRunner { readonly logger: Logger; diff --git a/packages/cli/test/utils/simulation/SimulationEnvironment.ts b/packages/cli/test/utils/simulation/simulationEnvironment.ts similarity index 97% rename from packages/cli/test/utils/simulation/SimulationEnvironment.ts rename to packages/cli/test/utils/simulation/simulationEnvironment.ts index 88ae03cc868..24e3ced7da1 100644 --- a/packages/cli/test/utils/simulation/SimulationEnvironment.ts +++ b/packages/cli/test/utils/simulation/simulationEnvironment.ts @@ -10,13 +10,13 @@ import {BeaconStateAllForks, interopSecretKey} from "@lodestar/state-transition" import {prettyMsToTime} from "@lodestar/utils"; import {LogLevel, TimestampFormatCode} from "@lodestar/logger"; import {getNodeLogger, LoggerNode} from "@lodestar/logger/node"; -import {EpochClock, MS_IN_SEC} from "./EpochClock.js"; -import {ExternalSignerServer} from "./ExternalSignerServer.js"; -import {SimulationTracker} from "./SimulationTracker.js"; -import {createBeaconNode} from "./beacon_clients/index.js"; -import {createValidatorNode, getValidatorForBeaconNode} from "./validator_clients/index.js"; +import {EpochClock, MS_IN_SEC} from "./epochClock.js"; +import {ExternalSignerServer} from "./externalSignerServer.js"; +import {SimulationTracker} from "./simulationTracker.js"; +import {createBeaconNode} from "./clients/beacon/index.js"; +import {createValidatorNode, getValidatorForBeaconNode} from "./clients/validator/index.js"; import {MOCK_ETH1_GENESIS_HASH} from "./constants.js"; -import {createExecutionNode} from "./execution_clients/index.js"; +import {createExecutionNode} from "./clients/execution/index.js"; import { BeaconClient, ValidatorClientKeys, diff --git a/packages/cli/test/utils/simulation/SimulationTracker.ts b/packages/cli/test/utils/simulation/simulationTracker.ts similarity index 99% rename from packages/cli/test/utils/simulation/SimulationTracker.ts rename to packages/cli/test/utils/simulation/simulationTracker.ts index 3c2365ef997..909f92ede8e 100644 --- a/packages/cli/test/utils/simulation/SimulationTracker.ts +++ b/packages/cli/test/utils/simulation/simulationTracker.ts @@ -7,7 +7,7 @@ import {ChainForkConfig} from "@lodestar/config"; import {Epoch, Slot} from "@lodestar/types"; import {LoggerNode} from "@lodestar/logger/node"; import {isNullish} from "../../utils.js"; -import {EpochClock} from "./EpochClock.js"; +import {EpochClock} from "./epochClock.js"; import { AssertionMatch, AtLeast, @@ -20,7 +20,7 @@ import { StoreTypes, } from "./interfaces.js"; import {defaultAssertions} from "./assertions/defaults/index.js"; -import {TableReporter} from "./TableReporter.js"; +import {TableReporter} from "./tableReporter.js"; import {fetchBlock} from "./utils/network.js"; const debug = createDebug("lodestar:sim:tracker"); diff --git a/packages/cli/test/utils/simulation/TableRenderer.ts b/packages/cli/test/utils/simulation/tableRenderer.ts similarity index 100% rename from packages/cli/test/utils/simulation/TableRenderer.ts rename to packages/cli/test/utils/simulation/tableRenderer.ts diff --git a/packages/cli/test/utils/simulation/TableReporter.ts b/packages/cli/test/utils/simulation/tableReporter.ts similarity index 99% rename from packages/cli/test/utils/simulation/TableReporter.ts rename to packages/cli/test/utils/simulation/tableReporter.ts index 3ca7569a7a4..d11fc9ca3fb 100644 --- a/packages/cli/test/utils/simulation/TableReporter.ts +++ b/packages/cli/test/utils/simulation/tableReporter.ts @@ -3,7 +3,7 @@ import {isNullish} from "../../utils.js"; import {HeadSummary} from "./assertions/defaults/headAssertion.js"; import {defaultAssertions} from "./assertions/defaults/index.js"; import {SimulationReporter} from "./interfaces.js"; -import {TableRenderer} from "./TableRenderer.js"; +import {TableRenderer} from "./tableRenderer.js"; import {arrayGroupBy, avg, isSingletonArray} from "./utils/index.js"; export class TableReporter extends SimulationReporter { diff --git a/packages/cli/test/utils/simulation/utils/execution_genesis.ts b/packages/cli/test/utils/simulation/utils/executionGenesis.ts similarity index 100% rename from packages/cli/test/utils/simulation/utils/execution_genesis.ts rename to packages/cli/test/utils/simulation/utils/executionGenesis.ts diff --git a/packages/cli/test/utils/simulation/utils/index.ts b/packages/cli/test/utils/simulation/utils/index.ts index 82bdef27b26..20fc6d6fbd0 100644 --- a/packages/cli/test/utils/simulation/utils/index.ts +++ b/packages/cli/test/utils/simulation/utils/index.ts @@ -9,7 +9,7 @@ import { SIM_ENV_NETWORK_ID, SIM_TESTS_SECONDS_PER_SLOT, } from "../constants.js"; -import {SimulationEnvironment} from "../SimulationEnvironment.js"; +import {SimulationEnvironment} from "../simulationEnvironment.js"; export const logFilesDir = "test-logs"; diff --git a/packages/cli/test/utils/simulation/utils/network.ts b/packages/cli/test/utils/simulation/utils/network.ts index 999020b806c..cbdd1add7b8 100644 --- a/packages/cli/test/utils/simulation/utils/network.ts +++ b/packages/cli/test/utils/simulation/utils/network.ts @@ -3,8 +3,8 @@ import {ApiError} from "@lodestar/api"; import {Slot, allForks} from "@lodestar/types"; import {sleep} from "@lodestar/utils"; import {BeaconClient, BeaconNode, ExecutionClient, ExecutionNode, NodePair} from "../interfaces.js"; -import {SimulationEnvironment} from "../SimulationEnvironment.js"; -import {SimulationTrackerEvent} from "../SimulationTracker.js"; +import {SimulationEnvironment} from "../simulationEnvironment.js"; +import {SimulationTrackerEvent} from "../simulationTracker.js"; export async function connectAllNodes(nodes: NodePair[]): Promise { for (const node of nodes) { diff --git a/packages/cli/test/utils/simulation/utils/syncing.ts b/packages/cli/test/utils/simulation/utils/syncing.ts index bc6fd128b7f..fdfe3785e62 100644 --- a/packages/cli/test/utils/simulation/utils/syncing.ts +++ b/packages/cli/test/utils/simulation/utils/syncing.ts @@ -1,7 +1,7 @@ import {ApiError, routes} from "@lodestar/api"; import {Slot} from "@lodestar/types"; import {sleep, toHex} from "@lodestar/utils"; -import type {SimulationEnvironment} from "../SimulationEnvironment.js"; +import type {SimulationEnvironment} from "../simulationEnvironment.js"; import {BeaconClient, ExecutionClient, NodePair} from "../interfaces.js"; import {connectNewCLNode, connectNewELNode, connectNewNode, waitForHead, waitForSlot} from "./network.js"; From d79bc4953289a0ea64074a45aaf5d74d9c0c866a Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 8 Apr 2024 05:00:52 +0100 Subject: [PATCH 2/6] chore: fix heap allocations panel in VM + host dashboard (#6647) --- dashboards/lodestar_vm_host.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboards/lodestar_vm_host.json b/dashboards/lodestar_vm_host.json index 7471defd0e8..3f6c18bc19c 100644 --- a/dashboards/lodestar_vm_host.json +++ b/dashboards/lodestar_vm_host.json @@ -291,7 +291,7 @@ "uid": "${DS_PROMETHEUS}" }, "editorMode": "code", - "expr": "sum by (space) ({__name__=~\"nodejs_heap_space_size_used_bytes|network_worker_nodejs_heap_space_size_used_bytes|discv5_worker_nodejs_heap_space_size_used_bytes\")", + "expr": "sum by (space) ({__name__=~\"nodejs_heap_space_size_used_bytes|network_worker_nodejs_heap_space_size_used_bytes|discv5_worker_nodejs_heap_space_size_used_bytes\"})", "hide": false, "interval": "", "legendFormat": "{{space}}", From 65927c699c87c0a4e8320e1cbfe55247bd1c2468 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 8 Apr 2024 05:05:57 +0100 Subject: [PATCH 3/6] fix: return 404 error if no aggregated attestation is available (#6648) --- packages/beacon-node/src/api/impl/validator/index.ts | 8 +++++++- .../beacon-node/src/chain/opPools/attestationPool.ts | 9 ++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 658c86b905f..3b21b4434f1 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -1067,7 +1067,13 @@ export function getValidatorApi({ await waitForSlot(slot); // Must never request for a future slot > currentSlot - const aggregate = chain.attestationPool.getAggregate(slot, attestationDataRoot); + const dataRootHex = toHexString(attestationDataRoot); + const aggregate = chain.attestationPool.getAggregate(slot, dataRootHex); + + if (!aggregate) { + throw new ApiError(404, `No aggregated attestation for slot=${slot}, dataRoot=${dataRootHex}`); + } + metrics?.production.producedAggregateParticipants.observe(aggregate.aggregationBits.getTrueBitIndexes().length); return { diff --git a/packages/beacon-node/src/chain/opPools/attestationPool.ts b/packages/beacon-node/src/chain/opPools/attestationPool.ts index a04cd759209..804d8798cbc 100644 --- a/packages/beacon-node/src/chain/opPools/attestationPool.ts +++ b/packages/beacon-node/src/chain/opPools/attestationPool.ts @@ -1,7 +1,7 @@ import {PointFormat, Signature} from "@chainsafe/bls/types"; import bls from "@chainsafe/bls"; -import {BitArray, toHexString} from "@chainsafe/ssz"; -import {phase0, Slot, Root, RootHex} from "@lodestar/types"; +import {BitArray} from "@chainsafe/ssz"; +import {phase0, Slot, RootHex} from "@lodestar/types"; import {MapDef} from "@lodestar/utils"; import {IClock} from "../../util/clock.js"; import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js"; @@ -128,12 +128,11 @@ export class AttestationPool { /** * For validator API to get an aggregate */ - getAggregate(slot: Slot, dataRoot: Root): phase0.Attestation { - const dataRootHex = toHexString(dataRoot); + getAggregate(slot: Slot, dataRootHex: RootHex): phase0.Attestation | null { const aggregate = this.attestationByRootBySlot.get(slot)?.get(dataRootHex); if (!aggregate) { // TODO: Add metric for missing aggregates - throw Error(`No attestation for slot=${slot} dataRoot=${dataRootHex}`); + return null; } return fastToAttestation(aggregate); From b1f4e7e674a704a7442640d613920d2cce6c2325 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 8 Apr 2024 09:56:33 +0200 Subject: [PATCH 4/6] test: add support for web3.js to simulation tests (#6641) * Add support for web3.js to simulation tests * Fix lint error * Apply suggestions from code review Co-authored-by: Matthew Keil * Update the namespace * Fix the lint errors * Update the web3js plugin name --------- Co-authored-by: Matthew Keil --- .../assertions/accountBalanceAssertion.ts | 30 +++-------- .../assertions/executionHeadAssertion.ts | 4 +- .../simulation/clients/execution/geth.ts | 12 ++--- .../clients/execution/nethermind.ts | 12 ++--- .../utils/simulation/eth1ProviderWithAdmin.ts | 53 ------------------- .../cli/test/utils/simulation/interfaces.ts | 4 +- .../utils/simulation/simulationEnvironment.ts | 4 +- .../test/utils/simulation/utils/network.ts | 3 +- .../test/utils/simulation/web3JsPlugins.ts | 47 ++++++++++++++++ 9 files changed, 70 insertions(+), 99 deletions(-) delete mode 100644 packages/cli/test/utils/simulation/eth1ProviderWithAdmin.ts create mode 100644 packages/cli/test/utils/simulation/web3JsPlugins.ts diff --git a/packages/cli/test/utils/simulation/assertions/accountBalanceAssertion.ts b/packages/cli/test/utils/simulation/assertions/accountBalanceAssertion.ts index 2367763b0a2..1866d52a847 100644 --- a/packages/cli/test/utils/simulation/assertions/accountBalanceAssertion.ts +++ b/packages/cli/test/utils/simulation/assertions/accountBalanceAssertion.ts @@ -1,14 +1,6 @@ import {EL_GENESIS_ACCOUNT} from "../constants.js"; import {AssertionMatch, AssertionResult, NodePair, SimulationAssertion} from "../interfaces.js"; -function hexToBigInt(num: string): bigint { - return num.startsWith("0x") ? BigInt(num) : BigInt(`0x${num}`); -} - -function bigIntToHex(num: bigint): string { - return `0x${num.toString(16)}`; -} - const transactionAmount = BigInt(2441406250); export function createAccountBalanceAssertion({ @@ -30,17 +22,12 @@ export function createAccountBalanceAssertion({ return AssertionMatch.None; }, async capture({node}) { - await node.execution.provider?.getRpc().fetch({ - method: "eth_sendTransaction", - params: [ - { - to: address, - from: EL_GENESIS_ACCOUNT, - gas: "0x76c0", - gasPrice: "0x9184e72a000", - value: bigIntToHex(transactionAmount), - }, - ], + await node.execution.provider?.eth.sendTransaction({ + to: address, + from: EL_GENESIS_ACCOUNT, + gas: "0x76c0", + gasPrice: "0x9184e72a000", + value: transactionAmount, }); // Capture the value transferred to account @@ -57,10 +44,7 @@ export function createAccountBalanceAssertion({ expectedBalanceAtCurrentSlot += BigInt(store[captureSlot]); } - const balance = hexToBigInt( - (await node.execution.provider?.getRpc().fetch({method: "eth_getBalance", params: [address, "latest"]})) ?? - "0x0" - ); + const balance = await node.execution.provider?.eth.getBalance(address, "latest"); if (balance !== expectedBalanceAtCurrentSlot) { errors.push( diff --git a/packages/cli/test/utils/simulation/assertions/executionHeadAssertion.ts b/packages/cli/test/utils/simulation/assertions/executionHeadAssertion.ts index 595f98aea70..cef08bb3824 100644 --- a/packages/cli/test/utils/simulation/assertions/executionHeadAssertion.ts +++ b/packages/cli/test/utils/simulation/assertions/executionHeadAssertion.ts @@ -18,9 +18,9 @@ export function createExecutionHeadAssertion({ return AssertionMatch.None; }, async capture({node}) { - const blockNumber = await node.execution.provider?.getBlockNumber(); + const blockNumber = await node.execution.provider?.eth.getBlockNumber(); if (blockNumber == null) throw new Error("Execution provider not available"); - const executionHeadBlock = await node.execution.provider?.getBlockByNumber(blockNumber); + const executionHeadBlock = await node.execution.provider?.eth.getBlock(blockNumber); const consensusHead = await node.beacon.api.beacon.getBlockV2("head"); ApiError.assert(consensusHead); diff --git a/packages/cli/test/utils/simulation/clients/execution/geth.ts b/packages/cli/test/utils/simulation/clients/execution/geth.ts index 91ed754c285..f3f8d8f73a5 100644 --- a/packages/cli/test/utils/simulation/clients/execution/geth.ts +++ b/packages/cli/test/utils/simulation/clients/execution/geth.ts @@ -1,8 +1,7 @@ -/* eslint-disable @typescript-eslint/naming-convention */ import {writeFile} from "node:fs/promises"; import path from "node:path"; import got from "got"; -import {ZERO_HASH} from "@lodestar/state-transition"; +import {Web3} from "web3"; import { EL_GENESIS_ACCOUNT, EL_GENESIS_PASSWORD, @@ -10,7 +9,7 @@ import { SHARED_JWT_SECRET, SIM_ENV_NETWORK_ID, } from "../../constants.js"; -import {Eth1ProviderWithAdmin} from "../../eth1ProviderWithAdmin.js"; +import {registerWeb3JsPlugins} from "../../web3JsPlugins.js"; import {ExecutionClient, ExecutionNodeGenerator, ExecutionStartMode, JobOptions, RunnerType} from "../../interfaces.js"; import {getNodeMountedPaths} from "../../utils/paths.js"; import {getNodePorts} from "../../utils/ports.js"; @@ -166,11 +165,8 @@ export const generateGethNode: ExecutionNodeGenerator = (o const job = runner.create([{...initJobOptions, children: [{...importJobOptions, children: [startJobOptions]}]}]); - const provider = new Eth1ProviderWithAdmin( - {DEPOSIT_CONTRACT_ADDRESS: ZERO_HASH}, - // To allow admin_* RPC methods had to add "ethRpcUrl" - {providerUrls: [ethRpcPublicUrl, engineRpcPublicUrl], jwtSecretHex: SHARED_JWT_SECRET} - ); + const provider = new Web3(ethRpcPublicUrl); + registerWeb3JsPlugins(provider); return { client: ExecutionClient.Geth, diff --git a/packages/cli/test/utils/simulation/clients/execution/nethermind.ts b/packages/cli/test/utils/simulation/clients/execution/nethermind.ts index 4f864783d8b..0abc7ad8cc7 100644 --- a/packages/cli/test/utils/simulation/clients/execution/nethermind.ts +++ b/packages/cli/test/utils/simulation/clients/execution/nethermind.ts @@ -1,9 +1,8 @@ -/* eslint-disable @typescript-eslint/naming-convention */ import {writeFile} from "node:fs/promises"; import path from "node:path"; import got from "got"; -import {ZERO_HASH} from "@lodestar/state-transition"; -import {Eth1ProviderWithAdmin} from "../../eth1ProviderWithAdmin.js"; +import {Web3} from "web3"; +import {registerWeb3JsPlugins} from "../../web3JsPlugins.js"; import {ExecutionClient, ExecutionNodeGenerator, JobOptions, RunnerType} from "../../interfaces.js"; import {getNethermindChainSpec} from "../../utils/executionGenesis.js"; import {getNodeMountedPaths} from "../../utils/paths.js"; @@ -130,11 +129,8 @@ export const generateNethermindNode: ExecutionNodeGenerator => { - const method = "admin_nodeInfo"; - - return this.getRpc().fetch( - // false = include only transaction roots, not full objects - {method, params: []} - ); - }, - - addPeer: async (enode: string): Promise => { - const method = "admin_addPeer"; - - return this.getRpc().fetch( - // false = include only transaction roots, not full objects - {method, params: [enode]} - ); - }, - }; -} diff --git a/packages/cli/test/utils/simulation/interfaces.ts b/packages/cli/test/utils/simulation/interfaces.ts index 1e228b26371..e74b5c7a227 100644 --- a/packages/cli/test/utils/simulation/interfaces.ts +++ b/packages/cli/test/utils/simulation/interfaces.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import {ChildProcess} from "node:child_process"; import type {SecretKey} from "@chainsafe/bls/types"; +import {Web3} from "web3"; import {Api} from "@lodestar/api"; import {Api as KeyManagerApi} from "@lodestar/api/keymanager"; import {ChainForkConfig} from "@lodestar/config"; @@ -11,7 +12,6 @@ import {BeaconArgs} from "../../../src/cmds/beacon/options.js"; import {IValidatorCliArgs} from "../../../src/cmds/validator/options.js"; import {GlobalArgs} from "../../../src/options/index.js"; import {EpochClock} from "./epochClock.js"; -import {Eth1ProviderWithAdmin} from "./eth1ProviderWithAdmin.js"; export type NodeId = string; @@ -208,7 +208,7 @@ export interface ExecutionNode { */ readonly ethRpcPrivateUrl: string; readonly jwtSecretHex: string; - readonly provider: E extends ExecutionClient.Mock ? null : Eth1ProviderWithAdmin; + readonly provider: E extends ExecutionClient.Mock ? null : Web3; readonly job: Job; } diff --git a/packages/cli/test/utils/simulation/simulationEnvironment.ts b/packages/cli/test/utils/simulation/simulationEnvironment.ts index 24e3ced7da1..6d630d7dee1 100644 --- a/packages/cli/test/utils/simulation/simulationEnvironment.ts +++ b/packages/cli/test/utils/simulation/simulationEnvironment.ts @@ -317,9 +317,9 @@ export class SimulationEnvironment { const el = this.nodes[i].execution; // If eth1 is mock then genesis hash would be empty - const eth1Genesis = el.provider === null ? {hash: MOCK_ETH1_GENESIS_HASH} : await el.provider.getBlockByNumber(0); + const eth1Genesis = el.provider === null ? {hash: MOCK_ETH1_GENESIS_HASH} : await el.provider?.eth.getBlock(0); - if (!eth1Genesis) { + if (!eth1Genesis.hash) { throw new Error(`Eth1 genesis not found for node "${this.nodes[i].id}"`); } diff --git a/packages/cli/test/utils/simulation/utils/network.ts b/packages/cli/test/utils/simulation/utils/network.ts index cbdd1add7b8..fc62d0d6d88 100644 --- a/packages/cli/test/utils/simulation/utils/network.ts +++ b/packages/cli/test/utils/simulation/utils/network.ts @@ -45,7 +45,7 @@ export async function connectNewCLNode(newNode: BeaconNode, nodes: BeaconNode[]) } export async function connectNewELNode(newNode: ExecutionNode, nodes: ExecutionNode[]): Promise { - const elIdentity = newNode.provider === null ? null : await newNode.provider.admin.nodeInfo(); + const elIdentity = newNode.provider === null ? null : await newNode.provider?.admin.nodeInfo(); if (elIdentity && !elIdentity.enode) return; for (const node of nodes) { @@ -54,6 +54,7 @@ export async function connectNewELNode(newNode: ExecutionNode, nodes: ExecutionN // Nethermind had a bug in admin_addPeer RPC call // https://github.com/NethermindEth/nethermind/issues/4876 if (node.provider !== null && node.client !== ExecutionClient.Nethermind && elIdentity) { + // `web3.admin` here refers to the Web3 plugin `Web3AdminPlugin` await node.provider.admin.addPeer(elIdentity.enode); } } diff --git a/packages/cli/test/utils/simulation/web3JsPlugins.ts b/packages/cli/test/utils/simulation/web3JsPlugins.ts new file mode 100644 index 00000000000..e7d535063b1 --- /dev/null +++ b/packages/cli/test/utils/simulation/web3JsPlugins.ts @@ -0,0 +1,47 @@ +import {Web3PluginBase, Web3} from "web3"; + +class Web3AdminPlugin extends Web3PluginBase { + /** + * The admin plugin as available via the provider object + * like in the example below. + * + * await node.web3.admin.addPeer(elIdentity.enode); + */ + pluginNamespace = "admin"; + + async nodeInfo(): Promise<{ + enode: string; + id: string; + ip: string; + listenAddr: string; + name: string; + ports: { + discovery: number; + listener: number; + }; + protocols: { + eth: { + difficulty: number; + genesis: string; + head: string; + network: number; + }; + }; + }> { + return this.requestManager.send({method: "admin_nodeInfo", params: []}); + } + + async addPeer(enode: string): Promise { + return this.requestManager.send({method: "admin_addPeer", params: [enode]}); + } +} + +declare module "web3" { + interface Web3Context { + admin: Web3AdminPlugin; + } +} + +export function registerWeb3JsPlugins(web3: Web3): void { + web3.registerPlugin(new Web3AdminPlugin()); +} From d450cce216ee16a8be61d4ae03b81d0ca05dc054 Mon Sep 17 00:00:00 2001 From: Mihai Date: Mon, 8 Apr 2024 07:29:53 -0400 Subject: [PATCH 5/6] docs: add list of public endpoints to getting started page (#6644) add list of public endpoints --- docs/pages/getting-started/starting-a-node.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/getting-started/starting-a-node.md b/docs/pages/getting-started/starting-a-node.md index 7b5c132e305..86c03c621c4 100644 --- a/docs/pages/getting-started/starting-a-node.md +++ b/docs/pages/getting-started/starting-a-node.md @@ -115,6 +115,7 @@ In case you really trust `checkpointSyncUrl` then you may skip providing `wssChe :::warning Please use this option very carefully (and at your own risk), a malicious server URL can put you on the wrong chain with a danger of you losing your funds by social engineering. If possible, validate your `wssCheckpoint` from multiple places (e.g. different client distributions) or from other trusted sources. This will highly reduce the risk of starting off on a malicious chain. +This list of [public endpoints](https://eth-clients.github.io/checkpoint-sync-endpoints/) maintained by the Ethereum community may be used for reference. ::: **Taking too long to sync?** From 7fadd303fad8679ee2b7462747b9d9fc33dafb23 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 8 Apr 2024 23:21:15 +0100 Subject: [PATCH 6/6] fix: properly handle missing schema if route is not defined (#6650) * fix: properly handle missing schema if route is not defined * Access schema from route options Looks like `request.routeSchema` will be deprecated (runtime only warning) (node:7) [FSTDEP015] DeprecationWarning: You are accessing the deprecated "request.routeSchema" property. Use "request.routeOptions.schema" instead. Property "req.routeSchema" will be removed in `fastify@5`. --- packages/beacon-node/src/api/rest/base.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index 3de7f7db3fd..dbf69cd0d01 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -1,5 +1,5 @@ import {parse as parseQueryString} from "qs"; -import {FastifyInstance, fastify} from "fastify"; +import {FastifyInstance, FastifyRequest, fastify} from "fastify"; import {fastifyCors} from "@fastify/cors"; import bearerAuthPlugin from "@fastify/bearer-auth"; import {ErrorAborted, Gauge, Histogram, Logger} from "@lodestar/utils"; @@ -62,7 +62,7 @@ export class RestApiServer { this.activeSockets = new HttpActiveSocketsTracker(server.server, metrics); // To parse our ApiError -> statusCode - server.setErrorHandler((err, req, res) => { + server.setErrorHandler((err, _req, res) => { if (err.validation) { void res.status(400).send(err.validation); } else { @@ -83,19 +83,19 @@ export class RestApiServer { // Log all incoming request to debug (before parsing). TODO: Should we hook latter in the lifecycle? https://www.fastify.io/docs/latest/Lifecycle/ // Note: Must be an async method so fastify can continue the release lifecycle. Otherwise we must call done() or the request stalls server.addHook("onRequest", async (req, _res) => { - const operationId = req.routeSchema.operationId as string; + const operationId = getOperationId(req); this.logger.debug(`Req ${req.id} ${req.ip} ${operationId}`); metrics?.requests.inc({operationId}); }); server.addHook("preHandler", async (req, _res) => { - const operationId = req.routeSchema.operationId as string; + const operationId = getOperationId(req); this.logger.debug(`Exec ${req.id} ${req.ip} ${operationId}`); }); // Log after response server.addHook("onResponse", async (req, res) => { - const operationId = req.routeSchema.operationId as string; + const operationId = getOperationId(req); this.logger.debug(`Res ${req.id} ${operationId} - ${res.raw.statusCode}`); metrics?.responseTime.observe({operationId}, res.elapsedTime / 1000); }); @@ -105,7 +105,7 @@ export class RestApiServer { // Don't log NodeISSyncing errors, they happen very frequently while syncing and the validator polls duties if (err instanceof ErrorAborted || err instanceof NodeIsSyncing) return; - const operationId = req.routeSchema.operationId as string; + const operationId = getOperationId(req); if (err instanceof ApiError) { this.logger.warn(`Req ${req.id} ${operationId} failed`, {reason: err.message}); @@ -157,3 +157,8 @@ export class RestApiServer { return false; } } + +function getOperationId(req: FastifyRequest): string { + // Note: `schema` will be `undefined` if route is not defined + return req.routeOptions.schema?.operationId ?? "unknown"; +}