Skip to content

Commit

Permalink
chore!: use node v20 throughout monorepo (#5730)
Browse files Browse the repository at this point in the history
* chore!: use node 20 throughout monorepo

* Add yarn.lock

* Revert @types/node change

* Fix ts-node usage

* Add missed files

* Remove more ts-node-esm

* Update cross-fetch dependency

* Update @types/node to 20.4.2

* Use node version 20.4 in CI

* Revert "Use node version 20.4 in CI"

* skip tests that break in CI

* Update Dockerfile

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

* Check code ECONNRESET in Lighthouse health response

* Revert "Check code ECONNRESET in Lighthouse health response"

* Revert "Update Dockerfile"

This reverts commit e1f07be.

* Revert CI from using node 20

* Revert "skip tests that break in CI"

This reverts commit d296b2f.

* Fix the loader for few sim tests

* Update CI node version to 20

* Fix e2e test

* Remove try/catch from e2e test

* Consistently use node 20 in CI

* Fix missed 18.x reference in types readme

* Set node 20.x in readme

* Use node 18 in sim tests

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
Co-authored-by: Nazar Hussain <nazarhussain@gmail.com>
  • Loading branch information
3 people committed Jul 16, 2023
1 parent cdca9fb commit 6e01421
Show file tree
Hide file tree
Showing 33 changed files with 91 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
check-latest: true
- name: Node.js version
id: node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-check.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
- name: Node.js version
id: node
run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
check-latest: true
- name: Node.js version
id: node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-dev.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
registry-url: "https://registry.npmjs.org"
check-latest: true
- name: Node.js version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-rc.yml
Expand Up @@ -54,7 +54,7 @@ jobs:
fetch-depth: 0 # Needs full depth for changelog generation
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
check-latest: true
- name: Node.js version
id: node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-stable.yml
Expand Up @@ -60,7 +60,7 @@ jobs:
fetch-depth: 0 # Needs full depth for changelog generation
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
check-latest: true
- name: Node.js version
id: node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-browser.yml
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [18]
node: [20]
steps:
# <common-build> - Uses YAML anchors in the future
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e.yml
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [18]
node: [20]
steps:
# <common-build> - Uses YAML anchors in the future
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-sim-merge.yml
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
check-latest: true
- name: Node.js version
id: node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-spec.yml
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
check-latest: true
- name: Node.js version
id: node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [18]
node: [20]
steps:
# <common-build> - Uses YAML anchors in the future
- uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
@@ -1,7 +1,7 @@

# --platform=$BUILDPLATFORM is used build javascript source with host arch
# Otherwise TS builds on emulated archs and can be extremely slow (+1h)
FROM --platform=${BUILDPLATFORM:-amd64} node:18-alpine as build_src
FROM --platform=${BUILDPLATFORM:-amd64} node:20-alpine as build_src
ARG COMMIT
WORKDIR /usr/app
RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*
Expand All @@ -21,7 +21,7 @@ RUN cd packages/cli && GIT_COMMIT=${COMMIT} yarn write-git-data

# Copy built src + node_modules to build native packages for archs different than host.
# Note: This step is redundant for the host arch
FROM node:18-alpine as build_deps
FROM node:20-alpine as build_deps
WORKDIR /usr/app
RUN apk update && apk add --no-cache g++ make python3 && rm -rf /var/cache/apk/*

Expand All @@ -35,7 +35,7 @@ RUN cd node_modules/classic-level && yarn rebuild

# Copy built src + node_modules to a new layer to prune unnecessary fs
# Previous layer weights 7.25GB, while this final 488MB (as of Oct 2020)
FROM node:18-alpine
FROM node:20-alpine
WORKDIR /usr/app
COPY --from=build_deps /usr/app .

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -8,7 +8,7 @@
[![Ethereum Consensus Spec v1.1.10](https://img.shields.io/badge/ETH%20consensus--spec-1.1.10-blue)](https://github.com/ethereum/consensus-specs/releases/tag/v1.1.10)
[![codecov](https://codecov.io/gh/ChainSafe/lodestar/branch/unstable/graph/badge.svg)](https://codecov.io/gh/ChainSafe/lodestar)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.15.x-green)
![Node Version](https://img.shields.io/badge/node-20.x-green)
[![gitpoap badge](https://public-api.gitpoap.io/v1/repo/ChainSafe/lodestar/badge)](https://www.gitpoap.io/gh/ChainSafe/lodestar)

[Lodestar](https://lodestar.chainsafe.io) is a TypeScript implementation of the [Ethereum Consensus specification](https://github.com/ethereum/consensus-specs) developed by [ChainSafe Systems](https://chainsafe.io).
Expand Down
2 changes: 1 addition & 1 deletion docs/install/source.md
Expand Up @@ -2,7 +2,7 @@

## Prerequisites

Make sure to have [Yarn installed](https://classic.yarnpkg.com/en/docs/install). It is also recommended to [install NVM (Node Version Manager)](https://github.com/nvm-sh/nvm) and use the LTS version (currently v18) of [NodeJS](https://nodejs.org/en/).
Make sure to have [Yarn installed](https://classic.yarnpkg.com/en/docs/install). It is also recommended to [install NVM (Node Version Manager)](https://github.com/nvm-sh/nvm) and use the LTS version (currently v20) of [NodeJS](https://nodejs.org/en/).

<!-- prettier-ignore-start -->
!!! info
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,7 +41,7 @@
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.11",
"@types/node": "^20.4.2",
"@types/sinon": "^10.0.13",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/README.md
Expand Up @@ -3,7 +3,7 @@
[![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
[![ETH Beacon APIs Spec v2.1.0](https://img.shields.io/badge/ETH%20beacon--APIs-2.1.0-blue)](https://github.com/ethereum/beacon-APIs/releases/tag/v2.1.0)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.x-green)
![Node Version](https://img.shields.io/badge/node-20.x-green)

> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Expand Up @@ -75,7 +75,7 @@
"@lodestar/params": "^1.9.1",
"@lodestar/types": "^1.9.1",
"@lodestar/utils": "^1.9.1",
"cross-fetch": "^3.1.4",
"cross-fetch": "^4.0.0",
"eventsource": "^2.0.2",
"qs": "^6.11.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/README.md
Expand Up @@ -3,7 +3,7 @@
[![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
[![Eth Consensus Spec v1.1.10](https://img.shields.io/badge/ETH%20consensus--spec-1.1.10-blue)](https://github.com/ethereum/consensus-specs/releases/tag/v1.1.10)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.x-green)
![Node Version](https://img.shields.io/badge/node-20.x-green)

> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/package.json
Expand Up @@ -136,7 +136,7 @@
"@types/datastore-level": "^3.0.0",
"buffer-xor": "^2.0.2",
"c-kzg": "^2.1.0",
"cross-fetch": "^3.1.4",
"cross-fetch": "^4.0.0",
"datastore-core": "^9.1.1",
"datastore-level": "^10.1.1",
"deepmerge": "^4.3.1",
Expand Down
23 changes: 18 additions & 5 deletions packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts
Expand Up @@ -6,6 +6,10 @@ import {JsonRpcHttpClient} from "../../../src/eth1/provider/jsonRpcHttpClient.js
import {getGoerliRpcUrl} from "../../testParams.js";
import {RpcPayload} from "../../../src/eth1/interface.js";

type FetchError = {
code: string;
};

describe("eth1 / jsonRpcHttpClient", function () {
this.timeout("10 seconds");

Expand All @@ -22,6 +26,7 @@ describe("eth1 / jsonRpcHttpClient", function () {
abort?: true;
timeout?: number;
error: any;
errorCode?: string;
}[] = [
// // NOTE: This DNS query is very expensive, all cache miss. So it can timeout the tests and cause false positives
// {
Expand All @@ -39,7 +44,8 @@ describe("eth1 / jsonRpcHttpClient", function () {
id: "Bad port",
url: `http://localhost:${port + 1}`,
requestListener: (req, res) => res.end(),
error: "connect ECONNREFUSED",
error: "",
errorCode: "ECONNREFUSED",
},
{
id: "Not a JSON RPC endpoint",
Expand Down Expand Up @@ -122,7 +128,6 @@ describe("eth1 / jsonRpcHttpClient", function () {

for (const testCase of testCases) {
const {id, requestListener, abort, timeout} = testCase;
const error = testCase.error as Error;
let {url, payload} = testCase;

it(id, async function () {
Expand All @@ -148,7 +153,13 @@ describe("eth1 / jsonRpcHttpClient", function () {
const controller = new AbortController();
if (abort) setTimeout(() => controller.abort(), 50);
const eth1JsonRpcClient = new JsonRpcHttpClient([url], {signal: controller.signal});
await expect(eth1JsonRpcClient.fetch(payload, {timeout})).to.be.rejectedWith(error);
await expect(eth1JsonRpcClient.fetch(payload, {timeout})).to.be.rejected.then((error) => {
if (testCase.errorCode) {
expect((error as FetchError).code).to.be.equal(testCase.errorCode);
} else {
expect((error as Error).message).to.include(testCase.error);
}
});
});
}
});
Expand Down Expand Up @@ -210,8 +221,10 @@ describe("eth1 / jsonRpcHttpClient - with retries", function () {
return true;
},
})
).to.be.rejectedWith("connect ECONNREFUSED");
expect(retryCount).to.be.equal(retryAttempts, "connect ECONNREFUSED should be retried before failing");
).to.be.rejected.then((error) => {
expect((error as FetchError).code).to.be.equal("ECONNREFUSED");
});
expect(retryCount).to.be.equal(retryAttempts, "code ECONNREFUSED should be retried before failing");
});

it("should retry 404", async function () {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Expand Up @@ -24,7 +24,7 @@
"build": "tsc -p tsconfig.build.json && yarn write-git-data",
"build:release": "yarn clean && yarn run build",
"build:watch": "tsc -p tsconfig.build.json --watch",
"build:refdocs": "ts-node --esm ./docsgen/index.ts docs/cli.md",
"build:refdocs": "node --loader ts-node/esm ./docsgen/index.ts docs/cli.md",
"write-git-data": "node lib/util/gitData/writeGitData.js",
"check-build": "node -e \"(async function() { await import('./lib/index.js') })()\" lodestar --help",
"check-types": "tsc",
Expand All @@ -33,10 +33,10 @@
"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:multifork": "LODESTAR_PRESET=minimal ts-node --esm test/sim/multi_fork.test.ts",
"test:sim:endpoints": "LODESTAR_PRESET=minimal ts-node --esm test/sim/endpoints.test.ts",
"test:sim:deneb": "LODESTAR_PRESET=minimal ts-node --esm test/sim/deneb.test.ts",
"test:sim:backup_eth_provider": "LODESTAR_PRESET=minimal ts-node --esm test/sim/backup_eth_provider.test.ts",
"test:sim:multifork": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/multi_fork.test.ts",
"test:sim:endpoints": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/endpoints.test.ts",
"test:sim:deneb": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/deneb.test.ts",
"test:sim:backup_eth_provider": "LODESTAR_PRESET=minimal node --loader ts-node/esm test/sim/backup_eth_provider.test.ts",
"test": "yarn test:unit && yarn test:e2e",
"coverage": "codecov -F lodestar",
"check-readme": "typescript-docs-verifier"
Expand Down
2 changes: 1 addition & 1 deletion packages/light-client/package.json
Expand Up @@ -73,7 +73,7 @@
"@lodestar/state-transition": "^1.9.1",
"@lodestar/types": "^1.9.1",
"@lodestar/utils": "^1.9.1",
"cross-fetch": "^3.1.4",
"cross-fetch": "^4.0.0",
"mitt": "^3.0.0",
"strict-event-emitter-types": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/params/README.md
Expand Up @@ -4,7 +4,7 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Eth Consensus Spec v1.1.10](https://img.shields.io/badge/ETH%20consensus--spec-1.1.10-blue)](https://github.com/ethereum/consensus-specs/releases/tag/v1.1.10)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.x-green)
![Node Version](https://img.shields.io/badge/node-20.x-green)

> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
Expand Down
5 changes: 2 additions & 3 deletions packages/params/test/e2e/overridePreset.test.ts
Expand Up @@ -18,18 +18,17 @@ const exec = util.promisify(child.exec);
// Solutions: https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules
// eslint-disable-next-line @typescript-eslint/naming-convention
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const tsNodeBinary = path.join(__dirname, "../../../../node_modules/.bin/ts-node-esm");

describe("Override preset", function () {
// Allow time for ts-node to compile Typescript source
this.timeout(30_000);

it("Should correctly override preset", async () => {
await exec(`${tsNodeBinary} ${path.join(__dirname, scriptNames.ok)}`);
await exec(`node --loader ts-node/esm ${path.join(__dirname, scriptNames.ok)}`);
});

it("Should throw trying to override preset in the wrong order", async () => {
await expect(exec(`${tsNodeBinary} ${path.join(__dirname, scriptNames.error)}`)).to.be.rejectedWith(
await expect(exec(`node --loader ts-node/esm ${path.join(__dirname, scriptNames.error)}`)).to.be.rejectedWith(
"Lodestar preset is already frozen"
);
});
Expand Down
5 changes: 2 additions & 3 deletions packages/params/test/e2e/setPreset.test.ts
Expand Up @@ -18,18 +18,17 @@ const exec = util.promisify(child.exec);
// Solutions: https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules
// eslint-disable-next-line @typescript-eslint/naming-convention
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const tsNodeBinary = path.join(__dirname, "../../../../node_modules/.bin/ts-node-esm");

describe("setPreset", function () {
// Allow time for ts-node to compile Typescript source
this.timeout(30_000);

it("Should correctly set preset", async () => {
await exec(`${tsNodeBinary} ${path.join(__dirname, scriptNames.ok)}`);
await exec(`node --loader ts-node/esm ${path.join(__dirname, scriptNames.ok)}`);
});

it("Should throw trying to set preset in the wrong order", async () => {
await expect(exec(`${tsNodeBinary} ${path.join(__dirname, scriptNames.error)}`)).to.be.rejectedWith(
await expect(exec(`node --loader ts-node/esm ${path.join(__dirname, scriptNames.error)}`)).to.be.rejectedWith(
"Lodestar preset is already frozen"
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/prover/README.md
Expand Up @@ -3,7 +3,7 @@
[![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
[![ETH Beacon APIs Spec v2.1.0](https://img.shields.io/badge/ETH%20beacon--APIs-2.1.0-blue)](https://github.com/ethereum/beacon-APIs/releases/tag/v2.1.0)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.x-green)
![Node Version](https://img.shields.io/badge/node-20.x-green)

> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
Expand Down
2 changes: 1 addition & 1 deletion packages/prover/package.json
Expand Up @@ -55,7 +55,7 @@
"test:browsers": "yarn karma start karma.config.cjs",
"test:e2e": "LODESTAR_PRESET=minimal mocha 'test/e2e/**/*.test.ts'",
"check-readme": "typescript-docs-verifier",
"generate-fixtures": "npx ts-node --esm scripts/generate_fixtures.ts"
"generate-fixtures": "node --loader ts-node/esm scripts/generate_fixtures.ts"
},
"dependencies": {
"@ethereumjs/block": "^4.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/reqresp/README.md
Expand Up @@ -3,7 +3,7 @@
[![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
[![ETH Beacon APIs Spec v2.1.0](https://img.shields.io/badge/ETH%20beacon--APIs-2.1.0-blue)](https://github.com/ethereum/beacon-APIs/releases/tag/v2.1.0)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.x-green)
![Node Version](https://img.shields.io/badge/node-20.x-green)

> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
Expand Down
2 changes: 1 addition & 1 deletion packages/types/README.md
Expand Up @@ -4,7 +4,7 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Eth Consensus Spec v1.1.10](https://img.shields.io/badge/ETH%20consensus--spec-1.1.10-blue)](https://github.com/ethereum/consensus-specs/releases/tag/v1.1.10)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.x-green)
![Node Version](https://img.shields.io/badge/node-20.x-green)

> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
Expand Down
2 changes: 1 addition & 1 deletion packages/validator/README.md
Expand Up @@ -3,7 +3,7 @@
[![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
[![Eth Consensus Spec v1.1.10](https://img.shields.io/badge/ETH%20consensus--spec-1.1.10-blue)](https://github.com/ethereum/consensus-specs/releases/tag/v1.1.10)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.x-green)
![Node Version](https://img.shields.io/badge/node-20.x-green)

> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
Expand Down
2 changes: 1 addition & 1 deletion packages/validator/package.json
Expand Up @@ -58,7 +58,7 @@
"@lodestar/types": "^1.9.1",
"@lodestar/utils": "^1.9.1",
"bigint-buffer": "^1.1.5",
"cross-fetch": "^3.1.4",
"cross-fetch": "^4.0.0",
"strict-event-emitter-types": "^2.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 6e01421

Please sign in to comment.