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

Draft
wants to merge 28 commits into
base: unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion 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 Down
5 changes: 2 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,8 @@ export async function fetchBootnodes(network: NetworkName): Promise<string[]> {
if (bootnodesFileUrl === null) {
return [];
}

const bootnodesFile = await got.get(bootnodesFileUrl).text();
const res = await fetch(bootnodesFileUrl);
const bootnodesFile = await res.text();
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
return parseBootnodesFile(bootnodesFile);
}

Expand Down
13 changes: 6 additions & 7 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 @@ -129,8 +126,9 @@ export async function downloadOrCopyFile(pathDest: string, urlOrPathSrc: string)
*/
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 +138,9 @@ 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);
const rawBody = new Uint8Array(await res.arrayBuffer())
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
return rawBody;
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
} 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,10 @@ export const generateLighthouseBeaconNode: BeaconNodeGenerator<BeaconClient.Ligh
},
health: async () => {
try {
await got.get(`http://127.0.0.1:${ports.beacon.httpPort}/eth/v1/node/health`);
await fetch(`http://127.0.0.1:${ports.beacon.httpPort}/eth/v1/node/health`);
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
return {ok: true};
} catch (err) {
if (err instanceof RequestError && err.code !== "ECONNREFUSED") {
if (err instanceof Error && !err.message.includes('ECONNREFUSED')) {
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
return {ok: true};
}
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,7 +95,7 @@ export const generateLodestarBeaconNode: BeaconNodeGenerator<BeaconClient.Lodest
},
health: async () => {
try {
await got.get(`http://${address}:${ports.beacon.httpPort}/eth/v1/node/health`);
await fetch(`http://${address}:${ports.beacon.httpPort}/eth/v1/node/health`);
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
return {ok: true};
} catch (err) {
return {ok: false, reason: (err as Error).message, checkId: "eth/v1/node/health query"};
Expand Down
14 changes: 12 additions & 2 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,7 +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}});
await fetch(ethRpcPublicUrl, {
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "net_version",
params: [],
id: 67
})
});
return {ok: true};
} 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,7 +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}});
await fetch(ethRpcPublicUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "net_version",
params: [],
id: 67
})
});
return {ok: true};
} 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,10 @@ export const generateLighthouseValidatorNode: ValidatorNodeGenerator<ValidatorCl
},
health: async () => {
try {
await got.get(`http://127.0.0.1:${ports.validator.keymanagerPort}/lighthouse/health`);
await fetch(`http://127.0.0.1:${ports.validator.keymanagerPort}/lighthouse/health`);
return {ok: true};
} catch (err) {
if (err instanceof RequestError) {
if (err instanceof Error && !err.message.includes('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,7 +69,7 @@ export const generateLodestarValidatorNode: ValidatorNodeGenerator<ValidatorClie
},
health: async () => {
try {
await got.get(`http://127.0.0.1:${ports.validator.keymanagerPort}/eth/v1/keystores`);
await fetch(`http://127.0.0.1:${ports.validator.keymanagerPort}/eth/v1/keystores`);
return {ok: true};
} catch (err) {
return {ok: false, reason: (err as Error).message, checkId: "eth/v1/keystores query"};
Expand Down
14 changes: 7 additions & 7 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,13 @@ 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) => {
e.message = `Error downloading ${fileUrl}: ${e.message}`;
throw e;
});
return res.body;
try {
HiroyukiNaito marked this conversation as resolved.
Show resolved Hide resolved
const res = await fetch(fileUrl);
const buffer = Buffer.from(await res.arrayBuffer());
return buffer
} catch (e) {
throw `Error downloading ${fileUrl}: ${e}`;
}
}

async function tryEach<T>(promises: (() => Promise<T>)[]): Promise<T> {
Expand Down