Skip to content

Commit

Permalink
Release v1.5.0 (#5212)
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain authored Feb 27, 2023
2 parents 941a1cf + 025b116 commit 77d3ce6
Show file tree
Hide file tree
Showing 263 changed files with 1,789 additions and 1,057 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-sim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
run: yarn test:sim:endpoints
working-directory: packages/cli

- name: Sim tests eip4844
run: yarn test:sim:eip4844
- name: Sim tests deneb
run: yarn test:sim:deneb
working-directory: packages/cli

- name: Sim tests backup eth provider
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "1.4.3",
"version": "1.5.0",
"stream": "true",
"command": {
"version": {
Expand Down
10 changes: 5 additions & 5 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"bugs": {
"url": "https://github.com/ChainSafe/lodestar/issues"
},
"version": "1.4.3",
"version": "1.5.0",
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -70,10 +70,10 @@
"dependencies": {
"@chainsafe/persistent-merkle-tree": "^0.4.2",
"@chainsafe/ssz": "^0.9.2",
"@lodestar/config": "^1.4.3",
"@lodestar/params": "^1.4.3",
"@lodestar/types": "^1.4.3",
"@lodestar/utils": "^1.4.3",
"@lodestar/config": "^1.5.0",
"@lodestar/params": "^1.5.0",
"@lodestar/types": "^1.5.0",
"@lodestar/utils": "^1.5.0",
"cross-fetch": "^3.1.4",
"eventsource": "^2.0.2",
"qs": "^6.10.1"
Expand Down
2 changes: 0 additions & 2 deletions packages/api/src/beacon/client/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export function getClient(_config: IChainForkConfig, httpClient: IHttpClient): A
timeoutMs: GET_STATE_TIMEOUT_MS,
});
// Casting to any otherwise Typescript doesn't like the multi-type return
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-explicit-any
return {
ok: true,
response: new Uint8Array(res.body),
Expand All @@ -58,7 +57,6 @@ export function getClient(_config: IChainForkConfig, httpClient: IHttpClient): A
timeoutMs: GET_STATE_TIMEOUT_MS,
});
// Casting to any otherwise Typescript doesn't like the multi-type return
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-explicit-any
return {ok: true, response: new Uint8Array(res.body), status: res.status} as ApiClientResponse<{
[HttpStatusCode.OK]: Uint8Array;
}>;
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/beacon/client/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {HttpStatusCode} from "../../utils/client/httpStatusCode.js";
/**
* REST HTTP client for events routes
*/
export function getClient(_config: IChainForkConfig, baseUrl: string): Api {
const eventSerdes = getEventSerdes();
export function getClient(config: IChainForkConfig, baseUrl: string): Api {
const eventSerdes = getEventSerdes(config);

return {
eventstream: async (topics, signal, onEvent) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/beacon/routes/beacon/block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ContainerType} from "@chainsafe/ssz";
import {ForkName} from "@lodestar/params";
import {IChainForkConfig} from "@lodestar/config";
import {phase0, allForks, Slot, Root, ssz, RootHex, eip4844} from "@lodestar/types";
import {phase0, allForks, Slot, Root, ssz, RootHex, deneb} from "@lodestar/types";

import {
RoutesData,
Expand Down Expand Up @@ -196,7 +196,7 @@ export type Api = {
blockId: BlockId
): Promise<
ApiClientResponse<{
[HttpStatusCode.OK]: {executionOptimistic: ExecutionOptimistic; data: eip4844.BlobsSidecar};
[HttpStatusCode.OK]: {executionOptimistic: ExecutionOptimistic; data: deneb.BlobsSidecar};
}>
>;
};
Expand Down Expand Up @@ -294,6 +294,6 @@ export function getReturnTypes(): ReturnTypes<Api> {
getBlockHeader: ContainerDataExecutionOptimistic(BeaconHeaderResType),
getBlockHeaders: ContainerDataExecutionOptimistic(ArrayOf(BeaconHeaderResType)),
getBlockRoot: ContainerDataExecutionOptimistic(RootContainer),
getBlobsSidecar: ContainerDataExecutionOptimistic(ssz.eip4844.BlobsSidecar),
getBlobsSidecar: ContainerDataExecutionOptimistic(ssz.deneb.BlobsSidecar),
};
}
2 changes: 1 addition & 1 deletion packages/api/src/beacon/routes/beacon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type ReqTypes = {
[K in keyof ReturnType<typeof getReqSerializers>]: ReturnType<ReturnType<typeof getReqSerializers>[K]["writeReq"]>;
};

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function getReqSerializers(config: IChainForkConfig) {
return {
getGenesis: reqEmpty,
Expand Down
77 changes: 48 additions & 29 deletions packages/api/src/beacon/routes/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Epoch, phase0, capella, Slot, ssz, StringType, RootHex, altair, UintNum64} from "@lodestar/types";
import {ContainerType, Type, VectorCompositeType} from "@chainsafe/ssz";
import {FINALIZED_ROOT_DEPTH} from "@lodestar/params";
import {Epoch, phase0, capella, Slot, ssz, StringType, RootHex, altair, UintNum64, allForks} from "@lodestar/types";
import {ContainerType} from "@chainsafe/ssz";
import {IChainForkConfig} from "@lodestar/config";

import {RouteDef, TypeJson} from "../../utils/index.js";
import {HttpStatusCode} from "../../utils/client/httpStatusCode.js";
import {ApiClientResponse} from "../../interfaces.js";
Expand Down Expand Up @@ -86,9 +87,9 @@ export type EventData = {
executionOptimistic: boolean;
};
[EventType.contributionAndProof]: altair.SignedContributionAndProof;
[EventType.lightClientOptimisticUpdate]: altair.LightClientOptimisticUpdate;
[EventType.lightClientFinalityUpdate]: altair.LightClientFinalityUpdate;
[EventType.lightClientUpdate]: altair.LightClientUpdate;
[EventType.lightClientOptimisticUpdate]: allForks.LightClientOptimisticUpdate;
[EventType.lightClientFinalityUpdate]: allForks.LightClientFinalityUpdate;
[EventType.lightClientUpdate]: allForks.LightClientUpdate;
};

export type BeaconEvent = {[K in EventType]: {type: K; message: EventData[K]}}[EventType];
Expand Down Expand Up @@ -123,8 +124,12 @@ export type ReqTypes = {
// It doesn't make sense to define a getReqSerializers() here given the exotic argument of eventstream()
// The request is very simple: (topics) => {query: {topics}}, and the test will ensure compatibility server - client

export function getTypeByEvent(): {[K in EventType]: Type<EventData[K]>} {
export function getTypeByEvent(config: IChainForkConfig): {[K in EventType]: TypeJson<EventData[K]>} {
const stringType = new StringType();
const getLightClientTypeFromHeader = (data: allForks.LightClientHeader): allForks.AllForksLightClientSSZTypes => {
return config.getLightClientForkTypes(data.beacon.slot);
};

return {
[EventType.head]: new ContainerType(
{
Expand Down Expand Up @@ -178,31 +183,45 @@ export function getTypeByEvent(): {[K in EventType]: Type<EventData[K]>} {

[EventType.contributionAndProof]: ssz.altair.SignedContributionAndProof,

[EventType.lightClientOptimisticUpdate]: new ContainerType(
{
syncAggregate: ssz.altair.SyncAggregate,
attestedHeader: ssz.altair.LightClientHeader,
signatureSlot: ssz.Slot,
},
{jsonCase: "eth2"}
),
[EventType.lightClientFinalityUpdate]: new ContainerType(
{
attestedHeader: ssz.altair.LightClientHeader,
finalizedHeader: ssz.altair.LightClientHeader,
finalityBranch: new VectorCompositeType(ssz.Bytes32, FINALIZED_ROOT_DEPTH),
syncAggregate: ssz.altair.SyncAggregate,
signatureSlot: ssz.Slot,
},
{jsonCase: "eth2"}
),
[EventType.lightClientUpdate]: ssz.altair.LightClientUpdate,
[EventType.lightClientOptimisticUpdate]: {
toJson: (data) =>
getLightClientTypeFromHeader(((data as unknown) as allForks.LightClientOptimisticUpdate).attestedHeader)[
"LightClientOptimisticUpdate"
].toJson(data),
fromJson: (data) =>
getLightClientTypeFromHeader(
// eslint-disable-next-line @typescript-eslint/naming-convention
((data as unknown) as {attested_header: allForks.LightClientHeader}).attested_header
)["LightClientOptimisticUpdate"].fromJson(data),
},
[EventType.lightClientFinalityUpdate]: {
toJson: (data) =>
getLightClientTypeFromHeader(((data as unknown) as allForks.LightClientFinalityUpdate).attestedHeader)[
"LightClientFinalityUpdate"
].toJson(data),
fromJson: (data) =>
getLightClientTypeFromHeader(
// eslint-disable-next-line @typescript-eslint/naming-convention
((data as unknown) as {attested_header: allForks.LightClientHeader}).attested_header
)["LightClientFinalityUpdate"].fromJson(data),
},
[EventType.lightClientUpdate]: {
toJson: (data) =>
getLightClientTypeFromHeader(((data as unknown) as allForks.LightClientUpdate).attestedHeader)[
"LightClientUpdate"
].toJson(data),
fromJson: (data) =>
getLightClientTypeFromHeader(
// eslint-disable-next-line @typescript-eslint/naming-convention
((data as unknown) as {attested_header: allForks.LightClientHeader}).attested_header
)["LightClientUpdate"].fromJson(data),
},
};
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export function getEventSerdes() {
const typeByEvent = getTypeByEvent();
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function getEventSerdes(config: IChainForkConfig) {
const typeByEvent = getTypeByEvent(config);

return {
toJson: (event: BeaconEvent): unknown => {
Expand Down
51 changes: 29 additions & 22 deletions packages/api/src/beacon/routes/lightclient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {altair, ssz, StringType, SyncPeriod} from "@lodestar/types";
import {ForkName} from "@lodestar/params";
import {ContainerType} from "@chainsafe/ssz";
import {ssz, SyncPeriod, allForks} from "@lodestar/types";
import {ForkName, isForkLightClient} from "@lodestar/params";
import {
ArrayOf,
ReturnTypes,
Expand All @@ -17,13 +16,6 @@ import {ApiClientResponse} from "../../interfaces.js";

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

export type LightClientBootstrap = {
header: altair.LightClientHeader;
currentSyncCommittee: altair.SyncCommittee;
/** Single branch proof from state root to currentSyncCommittee */
currentSyncCommitteeBranch: Uint8Array[];
};

export type Api = {
/**
* Returns an array of best updates given a `startPeriod` and `count` number of sync committee period to return.
Expand All @@ -39,7 +31,7 @@ export type Api = {
ApiClientResponse<{
[HttpStatusCode.OK]: {
version: ForkName;
data: altair.LightClientUpdate;
data: allForks.LightClientUpdate;
}[];
}>
>;
Expand All @@ -51,15 +43,15 @@ export type Api = {
ApiClientResponse<{
[HttpStatusCode.OK]: {
version: ForkName;
data: altair.LightClientOptimisticUpdate;
data: allForks.LightClientOptimisticUpdate;
};
}>
>;
getFinalityUpdate(): Promise<
ApiClientResponse<{
[HttpStatusCode.OK]: {
version: ForkName;
data: altair.LightClientFinalityUpdate;
data: allForks.LightClientFinalityUpdate;
};
}>
>;
Expand All @@ -74,7 +66,7 @@ export type Api = {
ApiClientResponse<{
[HttpStatusCode.OK]: {
version: ForkName;
data: altair.LightClientBootstrap;
data: allForks.LightClientBootstrap;
};
}>
>;
Expand Down Expand Up @@ -138,16 +130,31 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
}

export function getReturnTypes(): ReturnTypes<Api> {
// Form a TypeJson convertor for getUpdates
const VersionedUpdate = WithVersion((fork: ForkName) =>
isForkLightClient(fork) ? ssz.allForksLightClient[fork].LightClientUpdate : ssz.altair.LightClientUpdate
);
const getUpdates = {
toJson: (updates: {version: ForkName; data: allForks.LightClientUpdate}[]) =>
updates.map((data) => VersionedUpdate.toJson(data)),
fromJson: (updates: unknown[]) => updates.map((data) => VersionedUpdate.fromJson(data)),
};

return {
getUpdates: ArrayOf(
new ContainerType({
version: new StringType<ForkName>(),
data: ssz.altair.LightClientUpdate,
})
getUpdates,
getOptimisticUpdate: WithVersion((fork: ForkName) =>
isForkLightClient(fork)
? ssz.allForksLightClient[fork].LightClientOptimisticUpdate
: ssz.altair.LightClientOptimisticUpdate
),
getFinalityUpdate: WithVersion((fork: ForkName) =>
isForkLightClient(fork)
? ssz.allForksLightClient[fork].LightClientFinalityUpdate
: ssz.altair.LightClientFinalityUpdate
),
getBootstrap: WithVersion((fork: ForkName) =>
isForkLightClient(fork) ? ssz.allForksLightClient[fork].LightClientBootstrap : ssz.altair.LightClientBootstrap
),
getOptimisticUpdate: WithVersion(() => ssz.altair.LightClientOptimisticUpdate),
getFinalityUpdate: WithVersion(() => ssz.altair.LightClientFinalityUpdate),
getBootstrap: WithVersion(() => ssz.altair.LightClientBootstrap),
getCommitteeRoot: ContainerData(ArrayOf(ssz.Root)),
};
}
1 change: 0 additions & 1 deletion packages/api/src/beacon/routes/lodestar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
};
}

/* eslint-disable @typescript-eslint/naming-convention */
export function getReturnTypes(): ReturnTypes<Api> {
return {
writeHeapdump: sameType(),
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/beacon/server/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {ServerRoutes} from "../../utils/server/index.js";
import {ServerApi} from "../../interfaces.js";

export function getRoutes(config: IChainForkConfig, api: ServerApi<Api>): ServerRoutes<Api, ReqTypes> {
const eventSerdes = getEventSerdes();
const eventSerdes = getEventSerdes(config);

return {
// Non-JSON route. Server Sent Events (SSE)
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/builder/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function getReturnTypes(): ReturnTypes<Api> {
submitBlindedBlockV2: WithVersion((fork: ForkName) =>
isForkBlobs(fork)
? ssz.allForksBlobs[fork].SignedBeaconBlockAndBlobsSidecar
: ssz.eip4844.SignedBeaconBlockAndBlobsSidecar
: ssz.deneb.SignedBeaconBlockAndBlobsSidecar
),
};
}
2 changes: 1 addition & 1 deletion packages/api/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {HttpStatusCode, HttpSuccessCodes} from "./utils/client/httpStatusCode.js";
import {Resolves} from "./utils/types.js";

/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-explicit-any */

export type APIClientHandler = (...args: any) => PromiseLike<ApiClientResponse>;
export type APIServerHandler = (...args: any) => PromiseLike<unknown>;
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/keymanager/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
};
}

/* eslint-disable @typescript-eslint/naming-convention */
export function getReturnTypes(): ReturnTypes<Api> {
return {
listKeys: jsonType("snake"),
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/utils/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {FetchOpts, HttpError, IHttpClient} from "./httpClient.js";
* Format FetchFn opts from Fn arguments given a route definition and request serializer.
* For routes that return only JSOn use @see getGenericJsonClient
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function getFetchOptsSerializer<Fn extends (...args: any) => any, ReqType extends ReqGeneric>(
routeDef: RouteDef,
reqSerializer: ReqSerializer<Fn, ReqType>,
Expand All @@ -36,7 +36,7 @@ export function getFetchOptsSerializer<Fn extends (...args: any) => any, ReqType
/**
* Generate `getFetchOptsSerializer()` functions for all routes in `Api`
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function getFetchOptsSerializers<
Api extends Record<string, APIClientHandler>,
ReqTypes extends {[K in keyof Api]: ReqGeneric}
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/utils/server/genericJsonServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {mapValues} from "@lodestar/utils";
// eslint-disable-next-line import/no-extraneous-dependencies
import {IChainForkConfig} from "@lodestar/config";
import {ReqGeneric, TypeJson, Resolves, RouteGroupDefinition} from "../types.js";
import {getFastifySchema} from "../schema.js";
Expand All @@ -9,7 +8,7 @@ import {ServerRoute} from "./types.js";

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

/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/naming-convention */
/* eslint-disable @typescript-eslint/no-explicit-any */

export type ServerRoutes<
Api extends Record<string, APIServerHandler>,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/utils/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type ServerRoute<Req extends ReqGeneric = ReqGeneric> = {
id: string;
};

/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/naming-convention */
/* eslint-disable @typescript-eslint/naming-convention */

/** Adaptor for Fastify v3.x.x route type which has a ton of arguments */
export type FastifyHandler<Req extends ReqGeneric> = fastify.RouteHandlerMethod<
Expand Down
Loading

0 comments on commit 77d3ce6

Please sign in to comment.