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

test: update beacon api spec version to 2.4.1 #5695

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Lodestar Eth Consensus API

[![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)](https://discord.gg/aMxzVcr)
[![ETH Beacon APIs Spec v2.1.0](https://img.shields.io/badge/ETH%20beacon--APIs-2.1.0-blue)](https://github.com/ethereum/beacon-APIs/releases/tag/v2.1.0)
[![ETH Beacon APIs Spec v2.4.1](https://img.shields.io/badge/ETH%20beacon--APIs-2.4.1-blue)](https://github.com/ethereum/beacon-APIs/releases/tag/v2.4.1)
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-18.x-green)

Expand Down
18 changes: 9 additions & 9 deletions packages/api/src/beacon/routes/beacon/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type Api = {
* @returns any Successful response
* @throws ApiError
*/
getPoolBlsToExecutionChanges(): Promise<
getPoolBLSToExecutionChanges(): Promise<
ApiClientResponse<{[HttpStatusCode.OK]: {data: capella.SignedBLSToExecutionChange[]}}>
>;

Expand Down Expand Up @@ -123,7 +123,7 @@ export type Api = {
* @returns any BLSToExecutionChange is stored in node and broadcasted to network
* @throws ApiError
*/
submitPoolBlsToExecutionChange(
submitPoolBLSToExecutionChange(
blsToExecutionChange: capella.SignedBLSToExecutionChange[]
): Promise<ApiClientResponse<{[HttpStatusCode.OK]: void}, HttpStatusCode.BAD_REQUEST>>;

Expand All @@ -143,12 +143,12 @@ export const routesData: RoutesData<Api> = {
getPoolAttesterSlashings: {url: "/eth/v1/beacon/pool/attester_slashings", method: "GET"},
getPoolProposerSlashings: {url: "/eth/v1/beacon/pool/proposer_slashings", method: "GET"},
getPoolVoluntaryExits: {url: "/eth/v1/beacon/pool/voluntary_exits", method: "GET"},
getPoolBlsToExecutionChanges: {url: "/eth/v1/beacon/pool/bls_to_execution_changes", method: "GET"},
getPoolBLSToExecutionChanges: {url: "/eth/v1/beacon/pool/bls_to_execution_changes", method: "GET"},
submitPoolAttestations: {url: "/eth/v1/beacon/pool/attestations", method: "POST"},
submitPoolAttesterSlashings: {url: "/eth/v1/beacon/pool/attester_slashings", method: "POST"},
submitPoolProposerSlashings: {url: "/eth/v1/beacon/pool/proposer_slashings", method: "POST"},
submitPoolVoluntaryExit: {url: "/eth/v1/beacon/pool/voluntary_exits", method: "POST"},
submitPoolBlsToExecutionChange: {url: "/eth/v1/beacon/pool/bls_to_execution_changes", method: "POST"},
submitPoolBLSToExecutionChange: {url: "/eth/v1/beacon/pool/bls_to_execution_changes", method: "POST"},
submitPoolSyncCommitteeSignatures: {url: "/eth/v1/beacon/pool/sync_committees", method: "POST"},
};

Expand All @@ -158,12 +158,12 @@ export type ReqTypes = {
getPoolAttesterSlashings: ReqEmpty;
getPoolProposerSlashings: ReqEmpty;
getPoolVoluntaryExits: ReqEmpty;
getPoolBlsToExecutionChanges: ReqEmpty;
getPoolBLSToExecutionChanges: ReqEmpty;
submitPoolAttestations: {body: unknown};
submitPoolAttesterSlashings: {body: unknown};
submitPoolProposerSlashings: {body: unknown};
submitPoolVoluntaryExit: {body: unknown};
submitPoolBlsToExecutionChange: {body: unknown};
submitPoolBLSToExecutionChange: {body: unknown};
submitPoolSyncCommitteeSignatures: {body: unknown};
};

Expand All @@ -177,12 +177,12 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
getPoolAttesterSlashings: reqEmpty,
getPoolProposerSlashings: reqEmpty,
getPoolVoluntaryExits: reqEmpty,
getPoolBlsToExecutionChanges: reqEmpty,
getPoolBLSToExecutionChanges: reqEmpty,
submitPoolAttestations: reqOnlyBody(ArrayOf(ssz.phase0.Attestation), Schema.ObjectArray),
submitPoolAttesterSlashings: reqOnlyBody(ssz.phase0.AttesterSlashing, Schema.Object),
submitPoolProposerSlashings: reqOnlyBody(ssz.phase0.ProposerSlashing, Schema.Object),
submitPoolVoluntaryExit: reqOnlyBody(ssz.phase0.SignedVoluntaryExit, Schema.Object),
submitPoolBlsToExecutionChange: reqOnlyBody(ArrayOf(ssz.capella.SignedBLSToExecutionChange), Schema.ObjectArray),
submitPoolBLSToExecutionChange: reqOnlyBody(ArrayOf(ssz.capella.SignedBLSToExecutionChange), Schema.ObjectArray),
submitPoolSyncCommitteeSignatures: reqOnlyBody(ArrayOf(ssz.altair.SyncCommitteeMessage), Schema.ObjectArray),
};
}
Expand All @@ -193,6 +193,6 @@ export function getReturnTypes(): ReturnTypes<Api> {
getPoolAttesterSlashings: ContainerData(ArrayOf(ssz.phase0.AttesterSlashing)),
getPoolProposerSlashings: ContainerData(ArrayOf(ssz.phase0.ProposerSlashing)),
getPoolVoluntaryExits: ContainerData(ArrayOf(ssz.phase0.SignedVoluntaryExit)),
getPoolBlsToExecutionChanges: ContainerData(ArrayOf(ssz.capella.SignedBLSToExecutionChange)),
getPoolBLSToExecutionChanges: ContainerData(ArrayOf(ssz.capella.SignedBLSToExecutionChange)),
};
}
54 changes: 27 additions & 27 deletions packages/api/src/beacon/routes/lightclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type Api = {
* - Has most bits
* - Oldest update
*/
getUpdates(
getLightClientUpdatesByRange(
startPeriod: SyncPeriod,
count: number
): Promise<
Expand All @@ -39,15 +39,15 @@ export type Api = {
* Returns the latest optimistic head update available. Clients should use the SSE type `light_client_optimistic_update`
* unless to get the very first head update after syncing, or if SSE are not supported by the server.
*/
getOptimisticUpdate(): Promise<
getLightClientOptimisticUpdate(): Promise<
ApiClientResponse<{
[HttpStatusCode.OK]: {
version: ForkName;
data: allForks.LightClientOptimisticUpdate;
};
}>
>;
getFinalityUpdate(): Promise<
getLightClientFinalityUpdate(): Promise<
ApiClientResponse<{
[HttpStatusCode.OK]: {
version: ForkName;
Expand All @@ -60,7 +60,7 @@ export type Api = {
* The trusted block root should be fetched with similar means to a weak subjectivity checkpoint.
* Only block roots for checkpoints are guaranteed to be available.
*/
getBootstrap(blockRoot: string): Promise<
getLightClientBootstrap(blockRoot: string): Promise<
ApiClientResponse<{
[HttpStatusCode.OK]: {
version: ForkName;
Expand All @@ -71,7 +71,7 @@ export type Api = {
/**
* Returns an array of sync committee hashes based on the provided period and count
*/
getCommitteeRoot(
getLightClientCommitteeRoot(
startPeriod: SyncPeriod,
count: number
): Promise<
Expand All @@ -87,39 +87,39 @@ export type Api = {
* Define javascript values for each route
*/
export const routesData: RoutesData<Api> = {
getUpdates: {url: "/eth/v1/beacon/light_client/updates", method: "GET"},
getOptimisticUpdate: {url: "/eth/v1/beacon/light_client/optimistic_update", method: "GET"},
getFinalityUpdate: {url: "/eth/v1/beacon/light_client/finality_update", method: "GET"},
getBootstrap: {url: "/eth/v1/beacon/light_client/bootstrap/{block_root}", method: "GET"},
getCommitteeRoot: {url: "/eth/v0/beacon/light_client/committee_root", method: "GET"},
getLightClientUpdatesByRange: {url: "/eth/v1/beacon/light_client/updates", method: "GET"},
getLightClientOptimisticUpdate: {url: "/eth/v1/beacon/light_client/optimistic_update", method: "GET"},
getLightClientFinalityUpdate: {url: "/eth/v1/beacon/light_client/finality_update", method: "GET"},
getLightClientBootstrap: {url: "/eth/v1/beacon/light_client/bootstrap/{block_root}", method: "GET"},
getLightClientCommitteeRoot: {url: "/eth/v0/beacon/light_client/committee_root", method: "GET"},
};

/* eslint-disable @typescript-eslint/naming-convention */
export type ReqTypes = {
getUpdates: {query: {start_period: number; count: number}};
getOptimisticUpdate: ReqEmpty;
getFinalityUpdate: ReqEmpty;
getBootstrap: {params: {block_root: string}};
getCommitteeRoot: {query: {start_period: number; count: number}};
getLightClientUpdatesByRange: {query: {start_period: number; count: number}};
getLightClientOptimisticUpdate: ReqEmpty;
getLightClientFinalityUpdate: ReqEmpty;
getLightClientBootstrap: {params: {block_root: string}};
getLightClientCommitteeRoot: {query: {start_period: number; count: number}};
};

export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
return {
getUpdates: {
getLightClientUpdatesByRange: {
writeReq: (start_period, count) => ({query: {start_period, count}}),
parseReq: ({query}) => [query.start_period, query.count],
schema: {query: {start_period: Schema.UintRequired, count: Schema.UintRequired}},
},

getOptimisticUpdate: reqEmpty,
getFinalityUpdate: reqEmpty,
getLightClientOptimisticUpdate: reqEmpty,
getLightClientFinalityUpdate: reqEmpty,

getBootstrap: {
getLightClientBootstrap: {
writeReq: (block_root) => ({params: {block_root}}),
parseReq: ({params}) => [params.block_root],
schema: {params: {block_root: Schema.StringRequired}},
},
getCommitteeRoot: {
getLightClientCommitteeRoot: {
writeReq: (start_period, count) => ({query: {start_period, count}}),
parseReq: ({query}) => [query.start_period, query.count],
schema: {query: {start_period: Schema.UintRequired, count: Schema.UintRequired}},
Expand All @@ -128,31 +128,31 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
}

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

return {
getUpdates,
getOptimisticUpdate: WithVersion((fork: ForkName) =>
getLightClientUpdatesByRange,
getLightClientOptimisticUpdate: WithVersion((fork: ForkName) =>
isForkLightClient(fork)
? ssz.allForksLightClient[fork].LightClientOptimisticUpdate
: ssz.altair.LightClientOptimisticUpdate
),
getFinalityUpdate: WithVersion((fork: ForkName) =>
getLightClientFinalityUpdate: WithVersion((fork: ForkName) =>
isForkLightClient(fork)
? ssz.allForksLightClient[fork].LightClientFinalityUpdate
: ssz.altair.LightClientFinalityUpdate
),
getBootstrap: WithVersion((fork: ForkName) =>
getLightClientBootstrap: WithVersion((fork: ForkName) =>
isForkLightClient(fork) ? ssz.allForksLightClient[fork].LightClientBootstrap : ssz.altair.LightClientBootstrap
),
getCommitteeRoot: ContainerData(ArrayOf(ssz.Root)),
getLightClientCommitteeRoot: ContainerData(ArrayOf(ssz.Root)),
};
}
2 changes: 1 addition & 1 deletion packages/api/test/unit/beacon/oapiSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {testData as validatorTestData} from "./testData/validator.js";
// eslint-disable-next-line @typescript-eslint/naming-convention
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const version = "v2.3.0";
const version = "v2.4.1";
const openApiFile: OpenApiFile = {
url: `https://github.com/ethereum/beacon-APIs/releases/download/${version}/beacon-node-oapi.json`,
filepath: path.join(__dirname, "../../../oapi-schemas/beacon-node-oapi.json"),
Expand Down
4 changes: 2 additions & 2 deletions packages/api/test/unit/beacon/testData/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const testData: GenericServerTestCases<Api> = {
args: [],
res: {data: [ssz.phase0.SignedVoluntaryExit.defaultValue()]},
},
getPoolBlsToExecutionChanges: {
getPoolBLSToExecutionChanges: {
args: [],
res: {data: [ssz.capella.SignedBLSToExecutionChange.defaultValue()]},
},
Expand All @@ -99,7 +99,7 @@ export const testData: GenericServerTestCases<Api> = {
args: [ssz.phase0.SignedVoluntaryExit.defaultValue()],
res: undefined,
},
submitPoolBlsToExecutionChange: {
submitPoolBLSToExecutionChange: {
args: [[ssz.capella.SignedBLSToExecutionChange.defaultValue()]],
res: undefined,
},
Expand Down
10 changes: 5 additions & 5 deletions packages/api/test/unit/beacon/testData/lightclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const header = ssz.altair.LightClientHeader.defaultValue();
const signatureSlot = ssz.Slot.defaultValue();

export const testData: GenericServerTestCases<Api> = {
getUpdates: {
getLightClientUpdatesByRange: {
args: [1, 2],
res: [{version: ForkName.bellatrix, data: lightClientUpdate}],
},
getOptimisticUpdate: {
getLightClientOptimisticUpdate: {
args: [],
res: {version: ForkName.bellatrix, data: {syncAggregate, attestedHeader: header, signatureSlot}},
},
getFinalityUpdate: {
getLightClientFinalityUpdate: {
args: [],
res: {
version: ForkName.bellatrix,
Expand All @@ -33,7 +33,7 @@ export const testData: GenericServerTestCases<Api> = {
},
},
},
getBootstrap: {
getLightClientBootstrap: {
args: [toHexString(root)],
res: {
version: ForkName.bellatrix,
Expand All @@ -44,7 +44,7 @@ export const testData: GenericServerTestCases<Api> = {
},
},
},
getCommitteeRoot: {
getLightClientCommitteeRoot: {
args: [1, 2],
res: {data: [Buffer.alloc(32, 0), Buffer.alloc(32, 1)]},
},
Expand Down
18 changes: 9 additions & 9 deletions packages/beacon-node/src/api/impl/beacon/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {validateGossipAttestation} from "../../../../chain/validation/index.js";
import {validateGossipAttesterSlashing} from "../../../../chain/validation/attesterSlashing.js";
import {validateGossipProposerSlashing} from "../../../../chain/validation/proposerSlashing.js";
import {validateGossipVoluntaryExit} from "../../../../chain/validation/voluntaryExit.js";
import {validateBlsToExecutionChange} from "../../../../chain/validation/blsToExecutionChange.js";
import {validateBLSToExecutionChange} from "../../../../chain/validation/blsToExecutionChange.js";
import {validateSyncCommitteeSigOnly} from "../../../../chain/validation/syncCommittee.js";
import {ApiModules} from "../../types.js";
import {AttestationError, GossipAction, SyncCommitteeError} from "../../../../chain/errors/index.js";
Expand Down Expand Up @@ -41,8 +41,8 @@ export function getBeaconPoolApi({
return {data: chain.opPool.getAllVoluntaryExits()};
},

async getPoolBlsToExecutionChanges() {
return {data: chain.opPool.getAllBlsToExecutionChanges().map(({data}) => data)};
async getPoolBLSToExecutionChanges() {
return {data: chain.opPool.getAllBLSToExecutionChanges().map(({data}) => data)};
},

async submitPoolAttestations(attestations) {
Expand Down Expand Up @@ -111,23 +111,23 @@ export function getBeaconPoolApi({
await network.publishVoluntaryExit(voluntaryExit);
},

async submitPoolBlsToExecutionChange(blsToExecutionChanges) {
async submitPoolBLSToExecutionChange(blsToExecutionChanges) {
const errors: Error[] = [];

await Promise.all(
blsToExecutionChanges.map(async (blsToExecutionChange, i) => {
try {
// Ignore even if the change exists and reprocess
await validateBlsToExecutionChange(chain, blsToExecutionChange, true);
await validateBLSToExecutionChange(chain, blsToExecutionChange, true);
const preCapella = chain.clock.currentEpoch < chain.config.CAPELLA_FORK_EPOCH;
chain.opPool.insertBlsToExecutionChange(blsToExecutionChange, preCapella);
chain.opPool.insertBLSToExecutionChange(blsToExecutionChange, preCapella);
if (!preCapella) {
await network.publishBlsToExecutionChange(blsToExecutionChange);
await network.publishBLSToExecutionChange(blsToExecutionChange);
}
} catch (e) {
errors.push(e as Error);
logger.error(
`Error on submitPoolBlsToExecutionChange [${i}]`,
`Error on submitPoolBLSToExecutionChange [${i}]`,
{validatorIndex: blsToExecutionChange.message.validatorIndex},
e as Error
);
Expand All @@ -136,7 +136,7 @@ export function getBeaconPoolApi({
);

if (errors.length > 1) {
throw Error("Multiple errors on submitPoolBlsToExecutionChange\n" + errors.map((e) => e.message).join("\n"));
throw Error("Multiple errors on submitPoolBLSToExecutionChange\n" + errors.map((e) => e.message).join("\n"));
} else if (errors.length === 1) {
throw errors[0];
}
Expand Down
10 changes: 5 additions & 5 deletions packages/beacon-node/src/api/impl/lightclient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getLightclientApi({
config,
}: Pick<ApiModules, "chain" | "config">): ServerApi<routes.lightclient.Api> {
return {
async getUpdates(startPeriod: SyncPeriod, count: number) {
async getLightClientUpdatesByRange(startPeriod: SyncPeriod, count: number) {
const maxAllowedCount = Math.min(MAX_REQUEST_LIGHT_CLIENT_UPDATES, count);
const periods = Array.from({length: maxAllowedCount}, (_ignored, i) => i + startPeriod);
const updates = await Promise.all(periods.map((period) => chain.lightClientServer.getUpdate(period)));
Expand All @@ -21,28 +21,28 @@ export function getLightclientApi({
}));
},

async getOptimisticUpdate() {
async getLightClientOptimisticUpdate() {
const data = chain.lightClientServer.getOptimisticUpdate();
if (data === null) {
throw Error("No optimistic update available");
}
return {version: config.getForkName(data.attestedHeader.beacon.slot), data};
},

async getFinalityUpdate() {
async getLightClientFinalityUpdate() {
const data = chain.lightClientServer.getFinalityUpdate();
if (data === null) {
throw Error("No finality update available");
}
return {version: config.getForkName(data.attestedHeader.beacon.slot), data};
},

async getBootstrap(blockRoot) {
async getLightClientBootstrap(blockRoot) {
const bootstrapProof = await chain.lightClientServer.getBootstrap(fromHexString(blockRoot));
return {version: config.getForkName(bootstrapProof.header.beacon.slot), data: bootstrapProof};
},

async getCommitteeRoot(startPeriod: SyncPeriod, count: number) {
async getLightClientCommitteeRoot(startPeriod: SyncPeriod, count: number) {
const maxAllowedCount = Math.min(MAX_REQUEST_LIGHT_CLIENT_COMMITTEE_HASHES, count);
const periods = Array.from({length: maxAllowedCount}, (_ignored, i) => i + startPeriod);
const committeeHashes = await Promise.all(
Expand Down
Loading
Loading