Skip to content

Commit

Permalink
Merge cb36a54 into 3e1f9b2
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Apr 4, 2022
2 parents 3e1f9b2 + cb36a54 commit fc245ba
Show file tree
Hide file tree
Showing 411 changed files with 4,791 additions and 6,460 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"lint": "lerna run lint --no-bail",
"check-types": "lerna run check-types --no-bail",
"coverage": "lerna run coverage --no-bail",
"test:unit": "lerna run test:unit --no-bail",
"test:e2e": "lerna run test:e2e --no-bail",
"test:unit": "lerna run test:unit --no-bail --concurrency 1",
"test:e2e": "lerna run test:e2e --no-bail --concurrency 1",
"test:e2e:sim": "lerna run test:e2e:sim --no-bail",
"test:spec-min": "lerna run test:spec-min --no-bail",
"test:spec-fast": "lerna run test:spec-fast --no-bail",
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"@chainsafe/lodestar-params": "^0.36.0",
"@chainsafe/lodestar-types": "^0.36.0",
"@chainsafe/lodestar-utils": "^0.36.0",
"@chainsafe/persistent-merkle-tree": "^0.3.7",
"@chainsafe/ssz": "^0.8.20",
"@chainsafe/persistent-merkle-tree": "^0.4.0",
"@chainsafe/ssz": "^0.9.0",
"cross-fetch": "^3.1.4",
"eventsource": "^1.1.0",
"qs": "^6.10.1"
Expand Down
6 changes: 2 additions & 4 deletions packages/api/src/client/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Json} from "@chainsafe/ssz";
import {mapValues} from "@chainsafe/lodestar-utils";
import {FetchOpts, IHttpClient} from "./httpClient";
import {compileRouteUrlFormater} from "../../utils/urlFormat";
Expand All @@ -8,7 +7,6 @@ import {
RouteGeneric,
ReturnTypes,
TypeJson,
jsonOpts,
ReqSerializer,
ReqSerializers,
RoutesData,
Expand Down Expand Up @@ -69,10 +67,10 @@ export function generateGenericJsonClient<
const returnType = returnTypes[routeKey as keyof ReturnTypes<Api>] as TypeJson<any> | null;

return async function request(...args: Parameters<Api[keyof Api]>): Promise<any | void> {
const res = await fetchFn.json<Json>(fetchOptsSerializer(...args));
const res = await fetchFn.json<unknown>(fetchOptsSerializer(...args));
if (returnType) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return returnType.fromJson(res, jsonOpts) as ReturnType<Api[keyof Api]>;
return returnType.fromJson(res) as ReturnType<Api[keyof Api]>;
}
};
}) as Api;
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/keymanager/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
/* eslint-disable @typescript-eslint/naming-convention */
export function getReturnTypes(): ReturnTypes<Api> {
return {
listKeys: jsonType(),
importKeystores: jsonType(),
deleteKeystores: jsonType(),
listKeys: jsonType("camel"),
importKeystores: jsonType("camel"),
deleteKeystores: jsonType("camel"),
};
}
26 changes: 11 additions & 15 deletions packages/api/src/routes/beacon/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ContainerType, Json} from "@chainsafe/ssz";
import {ContainerType} from "@chainsafe/ssz";
import {ForkName} from "@chainsafe/lodestar-params";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {phase0, allForks, Slot, Root, ssz} from "@chainsafe/lodestar-types";
Expand Down Expand Up @@ -114,7 +114,7 @@ export type ReqTypes = {
getBlockHeader: BlockIdOnlyReq;
getBlockHeaders: {query: {slot?: number; parent_root?: string}};
getBlockRoot: BlockIdOnlyReq;
publishBlock: {body: Json};
publishBlock: {body: unknown};
};

export function getReqSerializers(config: IChainForkConfig): ReqSerializers<Api, ReqTypes> {
Expand All @@ -124,13 +124,13 @@ export function getReqSerializers(config: IChainForkConfig): ReqSerializers<Api,
schema: {params: {blockId: Schema.StringRequired}},
};

// Compute block type from JSON payload. See https://github.com/ethereum/beacon-APIs/pull/142
const getSignedBeaconBlockType = (data: allForks.SignedBeaconBlock): ContainerType<allForks.SignedBeaconBlock> =>
// Compute block type from JSON payload. See https://github.com/ethereum/eth2.0-APIs/pull/142
const getSignedBeaconBlockType = (data: allForks.SignedBeaconBlock): allForks.AllForksSSZTypes["SignedBeaconBlock"] =>
config.getForkTypes(data.message.slot).SignedBeaconBlock;

const AllForksSignedBeaconBlock: TypeJson<allForks.SignedBeaconBlock> = {
toJson: (data, opts) => getSignedBeaconBlockType(data).toJson(data, opts),
fromJson: (data, opts) =>
getSignedBeaconBlockType((data as unknown) as allForks.SignedBeaconBlock).fromJson(data, opts),
toJson: (data) => getSignedBeaconBlockType(data).toJson(data),
fromJson: (data) => getSignedBeaconBlockType((data as unknown) as allForks.SignedBeaconBlock).fromJson(data),
};

return {
Expand All @@ -149,14 +149,10 @@ export function getReqSerializers(config: IChainForkConfig): ReqSerializers<Api,
}

export function getReturnTypes(): ReturnTypes<Api> {
const BeaconHeaderResType = new ContainerType<BlockHeaderResponse>({
fields: {
root: ssz.Root,
canonical: ssz.Boolean,
header: ssz.phase0.SignedBeaconBlockHeader,
},
//from beacon apis
expectedCase: "notransform",
const BeaconHeaderResType = new ContainerType({
root: ssz.Root,
canonical: ssz.Boolean,
header: ssz.phase0.SignedBeaconBlockHeader,
});

return {
Expand Down
11 changes: 5 additions & 6 deletions packages/api/src/routes/beacon/pool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {phase0, altair, CommitteeIndex, Slot, ssz} from "@chainsafe/lodestar-types";
import {Json} from "@chainsafe/ssz";
import {
RoutesData,
ReturnTypes,
Expand Down Expand Up @@ -122,11 +121,11 @@ export type ReqTypes = {
getPoolAttesterSlashings: ReqEmpty;
getPoolProposerSlashings: ReqEmpty;
getPoolVoluntaryExits: ReqEmpty;
submitPoolAttestations: {body: Json};
submitPoolAttesterSlashing: {body: Json};
submitPoolProposerSlashing: {body: Json};
submitPoolVoluntaryExit: {body: Json};
submitPoolSyncCommitteeSignatures: {body: Json};
submitPoolAttestations: {body: unknown};
submitPoolAttesterSlashing: {body: unknown};
submitPoolProposerSlashing: {body: unknown};
submitPoolVoluntaryExit: {body: unknown};
submitPoolSyncCommitteeSignatures: {body: unknown};
};

export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
Expand Down
49 changes: 22 additions & 27 deletions packages/api/src/routes/beacon/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,54 +217,49 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {

/* eslint-disable @typescript-eslint/naming-convention */
export function getReturnTypes(): ReturnTypes<Api> {
const FinalityCheckpoints = new ContainerType<FinalityCheckpoints>({
fields: {
const FinalityCheckpoints = new ContainerType(
{
previousJustified: ssz.phase0.Checkpoint,
currentJustified: ssz.phase0.Checkpoint,
finalized: ssz.phase0.Checkpoint,
},
// From beacon apis
casingMap: {
previousJustified: "previous_justified",
currentJustified: "current_justified",
finalized: "finalized",
},
});
{jsonCase: "eth2"}
);

const ValidatorResponse = new ContainerType<ValidatorResponse>({
fields: {
const ValidatorResponse = new ContainerType(
{
index: ssz.ValidatorIndex,
balance: ssz.Number64,
balance: ssz.UintNum64,
status: new StringType<ValidatorStatus>(),
validator: ssz.phase0.Validator,
},
// From beacon apis
expectedCase: "notransform",
});
{jsonCase: "eth2"}
);

const ValidatorBalance = new ContainerType<ValidatorBalance>({
fields: {
const ValidatorBalance = new ContainerType(
{
index: ssz.ValidatorIndex,
balance: ssz.Number64,
balance: ssz.UintNum64,
},
// From beacon apis
expectedCase: "notransform",
});
{jsonCase: "eth2"}
);

const EpochCommitteeResponse = new ContainerType<EpochCommitteeResponse>({
fields: {
const EpochCommitteeResponse = new ContainerType(
{
index: ssz.CommitteeIndex,
slot: ssz.Slot,
validators: ssz.phase0.CommitteeIndices,
},
});
{jsonCase: "eth2"}
);

const EpochSyncCommitteesResponse = new ContainerType<EpochSyncCommitteeResponse>({
fields: {
const EpochSyncCommitteesResponse = new ContainerType(
{
validators: ArrayOf(ssz.ValidatorIndex),
validatorAggregates: ArrayOf(ssz.ValidatorIndex),
},
});
{jsonCase: "eth2"}
);

return {
getStateRoot: ContainerData(ssz.Root),
Expand Down
20 changes: 8 additions & 12 deletions packages/api/src/routes/config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {BeaconPreset} from "@chainsafe/lodestar-params";
import {IChainConfig} from "@chainsafe/lodestar-config";
import {Bytes32, Number64, phase0, ssz} from "@chainsafe/lodestar-types";
import {Bytes32, UintNum64, phase0, ssz} from "@chainsafe/lodestar-types";
import {mapValues} from "@chainsafe/lodestar-utils";
import {ByteVectorType, ContainerType} from "@chainsafe/ssz";
import {ArrayOf, ContainerData, ReqEmpty, reqEmpty, ReturnTypes, ReqSerializers, RoutesData, sameType} from "../utils";

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

export type DepositContract = {
chainId: Number64;
chainId: UintNum64;
address: Bytes32;
};

Expand Down Expand Up @@ -57,17 +57,13 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {

/* eslint-disable @typescript-eslint/naming-convention */
export function getReturnTypes(): ReturnTypes<Api> {
const DepositContract = new ContainerType<DepositContract>({
fields: {
chainId: ssz.Number64,
address: new ByteVectorType({length: 20}),
const DepositContract = new ContainerType(
{
chainId: ssz.UintNum64,
address: new ByteVectorType(20),
},
// From beacon apis
casingMap: {
chainId: "chain_id",
address: "address",
},
});
{jsonCase: "eth2"}
);

return {
getDepositContract: ContainerData(DepositContract),
Expand Down
9 changes: 4 additions & 5 deletions packages/api/src/routes/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
/* eslint-disable @typescript-eslint/naming-convention */
export function getReturnTypes(): ReturnTypes<Api> {
const stringType = new StringType();
const SlotRoot = new ContainerType<SlotRoot>({
fields: {
const SlotRoot = new ContainerType(
{
slot: ssz.Slot,
root: stringType,
},
// From beacon apis
expectedCase: "notransform",
});
{jsonCase: "eth2"}
);

return {
getHeads: ContainerData(ArrayOf(SlotRoot)),
Expand Down
Loading

0 comments on commit fc245ba

Please sign in to comment.