Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove got dependency #6497

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bb7bb0b
Changed got to fetch in file.ts
HiroyukiNaito Feb 28, 2024
d34d763
Align the valuable name
HiroyukiNaito Feb 28, 2024
492f12a
Completed changing module got to fetch in file.ts
HiroyukiNaito Feb 28, 2024
357c37a
Changed All files got to fetch
HiroyukiNaito Feb 28, 2024
ca99c0c
Update packages/cli/src/util/file.ts
HiroyukiNaito Feb 29, 2024
883fca8
Update packages/cli/src/util/file.ts
HiroyukiNaito Feb 29, 2024
0174d36
Delete got package by yarn remove command
HiroyukiNaito Feb 29, 2024
39c4bd1
Delete
HiroyukiNaito Feb 29, 2024
5bbc97c
Delete downloadOrCopyFile(pathDest: string, urlOrPathSrc: string): P…
HiroyukiNaito Feb 29, 2024
d573a50
Update packages/cli/test/utils/simulation/beacon_clients/lighthouse.ts
HiroyukiNaito Feb 29, 2024
cbdd24b
Update packages/cli/test/utils/simulation/beacon_clients/lodestar.ts
HiroyukiNaito Feb 29, 2024
193ad5a
Changed Fetch error
HiroyukiNaito Feb 29, 2024
e9d8b77
Changed to return Buffer.from(await res.arrayBuffer());
HiroyukiNaito Feb 29, 2024
fe41173
Edited downloadTestFile
HiroyukiNaito Feb 29, 2024
273f5c5
Changed some codes
HiroyukiNaito Feb 29, 2024
ad0bdf1
Merge remote-tracking branch 'upstream/unstable' into unstable
HiroyukiNaito Feb 29, 2024
087589f
Added Error check logic
HiroyukiNaito Feb 29, 2024
ae3f92c
Changed for PR
HiroyukiNaito Feb 29, 2024
56f644b
Delete a unused function downloadFilefunction downloadFile in files.ts
HiroyukiNaito Feb 29, 2024
2b2e1e1
Alighed Error message
HiroyukiNaito Feb 29, 2024
fcaf7ea
Added fetch "@lodestar/api";
HiroyukiNaito Mar 1, 2024
e92c5ba
Deleted (err instanceof FetchError && err.code !== "ECONNREFUSED") logic
HiroyukiNaito Mar 1, 2024
ba0b674
added HealthStatus
HiroyukiNaito Mar 1, 2024
a44139e
Added Utility function for postEthRpc
HiroyukiNaito Mar 1, 2024
19c016c
Changed Error handling
HiroyukiNaito Mar 2, 2024
0ce433a
Lint fix
HiroyukiNaito Mar 2, 2024
f775aff
Mistakely deleted lint restored.
HiroyukiNaito Mar 2, 2024
e90a890
Lint corrected
HiroyukiNaito Mar 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"deepmerge": "^4.3.1",
"ethers": "^6.7.0",
"find-up": "^6.3.0",
"got": "^11.8.6",
"inquirer": "^9.1.5",
"js-yaml": "^4.1.0",
"prom-client": "^15.1.0",
Expand All @@ -91,7 +90,6 @@
"devDependencies": {
"@lodestar/test-utils": "^1.16.0",
"@types/debug": "^4.1.7",
"@types/got": "^9.6.12",
"@types/inquirer": "^9.0.3",
"@types/proper-lockfile": "^4.1.4",
"@types/yargs": "^17.0.24"
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/networks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from "node:fs";
import got from "got";
import {ENR} from "@chainsafe/enr";
import {SLOTS_PER_EPOCH} from "@lodestar/params";
import {ApiError, getClient} from "@lodestar/api";
Expand Down Expand Up @@ -107,8 +106,11 @@ export async function fetchBootnodes(network: NetworkName): Promise<string[]> {
if (bootnodesFileUrl === null) {
return [];
}

const bootnodesFile = await got.get(bootnodesFileUrl).text();
const res = await fetch(bootnodesFileUrl);
if (!res.ok) {
throw new Error(`Failed to fetch bootnodes file. Status: ${res.status} ${res.statusText}`);
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
}
const bootnodesFile = await res.text();
return parseBootnodesFile(bootnodesFile);
}

Expand Down
25 changes: 5 additions & 20 deletions packages/cli/src/util/file.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import fs from "node:fs";
import path from "node:path";
import stream from "node:stream";
import {promisify} from "node:util";
import got from "got";
import yaml from "js-yaml";
const {load, dump, FAILSAFE_SCHEMA, Type} = yaml;

Expand Down Expand Up @@ -111,26 +108,14 @@ export function readFileIfExists<T>(filepath: string, acceptedFormats?: string[]
}
}

/**
* Download from URL or copy from local filesystem
* @param urlOrPathSrc "/path/to/file.szz" | "https://url.to/file.szz"
*/
export async function downloadOrCopyFile(pathDest: string, urlOrPathSrc: string): Promise<void> {
if (isUrl(urlOrPathSrc)) {
await downloadFile(pathDest, urlOrPathSrc);
} else {
mkdir(path.dirname(pathDest));
await fs.promises.copyFile(urlOrPathSrc, pathDest);
}
}

/**
* Downloads a genesis file per network if it does not exist
*/
export async function downloadFile(pathDest: string, url: string): Promise<void> {
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
if (!fs.existsSync(pathDest)) {
mkdir(path.dirname(pathDest));
await promisify(stream.pipeline)(got.stream(url), fs.createWriteStream(pathDest));
const res = await fetch(url);
const buffer = new Uint8Array(await res.arrayBuffer());
await fs.promises.writeFile(pathDest, buffer);
}
}

Expand All @@ -140,8 +125,8 @@ export async function downloadFile(pathDest: string, url: string): Promise<void>
*/
export async function downloadOrLoadFile(pathOrUrl: string): Promise<Uint8Array> {
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
if (isUrl(pathOrUrl)) {
const res = await got.get(pathOrUrl, {encoding: "binary"});
return res.rawBody;
const res = await fetch(pathOrUrl);
return new Uint8Array(await res.arrayBuffer());
} else {
return fs.promises.readFile(pathOrUrl);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {writeFile} from "node:fs/promises";
import path from "node:path";
import got, {RequestError} from "got";
import yaml from "js-yaml";
import {HttpClient} from "@lodestar/api";
import {getClient} from "@lodestar/api/beacon";
Expand Down Expand Up @@ -92,10 +91,9 @@ export const generateLighthouseBeaconNode: BeaconNodeGenerator<BeaconClient.Ligh
},
health: async () => {
try {
await got.get(`http://127.0.0.1:${ports.beacon.httpPort}/eth/v1/node/health`);
return {ok: true};
return await fetch(`http://127.0.0.1:${ports.beacon.httpPort}/eth/v1/node/health`);
} catch (err) {
if (err instanceof RequestError && err.code !== "ECONNREFUSED") {
if (err instanceof FetchError && err.code !== "ECONNREFUSED") {
return {ok: true};
}
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
return {ok: false, reason: (err as Error).message, checkId: "/eth/v1/node/health query"};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {writeFile} from "node:fs/promises";
import path from "node:path";
import got from "got";
import {getClient} from "@lodestar/api/beacon";
import {chainConfigToJson} from "@lodestar/config";
import {LogLevel} from "@lodestar/utils";
Expand Down Expand Up @@ -96,8 +95,7 @@ export const generateLodestarBeaconNode: BeaconNodeGenerator<BeaconClient.Lodest
},
health: async () => {
try {
await got.get(`http://${address}:${ports.beacon.httpPort}/eth/v1/node/health`);
return {ok: true};
return await fetch(`http://${address}:${ports.beacon.httpPort}/eth/v1/node/health`);
} catch (err) {
return {ok: false, reason: (err as Error).message, checkId: "eth/v1/node/health query"};
}
Expand Down
15 changes: 12 additions & 3 deletions packages/cli/test/utils/simulation/execution_clients/geth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* 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 {
EL_GENESIS_ACCOUNT,
Expand Down Expand Up @@ -155,8 +154,18 @@ export const generateGethNode: ExecutionNodeGenerator<ExecutionClient.Geth> = (o
},
health: async () => {
try {
await got.post(ethRpcPublicUrl, {json: {jsonrpc: "2.0", method: "net_version", params: [], id: 67}});
return {ok: true};
return await fetch(ethRpcPublicUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "net_version",
params: [],
id: 67,
}),
});
} catch (err) {
return {ok: false, reason: (err as Error).message, checkId: "JSON RPC query net_version"};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* 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 {ExecutionClient, ExecutionNodeGenerator, JobOptions, RunnerType} from "../interfaces.js";
Expand Down Expand Up @@ -102,8 +101,18 @@ export const generateNethermindNode: ExecutionNodeGenerator<ExecutionClient.Neth
},
health: async () => {
try {
await got.post(ethRpcPublicUrl, {json: {jsonrpc: "2.0", method: "net_version", params: [], id: 67}});
return {ok: true};
return await fetch(ethRpcPublicUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "net_version",
params: [],
id: 67,
}),
});
} catch (err) {
return {ok: false, reason: (err as Error).message, checkId: "JSON RPC query net_version"};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from "node:path";
import {writeFile} from "node:fs/promises";
import got, {RequestError} from "got";
import yaml from "js-yaml";
import {getClient as keyManagerGetClient} from "@lodestar/api/keymanager";
import {chainConfigToJson} from "@lodestar/config";
Expand Down Expand Up @@ -82,10 +81,9 @@ export const generateLighthouseValidatorNode: ValidatorNodeGenerator<ValidatorCl
},
health: async () => {
try {
await got.get(`http://127.0.0.1:${ports.validator.keymanagerPort}/lighthouse/health`);
return {ok: true};
return await fetch(`http://127.0.0.1:${ports.validator.keymanagerPort}/lighthouse/health`);
} catch (err) {
if (err instanceof RequestError) {
if (err instanceof FetchError && err.code !== "ECONNREFUSED") {
return {ok: true};
}
return {ok: false, reason: (err as Error).message, checkId: "/lighthouse/health query"};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {writeFile} from "node:fs/promises";
import path from "node:path";
import got from "got";
import {getClient as keyManagerGetClient} from "@lodestar/api/keymanager";
import {chainConfigToJson} from "@lodestar/config";
import {LogLevel} from "@lodestar/utils";
Expand Down Expand Up @@ -70,8 +69,7 @@ export const generateLodestarValidatorNode: ValidatorNodeGenerator<ValidatorClie
},
health: async () => {
try {
await got.get(`http://127.0.0.1:${ports.validator.keymanagerPort}/eth/v1/keystores`);
return {ok: true};
return await fetch(`http://127.0.0.1:${ports.validator.keymanagerPort}/eth/v1/keystores`);
} catch (err) {
return {ok: false, reason: (err as Error).message, checkId: "eth/v1/keystores query"};
}
Expand Down
6 changes: 2 additions & 4 deletions packages/state-transition/test/utils/testFileCache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from "node:fs";
import path from "node:path";
import got from "got";
import {ApiError, getClient} from "@lodestar/api";
import {NetworkName, networksChainConfig} from "@lodestar/config/networks";
import {createChainForkConfig, ChainForkConfig} from "@lodestar/config";
Expand Down Expand Up @@ -103,12 +102,11 @@ async function downloadTestFile(fileId: string): Promise<Buffer> {
const fileUrl = `${TEST_FILES_BASE_URL}/${fileId}`;
// eslint-disable-next-line no-console
console.log(`Downloading file ${fileUrl}`);

const res = await got(fileUrl, {responseType: "buffer"}).catch((e: Error) => {
const res = await fetch(fileUrl).catch((e: Error) => {
e.message = `Error downloading ${fileUrl}: ${e.message}`;
throw e;
});
return res.body;
return Buffer.from(await res.arrayBuffer());
}

async function tryEach<T>(promises: (() => Promise<T>)[]): Promise<T> {
Expand Down
16 changes: 1 addition & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2846,15 +2846,6 @@
resolved "https://registry.yarnpkg.com/@types/eventsource/-/eventsource-1.1.11.tgz#a2c0bfd0436b7db42ed1b2b2117f7ec2e8478dc7"
integrity sha512-L7wLDZlWm5mROzv87W0ofIYeQP5K2UhoFnnUyEWLKM6UBb0ZNRgAqp98qE5DkgfBXdWfc2kYmw9KZm4NLjRbsw==

"@types/got@^9.6.12":
version "9.6.12"
resolved "https://registry.yarnpkg.com/@types/got/-/got-9.6.12.tgz#fd42a6e1f5f64cd6bb422279b08c30bb5a15a56f"
integrity sha512-X4pj/HGHbXVLqTpKjA2ahI4rV/nNBc9mGO2I/0CgAra+F2dKgMXnENv2SRpemScBzBAI4vMelIVYViQxlSE6xA==
dependencies:
"@types/node" "*"
"@types/tough-cookie" "*"
form-data "^2.5.0"

"@types/http-cache-semantics@*":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz#a3ff232bf7d5c55f38e4e45693eda2ebb545794d"
Expand Down Expand Up @@ -3084,11 +3075,6 @@
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.2.3.tgz#908bfb113419fd6a42273674c00994d40902c165"
integrity sha512-dDZH/tXzwjutnuk4UacGgFRwV+JSLaXL1ikvidfJprkb7L9Nx1njcRHHmi3Dsvt7pgqqTEeucQuOrWHPFgzVHA==

"@types/tough-cookie@*":
version "4.0.0"
resolved "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.0.tgz"
integrity sha512-I99sngh224D0M7XgW1s120zxCt3VYQ3IQsuw3P3jbq5GG4yc79+ZjyKznyOGIQrflfylLgcfekeZW/vk0yng6A==

"@types/triple-beam@^1.3.2":
version "1.3.2"
resolved "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.2.tgz"
Expand Down Expand Up @@ -6924,7 +6910,7 @@ gopd@^1.0.1:
dependencies:
get-intrinsic "^1.1.3"

got@^11.8.5, got@^11.8.6:
got@^11.8.5:
version "11.8.6"
resolved "https://registry.yarnpkg.com/got/-/got-11.8.6.tgz#276e827ead8772eddbcfc97170590b841823233a"
integrity sha512-6tfZ91bOr7bOXnK7PRDCGBLa1H4U080YHNaAQ2KsMGlLEzRbk44nsZF2E1IeRc3vtJHPVbKCYgdFbaGO2ljd8g==
Expand Down