Skip to content

Commit

Permalink
Added fetch from "@lodestar/api";
Browse files Browse the repository at this point in the history
  • Loading branch information
HiroyukiNaito committed Mar 1, 2024
1 parent e063c9e commit 83c6e94
Show file tree
Hide file tree
Showing 26 changed files with 69 additions and 60 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/builder/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export function getReturnTypes(): ReturnTypes<Api> {
isForkBlobs(fork)
? ssz.allForksBlobs[fork].ExecutionPayloadAndBlobsBundle
: isForkExecution(fork)
? ssz.allForksExecution[fork].ExecutionPayload
: ssz.bellatrix.ExecutionPayload
? ssz.allForksExecution[fork].ExecutionPayload
: ssz.bellatrix.ExecutionPayload
),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ export async function produceBlockBody<T extends BlockType>(
const feeRecipientType = requestedFeeRecipient
? "requested"
: this.beaconProposerCache.get(proposerIndex)
? "cached"
: "default";
? "cached"
: "default";

Object.assign(logMeta, {feeRecipientType, feeRecipient});

Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/db/repositories/blockArchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ export class BlockArchiveRepository extends Repository<Slot, allForks.SignedBeac
const firstSlot = dbFilterOpts.gt
? this.decodeKey(dbFilterOpts.gt) + 1
: dbFilterOpts.gte
? this.decodeKey(dbFilterOpts.gte)
: null;
? this.decodeKey(dbFilterOpts.gte)
: null;
if (firstSlot === null) throw Error("specify opts.gt or opts.gte");

return firstSlot;
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/eth1/provider/jsonRpcHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ export class ErrorJsonRpcResponse extends Error {
? typeof res.error.message === "string"
? res.error.message
: typeof res.error.code === "number"
? parseJsonRpcErrorCode(res.error.code)
: JSON.stringify(res.error)
? parseJsonRpcErrorCode(res.error.code)
: JSON.stringify(res.error)
: String(res.error);

super(`JSON RPC error: ${errorMessage}, ${payloadMethod}`);
Expand Down
12 changes: 6 additions & 6 deletions packages/beacon-node/src/execution/engine/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ export class ExecutionEngineHttp implements IExecutionEngine {
ForkSeq[fork] >= ForkSeq.deneb
? "engine_newPayloadV3"
: ForkSeq[fork] >= ForkSeq.capella
? "engine_newPayloadV2"
: "engine_newPayloadV1";
? "engine_newPayloadV2"
: "engine_newPayloadV1";

const serializedExecutionPayload = serializeExecutionPayload(fork, executionPayload);

Expand Down Expand Up @@ -299,8 +299,8 @@ export class ExecutionEngineHttp implements IExecutionEngine {
ForkSeq[fork] >= ForkSeq.deneb
? "engine_forkchoiceUpdatedV3"
: ForkSeq[fork] >= ForkSeq.capella
? "engine_forkchoiceUpdatedV2"
: "engine_forkchoiceUpdatedV1";
? "engine_forkchoiceUpdatedV2"
: "engine_forkchoiceUpdatedV1";
const payloadAttributesRpc = payloadAttributes ? serializePayloadAttributes(payloadAttributes) : undefined;
// If we are just fcUing and not asking execution for payload, retry is not required
// and we can move on, as the next fcU will be issued soon on the new slot
Expand Down Expand Up @@ -373,8 +373,8 @@ export class ExecutionEngineHttp implements IExecutionEngine {
ForkSeq[fork] >= ForkSeq.deneb
? "engine_getPayloadV3"
: ForkSeq[fork] >= ForkSeq.capella
? "engine_getPayloadV2"
: "engine_getPayloadV1";
? "engine_getPayloadV2"
: "engine_getPayloadV1";
const payloadResponse = await this.rpc.fetchWithRetries<
EngineApiRpcReturnTypes[typeof method],
EngineApiRpcParamTypes[typeof method]
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/execution/engine/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export function getExecutionEngineState<S extends ExecutionPayloadStatus | undef
targetState !== undefined
? targetState
: payloadStatus === undefined
? getExecutionEngineStateForPayloadError(payloadError, oldState)
: getExecutionEngineStateForPayloadStatus(payloadStatus);
? getExecutionEngineStateForPayloadError(payloadError, oldState)
: getExecutionEngineStateForPayloadStatus(payloadStatus);

if (newState === oldState) return oldState;

Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/src/metrics/validatorMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ export function createValidatorMonitor(
? // altair, attestation is not missed
attestationMinBlockInclusionDistance
: summary.inclusionDistance
? // phase0, this is from the state transition
summary.inclusionDistance
: null;
? // phase0, this is from the state transition
summary.inclusionDistance
: null;

if (inclusionDistance !== null) {
metrics.validatorMonitor.prevEpochOnChainInclusionDistance.observe(inclusionDistance);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cmds/validator/keymanager/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ export class KeymanagerApi implements Api {
const status = deletedKey[i]
? DeletionStatus.deleted
: pubkeysWithSlashingProtectionData.has(pubkeysHex[i])
? DeletionStatus.not_active
: DeletionStatus.not_found;
? DeletionStatus.not_active
: DeletionStatus.not_found;
statuses[i] = {status};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/networks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import {ENR} from "@chainsafe/enr";
import {SLOTS_PER_EPOCH} from "@lodestar/params";
import {ApiError, getClient} from "@lodestar/api";
import {ApiError, getClient, fetch} from "@lodestar/api";
import {getStateTypeFromBytes} from "@lodestar/beacon-node";
import {ChainConfig, ChainForkConfig} from "@lodestar/config";
import {Checkpoint} from "@lodestar/types/phase0";
Expand Down Expand Up @@ -101,7 +101,7 @@ export function getGenesisFileUrl(network: NetworkName): string | null {
* Fetches the latest list of bootnodes for a network
* Bootnodes file is expected to contain bootnode ENR's concatenated by newlines
*/
export async function fetchBootnodes(network: NetworkName): Promise<string[]> {
async function fetchBootnodes(network: NetworkName): Promise<string[]> {
const bootnodesFileUrl = getNetworkData(network).bootnodesFileUrl;
if (bootnodesFileUrl === null) {
return [];
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/util/file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import yaml from "js-yaml";
import {fetch} from "@lodestar/api";
const {load, dump, FAILSAFE_SCHEMA, Type} = yaml;

import {mkdir} from "./fs.js";
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/src/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ export function parseLoggerArgs(
timestampFormat: opts?.hideTimestamp
? {format: TimestampFormatCode.Hidden}
: args.logFormatGenesisTime !== undefined
? {
format: TimestampFormatCode.EpochSlot,
genesisTime: args.logFormatGenesisTime,
secondsPerSlot: config.SECONDS_PER_SLOT,
slotsPerEpoch: SLOTS_PER_EPOCH,
}
: {
format: TimestampFormatCode.DateRegular,
},
? {
format: TimestampFormatCode.EpochSlot,
genesisTime: args.logFormatGenesisTime,
secondsPerSlot: config.SECONDS_PER_SLOT,
slotsPerEpoch: SLOTS_PER_EPOCH,
}
: {
format: TimestampFormatCode.DateRegular,
},
};
}

Expand Down
8 changes: 4 additions & 4 deletions packages/cli/test/utils/simulation/SimulationEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ export class SimulationEnvironment {
interopKeys.length > 0 && remote
? {type: "remote", secretKeys: interopKeys}
: interopKeys.length > 0
? {type: "local", secretKeys: interopKeys}
: {type: "no-keys"};
? {type: "local", secretKeys: interopKeys}
: {type: "no-keys"};

const commonOptions: GeneratorOptions = {
id,
Expand Down Expand Up @@ -287,8 +287,8 @@ export class SimulationEnvironment {
typeof validator === "object"
? validator.type
: validator === undefined
? getValidatorForBeaconNode(beaconType)
: validator;
? getValidatorForBeaconNode(beaconType)
: validator;
const validatorOptions = typeof validator === "object" ? validator.options : {};
const beaconUrls = [
// As lodestar is running on host machine, need to connect through docker named host
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/utils/simulation/TableReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export class TableReporter extends SimulationReporter<typeof defaultAssertions>
finalizedSlots.length === 0
? "---"
: isSingletonArray(finalizedSlots)
? finalizedSlots[0]
: finalizedSlots.join(","),
? finalizedSlots[0]
: finalizedSlots.join(","),
peers: peersCount.length === 0 ? "---" : isSingletonArray(peersCount) ? peersCount[0] : peersCount.join(","),
attCount: attestationCounts.length > 0 && isSingletonArray(attestationCounts) ? attestationCounts[0] : "---",
incDelay: inclusionDelays.length > 0 && isSingletonArray(inclusionDelays) ? inclusionDelays[0].toFixed(2) : "---",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {writeFile} from "node:fs/promises";
import path from "node:path";
import yaml from "js-yaml";
import {HttpClient} from "@lodestar/api";
import {HttpClient, fetch} from "@lodestar/api";
import {getClient} from "@lodestar/api/beacon";
import {chainConfigToJson} from "@lodestar/config";
import {BeaconClient, BeaconNodeGenerator, LighthouseAPI, RunnerType} from "../interfaces.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from "node:path";
import {getClient} from "@lodestar/api/beacon";
import {chainConfigToJson} from "@lodestar/config";
import {LogLevel} from "@lodestar/utils";
import {fetch} from "@lodestar/api";
import {BeaconArgs} from "../../../../src/cmds/beacon/options.js";
import {GlobalArgs} from "../../../../src/options/globalOptions.js";
import {LODESTAR_BINARY_PATH} from "../constants.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {writeFile} from "node:fs/promises";
import path from "node:path";
import {ZERO_HASH} from "@lodestar/state-transition";
import {fetch} from "@lodestar/api";
import {
EL_GENESIS_ACCOUNT,
EL_GENESIS_PASSWORD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {writeFile} from "node:fs/promises";
import path from "node:path";
import {ZERO_HASH} from "@lodestar/state-transition";
import {fetch} from "@lodestar/api";
import {Eth1ProviderWithAdmin} from "../Eth1ProviderWithAdmin.js";
import {ExecutionClient, ExecutionNodeGenerator, JobOptions, RunnerType} from "../interfaces.js";
import {getNethermindChainSpec} from "../utils/execution_genesis.js";
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/test/utils/simulation/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,11 @@ export enum AssertionMatch {
Remove = 1 << 2,
}
export type AssertionMatcher = (input: SimulationMatcherInput) => AssertionMatch;
export type ExtractAssertionType<T, I> =
T extends SimulationAssertion<infer A, infer B> ? (A extends I ? B : never) : never;
export type ExtractAssertionType<T, I> = T extends SimulationAssertion<infer A, infer B>
? A extends I
? B
: never
: never;
export type ExtractAssertionId<T> = T extends SimulationAssertion<infer A, any> ? A : never;
export type StoreType<AssertionId extends string, Value = unknown> = Record<
AssertionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {writeFile} from "node:fs/promises";
import yaml from "js-yaml";
import {getClient as keyManagerGetClient} from "@lodestar/api/keymanager";
import {chainConfigToJson} from "@lodestar/config";
import {fetch} from "@lodestar/api";
import {RunnerType, ValidatorClient, ValidatorNodeGenerator} from "../interfaces.js";
import {updateKeystoresPath} from "../utils/keys.js";
import {getNodeMountedPaths} from "../utils/paths.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {getClient as keyManagerGetClient} from "@lodestar/api/keymanager";
import {chainConfigToJson} from "@lodestar/config";
import {LogLevel} from "@lodestar/utils";
import {defaultOptions} from "@lodestar/validator";
import {fetch} from "@lodestar/api";
import {IValidatorCliArgs} from "../../../../src/cmds/validator/options.js";
import {GlobalArgs} from "../../../../src/options/globalOptions.js";
import {LODESTAR_BINARY_PATH} from "../constants.js";
Expand Down
12 changes: 6 additions & 6 deletions packages/config/src/chainConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ export type SpecValue = number | bigint | Uint8Array | string;
export type SpecValueType<V extends SpecValue> = V extends number
? "number"
: V extends bigint
? "bigint"
: V extends Uint8Array
? "bytes"
: V extends string
? "string"
: never;
? "bigint"
: V extends Uint8Array
? "bytes"
: V extends string
? "string"
: never;

/** All possible type names for a SpecValue */
export type SpecValueTypeName = SpecValueType<SpecValue>;
Expand Down
4 changes: 2 additions & 2 deletions packages/state-transition/src/block/slashValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export function slashValidator(
fork === ForkSeq.phase0
? MIN_SLASHING_PENALTY_QUOTIENT
: fork === ForkSeq.altair
? MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR
: MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX;
? MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR
: MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX;
decreaseBalance(state, slashedIndex, Math.floor(effectiveBalance / minSlashingPenaltyQuotient));

// apply proposer and whistleblower rewards
Expand Down
4 changes: 2 additions & 2 deletions packages/state-transition/src/epoch/processSlashings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export function processSlashings(
fork === ForkSeq.phase0
? PROPORTIONAL_SLASHING_MULTIPLIER
: fork === ForkSeq.altair
? PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR
: PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX;
? PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR
: PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX;

const {effectiveBalanceIncrements} = state.epochCtx;
const adjustedTotalSlashingBalanceByIncrement = Math.min(
Expand Down
2 changes: 1 addition & 1 deletion packages/state-transition/test/utils/testFileCache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import {ApiError, getClient} from "@lodestar/api";
import {ApiError, getClient, fetch} from "@lodestar/api";
import {NetworkName, networksChainConfig} from "@lodestar/config/networks";
import {createChainForkConfig, ChainForkConfig} from "@lodestar/config";
import {allForks} from "@lodestar/types";
Expand Down
12 changes: 6 additions & 6 deletions packages/utils/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export interface CliOptionDefinition<T = any> extends Options {
type: T extends string
? "string"
: T extends number
? "number"
: T extends boolean
? "boolean"
: T extends Array<unknown>
? "array"
: never;
? "number"
: T extends boolean
? "boolean"
: T extends Array<unknown>
? "array"
: never;
}

export type CliCommandOptions<OwnArgs> = Required<{
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends (infer U)[]
? RecursivePartial<U>[]
: T[P] extends Readonly<infer U>[]
? Readonly<RecursivePartial<U>>[]
: RecursivePartial<T[P]>;
? Readonly<RecursivePartial<U>>[]
: RecursivePartial<T[P]>;
};

/** Type safe wrapper for Number constructor that takes 'any' */
Expand Down

0 comments on commit 83c6e94

Please sign in to comment.