Skip to content
  •  
  •  
  •  
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ module.exports = {
"prettier/prettier": "error",
//doesnt work, it reports false errors
"constructor-super": "off",
"import/order" : [
"error",
{ "groups":
[
"builtin",
"external",
"internal",
"sibling",
"parent",
"index",
],
}
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/naming-convention": [
"error",
Expand Down Expand Up @@ -151,6 +164,7 @@ module.exports = {
"no-only-tests/no-only-tests": "error",
},
settings: {
"import/internal-regex": "^@chainsafe/",
"import/core-modules": [
"node:child_process",
"node:crypto",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EventSource from "eventsource";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {Api, BeaconEvent, routesData, getEventSerdes} from "../routes/events";
import {stringifyQuery} from "./utils/format";
import {Api, BeaconEvent, routesData, getEventSerdes} from "../routes/events";

/**
* REST HTTP client for events routes
Expand Down
8 changes: 3 additions & 5 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {Api} from "../interface";
import {IHttpClient, HttpClient, HttpClientOptions, HttpError} from "./utils";
export {HttpClient, HttpClientOptions, HttpError};

import * as beacon from "./beacon";
import * as configApi from "./config";
import * as debug from "./debug";
Expand All @@ -11,7 +7,9 @@ import * as lightclient from "./lightclient";
import * as lodestar from "./lodestar";
import * as node from "./node";
import * as validator from "./validator";

import {IHttpClient, HttpClient, HttpClientOptions, HttpError} from "./utils";
import {Api} from "../interface";
export {HttpClient, HttpClientOptions, HttpError};
/**
* REST HTTP client for all routes
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/utils/httpClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {fetch} from "cross-fetch";
import {AbortSignal, AbortController} from "@chainsafe/abort-controller";
import {ErrorAborted, TimeoutError} from "@chainsafe/lodestar-utils";
import {ReqGeneric, RouteDef} from "../../utils";
import {stringifyQuery, urlJoin} from "./format";
import {ReqGeneric, RouteDef} from "../../utils";

export class HttpError extends Error {
status: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/keymanager/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IHttpClient, generateGenericJsonClient} from "../client/utils";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "./routes";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "./routes";
import {IHttpClient, generateGenericJsonClient} from "../client/utils";

export function getClient(_config: IChainForkConfig, httpClient: IHttpClient): Api {
const reqSerializers = getReqSerializers();
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/keymanager/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {HttpClient, HttpClientOptions} from "../client";
import {IHttpClient} from "../client/utils";
import {Api} from "./routes";
import * as keymanager from "./client";
import {HttpClient, HttpClientOptions} from "../client";
import {IHttpClient} from "../client/utils";

export {ImportStatus, DeletionStatus, KeystoreStr, SlashingProtectionData, PubkeyHex, Api} from "./routes";

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/keymanager/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoutes, getGenericJsonServer} from "../server/utils";
import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "./routes";
import {ServerRoutes, getGenericJsonServer} from "../server/utils";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
// All routes return JSON, use a server auto-generator
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/beacon/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {phase0, ssz} from "@chainsafe/lodestar-types";
import {RoutesData, ReturnTypes, reqEmpty, ContainerData} from "../../utils";
import * as block from "./block";
import * as pool from "./pool";
import * as state from "./state";
import {RoutesData, ReturnTypes, reqEmpty, ContainerData} from "../../utils";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we actually want the closest modules at the bottom, so the correct order would be the original one. @dadepo can you try to tweak the rule to achieve that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!


// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/lightclient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ContainerType, JsonPath, VectorCompositeType} from "@chainsafe/ssz";
import {Proof} from "@chainsafe/persistent-merkle-tree";
import {altair, phase0, ssz, SyncPeriod} from "@chainsafe/lodestar-types";
import {LightclientHeaderUpdate} from "./events";
import {
ArrayOf,
ReturnTypes,
Expand All @@ -13,7 +14,6 @@ import {
ReqEmpty,
} from "../utils";
import {queryParseProofPathsArr, querySerializeProofPathsArr} from "../utils/serdes";
import {LightclientHeaderUpdate} from "./events";

// Re-export for convenience when importing routes.lightclient.LightclientHeaderUpdate
export {LightclientHeaderUpdate};
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/lodestar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Epoch, RootHex, Slot} from "@chainsafe/lodestar-types";
import {jsonType, ReqEmpty, reqEmpty, ReturnTypes, ReqSerializers, RoutesData, sameType, Schema} from "../utils";
import {FilterGetPeers, NodePeer, PeerDirection, PeerState} from "./node";
import {jsonType, ReqEmpty, reqEmpty, ReturnTypes, ReqSerializers, RoutesData, sameType, Schema} from "../utils";

// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
// eslint-disable-next-line import/no-extraneous-dependencies
import {FastifyInstance} from "fastify";
import {Api} from "../interface";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoute} from "./utils";

import * as beacon from "./beacon";
Expand All @@ -12,6 +11,7 @@ import * as lightclient from "./lightclient";
import * as lodestar from "./lodestar";
import * as node from "./node";
import * as validator from "./validator";
import {Api} from "../interface";

export type RouteConfig = {
operationId: ServerRoute["id"];
Expand Down
5 changes: 3 additions & 2 deletions packages/api/src/server/utils/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {mapValues} from "@chainsafe/lodestar-utils";
// eslint-disable-next-line import/no-extraneous-dependencies
import * as fastify from "fastify";
import {mapValues} from "@chainsafe/lodestar-utils";
// eslint-disable-next-line import/no-extraneous-dependencies
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ReqGeneric, RouteGeneric, ReturnTypes, TypeJson, Resolves, RouteGroupDefinition} from "../../utils/types";
import {getFastifySchema} from "../../utils/schema";
import {IChainForkConfig} from "@chainsafe/lodestar-config";

// See /packages/api/src/routes/index.ts for reasoning

Expand Down
6 changes: 3 additions & 3 deletions packages/api/test/unit/client/httpClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {ErrorAborted, TimeoutError} from "@chainsafe/lodestar-utils";
import {AbortController} from "@chainsafe/abort-controller";
import {IncomingMessage} from "node:http";
import chai, {expect} from "chai";
import chaiAsPromised from "chai-as-promised";
import fastify, {RouteOptions} from "fastify";
import {IncomingMessage} from "node:http";
import {ErrorAborted, TimeoutError} from "@chainsafe/lodestar-utils";
import {AbortController} from "@chainsafe/abort-controller";
import {HttpClient, HttpError} from "../../../src/client/utils";

chai.use(chaiAsPromised);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect} from "chai";
import {ssz} from "@chainsafe/lodestar-types";
import {chainConfigToJson} from "@chainsafe/lodestar-config";
import {config, chainConfig} from "@chainsafe/lodestar-config/default";
Expand All @@ -6,7 +7,6 @@ import {Api, ReqTypes, getReturnTypes} from "../../src/routes/config";
import {getClient} from "../../src/client/config";
import {getRoutes} from "../../src/server/config";
import {runGenericServerTest} from "../utils/genericServerTest";
import {expect} from "chai";

/* eslint-disable @typescript-eslint/naming-convention */

Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/debug.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect} from "chai";
import {ForkName} from "@chainsafe/lodestar-params";
import {ssz} from "@chainsafe/lodestar-types";
import {toHexString} from "@chainsafe/ssz";
Expand All @@ -8,7 +9,6 @@ import {getRoutes} from "../../src/server/debug";
import {runGenericServerTest} from "../utils/genericServerTest";
import {getMockApi, getTestServer} from "../utils/utils";
import {registerRoutesGroup} from "../../src/server";
import {expect} from "chai";
import {HttpClient} from "../../src";

describe("debug", function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect} from "chai";
import {AbortController} from "@chainsafe/abort-controller";
import {sleep} from "@chainsafe/lodestar-utils";
import {config} from "@chainsafe/lodestar-config/default";
Expand All @@ -6,7 +7,6 @@ import {getClient} from "../../src/client/events";
import {getRoutes} from "../../src/server/events";
import {getMockApi, getTestServer} from "../utils/utils";
import {registerRoutesGroup} from "../../src/server";
import {expect} from "chai";

describe("events", () => {
const rootHex = "0x" + "01".repeat(32);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/lightclient.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {ssz} from "@chainsafe/lodestar-types";
import {config} from "@chainsafe/lodestar-config/default";
import {ProofType} from "@chainsafe/persistent-merkle-tree";
import {toHexString} from "@chainsafe/ssz";
import {Api, ReqTypes} from "../../src/routes/lightclient";
import {getClient} from "../../src/client/lightclient";
import {getRoutes} from "../../src/server/lightclient";
import {runGenericServerTest} from "../utils/genericServerTest";
import {toHexString} from "@chainsafe/ssz";

const root = Uint8Array.from(Buffer.alloc(32, 1));

Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/utils/genericServerTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {expect} from "chai";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {getMockApi, getTestServer} from "./utils";
import {RouteGeneric, ReqGeneric, Resolves} from "../../src/utils";
import {FetchOpts, HttpClient, IHttpClient} from "../../src/client/utils";
import {ServerRoutes} from "../../src/server/utils";
import {getMockApi, getTestServer} from "./utils";
import {registerRoutesGroup} from "../../src/server";

type IgnoreVoid<T> = T extends void ? undefined : T;
Expand Down
4 changes: 2 additions & 2 deletions packages/api/test/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fastify, {FastifyInstance} from "fastify";
import querystring from "querystring";
import {mapValues} from "@chainsafe/lodestar-utils";
import fastify, {FastifyInstance} from "fastify";
import Sinon from "sinon";
import {mapValues} from "@chainsafe/lodestar-utils";

export function getTestServer(): {baseUrl: string; server: FastifyInstance} {
const port = Math.floor(Math.random() * (65535 - 49152)) + 49152;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {phase0} from "@chainsafe/lodestar-types";
import {ForkName} from "@chainsafe/lodestar-params";

import {isSlashableValidator, isSlashableAttestationData, getAttesterSlashableIndices} from "../../util";
import {CachedBeaconStateAllForks} from "../../types";
import {isValidIndexedAttestation} from "./isValidIndexedAttestation";
import {slashValidatorAllForks} from "./slashValidator";
import {isSlashableValidator, isSlashableAttestationData, getAttesterSlashableIndices} from "../../util";
import {CachedBeaconStateAllForks} from "../../types";

/**
* Process an AttesterSlashing operation. Initiates the exit of a validator, decreases the balance of the slashed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import xor from "buffer-xor";
import {digest} from "@chainsafe/as-sha256";
import {allForks} from "@chainsafe/lodestar-types";
import {EPOCHS_PER_HISTORICAL_VECTOR} from "@chainsafe/lodestar-params";
import {getRandaoMix} from "../../util";
import {verifyRandaoSignature} from "../signatureSets";
import {CachedBeaconStateAllForks} from "../../types";
import {EPOCHS_PER_HISTORICAL_VECTOR} from "@chainsafe/lodestar-params";

/**
* Commit a randao reveal to generate pseudorandomness seeds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
WHISTLEBLOWER_REWARD_QUOTIENT,
} from "@chainsafe/lodestar-params";

import {initiateValidatorExit} from "./initiateValidatorExit";
import {decreaseBalance, increaseBalance} from "../../util";
import {CachedBeaconStateAllForks} from "../../types";
import {initiateValidatorExit} from "./initiateValidatorExit";

export function slashValidatorAllForks(
fork: ForkName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {allForks, phase0} from "@chainsafe/lodestar-types";
import {getIndexedAttestationSignatureSet} from "./indexedAttestation";
import {ISignatureSet} from "../../util";
import {CachedBeaconStateAllForks} from "../../types";
import {getIndexedAttestationSignatureSet} from "./indexedAttestation";

/** Get signature sets from a single AttesterSlashing object */
export function getAttesterSlashingSignatureSets(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {allForks, altair} from "@chainsafe/lodestar-types";
import {computeEpochAtSlot, ISignatureSet} from "../../util";
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../../types";
import {getProposerSlashingsSignatureSets} from "./proposerSlashings";
import {getAttesterSlashingsSignatureSets} from "./attesterSlashings";
import {getAttestationsSignatureSets} from "./indexedAttestation";
import {getProposerSignatureSet} from "./proposer";
import {getRandaoRevealSignatureSet} from "./randao";
import {getVoluntaryExitsSignatureSets} from "./voluntaryExits";
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../../types";
import {computeEpochAtSlot, ISignatureSet} from "../../util";
import {getSyncCommitteeSignatureSet} from "../../altair/block/processSyncCommittee";

export * from "./attesterSlashings";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import {allForks, Slot, ssz} from "@chainsafe/lodestar-types";
import {ForkName, SLOTS_PER_EPOCH} from "@chainsafe/lodestar-params";
import {toHexString} from "@chainsafe/ssz";
import {verifyProposerSignature} from "./signatureSets";
import {processSlot} from "./slot";
import * as phase0 from "../phase0";
import * as altair from "../altair";
import * as bellatrix from "../bellatrix";
import {IBeaconStateTransitionMetrics} from "../metrics";
import {EpochProcess, beforeProcessEpoch} from "../cache/epochProcess";
import {verifyProposerSignature} from "./signatureSets";
import {CachedBeaconStateAllForks, CachedBeaconStatePhase0, CachedBeaconStateAltair} from "../types";
import {processSlot} from "./slot";
import {computeEpochAtSlot} from "../util";

type StateAllForks = CachedBeaconStateAllForks;
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-state-transition/src/altair/block/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {altair} from "@chainsafe/lodestar-types";

import {CachedBeaconStateAltair} from "../../types";
import {processBlockHeader, processEth1Data, processRandao} from "../../allForks/block";
import {processOperations} from "./processOperations";
import {processAttestations, RootCache} from "./processAttestation";
import {processAttesterSlashing} from "./processAttesterSlashing";
import {processDeposit} from "./processDeposit";
import {processProposerSlashing} from "./processProposerSlashing";
import {processVoluntaryExit} from "./processVoluntaryExit";
import {processSyncAggregate} from "./processSyncCommittee";
import {processBlockHeader, processEth1Data, processRandao} from "../../allForks/block";
import {CachedBeaconStateAltair} from "../../types";

export {
processOperations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {Epoch, phase0, Root, Slot} from "@chainsafe/lodestar-types";
import {byteArrayEquals} from "@chainsafe/ssz";
import {intSqrt} from "@chainsafe/lodestar-utils";

import {getBlockRoot, getBlockRootAtSlot, increaseBalance, verifySignatureSet} from "../../util";
import {CachedBeaconStateAltair, CachedBeaconStateAllForks} from "../../types";
import {
MIN_ATTESTATION_INCLUSION_DELAY,
PROPOSER_WEIGHT,
Expand All @@ -16,6 +14,8 @@ import {
TIMELY_TARGET_WEIGHT,
WEIGHT_DENOMINATOR,
} from "@chainsafe/lodestar-params";
import {getBlockRoot, getBlockRootAtSlot, increaseBalance, verifySignatureSet} from "../../util";
import {CachedBeaconStateAltair, CachedBeaconStateAllForks} from "../../types";
import {checkpointToStr, validateAttestation} from "../../phase0/block/processAttestation";
import {getAttestationWithIndicesSignatureSet} from "../../allForks";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {altair} from "@chainsafe/lodestar-types";

import {CachedBeaconStateAltair} from "../../types";
import {MAX_DEPOSITS} from "@chainsafe/lodestar-params";
import {processProposerSlashing} from "./processProposerSlashing";
import {processAttesterSlashing} from "./processAttesterSlashing";
import {processAttestations} from "./processAttestation";
import {processDeposit} from "./processDeposit";
import {processVoluntaryExit} from "./processVoluntaryExit";
import {MAX_DEPOSITS} from "@chainsafe/lodestar-params";
import {CachedBeaconStateAltair} from "../../types";

export function processOperations(
state: CachedBeaconStateAltair,
Expand Down
12 changes: 6 additions & 6 deletions packages/beacon-state-transition/src/altair/epoch/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {CachedBeaconStateAltair, EpochProcess} from "../../types";
import {processRewardsAndPenalties} from "./processRewardsAndPenalties";
import {processSlashings} from "./processSlashings";
import {processParticipationFlagUpdates} from "./processParticipationFlagUpdates";
import {processInactivityUpdates} from "./processInactivityUpdates";
import {processSyncCommitteeUpdates} from "./processSyncCommitteeUpdates";
import {
processJustificationAndFinalization,
processRegistryUpdates,
Expand All @@ -8,11 +12,7 @@ import {
processRandaoMixesReset,
processHistoricalRootsUpdate,
} from "../../allForks/epoch";
import {processRewardsAndPenalties} from "./processRewardsAndPenalties";
import {processSlashings} from "./processSlashings";
import {processParticipationFlagUpdates} from "./processParticipationFlagUpdates";
import {processInactivityUpdates} from "./processInactivityUpdates";
import {processSyncCommitteeUpdates} from "./processSyncCommitteeUpdates";
import {CachedBeaconStateAltair, EpochProcess} from "../../types";

// For spec tests
export {getRewardsAndPenalties} from "./getRewardsAndPenalties";
Expand Down
Loading