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

chore: remove apis that are no longer part of beacon spec #6901

Merged
merged 2 commits into from
Jun 21, 2024
Merged
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
26 changes: 2 additions & 24 deletions packages/api/src/beacon/routes/beacon/block.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {ContainerType, ListCompositeType, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {allForks, Slot, ssz, RootHex, deneb, phase0, isSignedBlockContents} from "@lodestar/types";
import {allForks, Slot, ssz, RootHex, deneb, isSignedBlockContents} from "@lodestar/types";
import {ForkName, ForkSeq} from "@lodestar/params";
import {Endpoint, RequestCodec, RouteDefinitions, Schema} from "../../../utils/index.js";
import {EmptyMeta, EmptyMetaCodec, EmptyResponseCodec, EmptyResponseData, WithVersion} from "../../../utils/codecs.js";
import {EmptyMeta, EmptyResponseCodec, EmptyResponseData, WithVersion} from "../../../utils/codecs.js";
import {
ExecutionOptimisticAndFinalizedCodec,
ExecutionOptimisticAndFinalizedMeta,
Expand Down Expand Up @@ -66,19 +66,6 @@ export enum BroadcastValidation {
}

export type Endpoints = {
/**
* Get block
* Returns the complete `SignedBeaconBlock` for a given block ID.
*/
getBlock: Endpoint<
// ⏎
"GET",
BlockArgs,
{params: {block_id: string}},
phase0.SignedBeaconBlock,
EmptyMeta
>;

/**
* Get block
* Retrieves block details for given block id.
Expand Down Expand Up @@ -220,15 +207,6 @@ const blockIdOnlyReq: RequestCodec<Endpoint<"GET", {blockId: BlockId}, {params:

export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoints> {
return {
getBlock: {
url: "/eth/v1/beacon/blocks/{block_id}",
method: "GET",
req: blockIdOnlyReq,
resp: {
data: ssz.phase0.SignedBeaconBlock,
meta: EmptyMetaCodec,
},
},
getBlockV2: {
url: "/eth/v2/beacon/blocks/{block_id}",
method: "GET",
Expand Down
92 changes: 13 additions & 79 deletions packages/api/src/beacon/routes/debug.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {ContainerType, Type, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {allForks, ssz, StringType, phase0} from "@lodestar/types";
import {allForks, ssz, StringType} from "@lodestar/types";
import {
ArrayOf,
EmptyArgs,
Expand All @@ -14,8 +14,6 @@ import {
import {
ExecutionOptimisticFinalizedAndVersionCodec,
ExecutionOptimisticFinalizedAndVersionMeta,
ExecutionOptimisticAndFinalizedCodec,
ExecutionOptimisticAndFinalizedMeta,
} from "../../utils/metadata.js";
import {Endpoint, RouteDefinitions} from "../../utils/types.js";
import {WireFormat} from "../../utils/wireFormat.js";
Expand All @@ -25,7 +23,7 @@ import {StateArgs} from "./beacon/state.js";
// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

const stringType = new StringType();
const ProtoNodeResponseType = new ContainerType(
const ProtoNodeType = new ContainerType(
{
executionPayloadBlockHash: stringType,
executionPayloadNumber: ssz.UintNum64,
Expand All @@ -51,14 +49,7 @@ const ProtoNodeResponseType = new ContainerType(
},
{jsonCase: "eth2"}
);
const SlotRootType = new ContainerType(
{
slot: ssz.Slot,
root: stringType,
},
{jsonCase: "eth2"}
);
const SlotRootExecutionOptimisticType = new ContainerType(
const DebugChainHeadType = new ContainerType(
{
slot: ssz.Slot,
root: stringType,
Expand All @@ -67,27 +58,13 @@ const SlotRootExecutionOptimisticType = new ContainerType(
{jsonCase: "eth2"}
);

const ProtoNodeResponseListType = ArrayOf(ProtoNodeResponseType);
const SlotRootListType = ArrayOf(SlotRootType);
const SlotRootExecutionOptimisticListType = ArrayOf(SlotRootExecutionOptimisticType);
const ProtoNodeListType = ArrayOf(ProtoNodeType);
const DebugChainHeadListType = ArrayOf(DebugChainHeadType);

type ProtoNodeResponseList = ValueOf<typeof ProtoNodeResponseListType>;
type SlotRootList = ValueOf<typeof SlotRootListType>;
type SlotRootExecutionOptimisticList = ValueOf<typeof SlotRootExecutionOptimisticListType>;
type ProtoNodeList = ValueOf<typeof ProtoNodeListType>;
type DebugChainHeadList = ValueOf<typeof DebugChainHeadListType>;

export type Endpoints = {
/**
* Retrieves all possible chain heads (leaves of fork choice tree).
*/
getDebugChainHeads: Endpoint<
// ⏎
"GET",
EmptyArgs,
EmptyRequest,
SlotRootList,
EmptyMeta
>;

/**
* Retrieves all possible chain heads (leaves of fork choice tree).
*/
Expand All @@ -96,7 +73,7 @@ export type Endpoints = {
"GET",
EmptyArgs,
EmptyRequest,
SlotRootExecutionOptimisticList,
DebugChainHeadList,
EmptyMeta
>;

Expand All @@ -108,23 +85,10 @@ export type Endpoints = {
"GET",
EmptyArgs,
EmptyRequest,
ProtoNodeResponseList,
ProtoNodeList,
EmptyMeta
>;

/**
* Get full BeaconState object
* Returns full BeaconState object for given stateId.
* Depending on `Accept` header it can be returned either as json or as bytes serialized by SSZ
*/
getState: Endpoint<
"GET",
StateArgs,
{params: {state_id: string}},
phase0.BeaconState,
ExecutionOptimisticAndFinalizedMeta
>;

/**
* Get full BeaconState object
* Returns full BeaconState object for given stateId.
Expand All @@ -139,27 +103,14 @@ export type Endpoints = {
>;
};

// Default timeout is not sufficient to download state as JSON
const GET_STATE_TIMEOUT_MS = 5 * 60 * 1000;

export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpoints> {
return {
getDebugChainHeads: {
url: "/eth/v1/debug/beacon/heads",
method: "GET",
req: EmptyRequestCodec,
resp: {
data: SlotRootListType,
meta: EmptyMetaCodec,
onlySupport: WireFormat.json,
},
},
getDebugChainHeadsV2: {
url: "/eth/v2/debug/beacon/heads",
method: "GET",
req: EmptyRequestCodec,
resp: {
data: SlotRootExecutionOptimisticListType,
data: DebugChainHeadListType,
meta: EmptyMetaCodec,
onlySupport: WireFormat.json,
},
Expand All @@ -169,29 +120,11 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
method: "GET",
req: EmptyRequestCodec,
resp: {
data: ProtoNodeResponseListType,
data: ProtoNodeListType,
meta: EmptyMetaCodec,
onlySupport: WireFormat.json,
},
},
getState: {
url: "/eth/v1/debug/beacon/states/{state_id}",
method: "GET",
req: {
writeReq: ({stateId}) => ({params: {state_id: stateId.toString()}}),
parseReq: ({params}) => ({stateId: params.state_id}),
schema: {
params: {state_id: Schema.StringRequired},
},
},
resp: {
data: ssz.phase0.BeaconState,
meta: ExecutionOptimisticAndFinalizedCodec,
},
init: {
timeoutMs: GET_STATE_TIMEOUT_MS,
},
},
getStateV2: {
url: "/eth/v2/debug/beacon/states/{state_id}",
method: "GET",
Expand All @@ -207,7 +140,8 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
meta: ExecutionOptimisticFinalizedAndVersionCodec,
},
init: {
timeoutMs: GET_STATE_TIMEOUT_MS,
// Default timeout is not sufficient to download state as JSON
timeoutMs: 5 * 60 * 1000,
},
},
};
Expand Down
45 changes: 0 additions & 45 deletions packages/api/src/beacon/routes/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,25 +290,6 @@ export type Endpoints = {
ExecutionOptimisticMeta
>;

/**
* Produce a new block, without signature.
* Requests a beacon node to produce a valid block, which can then be signed by a validator.
*/
produceBlock: Endpoint<
"GET",
{
/** The slot for which the block should be proposed. */
slot: Slot;
/** The validator's randao reveal value */
randaoReveal: BLSSignature;
/** Arbitrary data validator wants to include in block */
graffiti: string;
},
{params: {slot: number}; query: {randao_reveal: string; graffiti: string}},
allForks.BeaconBlock,
VersionMeta
>;

/**
* Requests a beacon node to produce a valid block, which can then be signed by a validator.
* Metadata in the response indicates the type of block produced, and the supported types of block
Expand Down Expand Up @@ -607,32 +588,6 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
meta: ExecutionOptimisticCodec,
},
},
produceBlock: {
url: "/eth/v1/validator/blocks/{slot}",
method: "GET",
req: {
writeReq: ({slot, randaoReveal, graffiti}) => ({
params: {slot},
query: {randao_reveal: toHexString(randaoReveal), graffiti: toGraffitiHex(graffiti)},
}),
parseReq: ({params, query}) => ({
slot: params.slot,
randaoReveal: fromHexString(query.randao_reveal),
graffiti: fromGraffitiHex(query.graffiti),
}),
schema: {
params: {slot: Schema.UintRequired},
query: {
randao_reveal: Schema.StringRequired,
graffiti: Schema.String,
},
},
},
resp: {
data: WithVersion((fork) => ssz[fork].BeaconBlock),
meta: VersionCodec,
},
},
produceBlockV2: {
url: "/eth/v2/validator/blocks/{slot}",
method: "GET",
Expand Down
34 changes: 15 additions & 19 deletions packages/api/test/unit/beacon/genericServerTest/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("beacon / debug", () => {

// Get state by SSZ

describe("getState() in SSZ format", () => {
describe("get state in SSZ format", () => {
const mockApi = getMockApi<Endpoints>(getDefinitions(config));
let baseUrl: string;
let server: FastifyInstance;
Expand All @@ -41,26 +41,22 @@ describe("beacon / debug", () => {
if (server !== undefined) await server.close();
});

for (const method of ["getState" as const, "getStateV2" as const]) {
it(method, async () => {
const state = ssz.phase0.BeaconState.defaultValue();
const stateSerialized = ssz.phase0.BeaconState.serialize(state);
mockApi[method].mockResolvedValue({
data: stateSerialized,
meta: {version: ForkName.phase0, executionOptimistic: false, finalized: false},
});

const httpClient = new HttpClient({baseUrl});
const client = getClient(config, httpClient);
it("getStateV2", async () => {
const state = ssz.deneb.BeaconState.defaultValue();
const stateSerialized = ssz.deneb.BeaconState.serialize(state);
mockApi.getStateV2.mockResolvedValue({
data: stateSerialized,
meta: {version: ForkName.deneb, executionOptimistic: false, finalized: false},
});

const res = await client[method]({stateId: "head"}, {responseWireFormat: WireFormat.ssz});
const httpClient = new HttpClient({baseUrl});
const client = getClient(config, httpClient);

expect(res.ok).toBe(true);
const res = await client.getStateV2({stateId: "head"}, {responseWireFormat: WireFormat.ssz});

if (res.ok) {
expect(toHexString(res.ssz())).toBe(toHexString(stateSerialized));
}
});
}
expect(res.ok).toBe(true);
expect(res.wireFormat()).toBe(WireFormat.ssz);
expect(toHexString(res.ssz())).toBe(toHexString(stateSerialized));
});
});
});
4 changes: 0 additions & 4 deletions packages/api/test/unit/beacon/testData/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ const validatorResponse: ValidatorResponse = {
export const testData: GenericServerTestCases<Endpoints> = {
// block

getBlock: {
args: {blockId: "head"},
res: {data: ssz.phase0.SignedBeaconBlock.defaultValue()},
},
getBlockV2: {
args: {blockId: "head"},
res: {
Expand Down
8 changes: 0 additions & 8 deletions packages/api/test/unit/beacon/testData/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import {GenericServerTestCases} from "../../../utils/genericServerTest.js";
const rootHex = toHexString(Buffer.alloc(32, 1));

export const testData: GenericServerTestCases<Endpoints> = {
getDebugChainHeads: {
args: undefined,
res: {data: [{slot: 1, root: rootHex}]},
},
getDebugChainHeadsV2: {
args: undefined,
res: {data: [{slot: 1, root: rootHex, executionOptimistic: true}]},
Expand Down Expand Up @@ -45,10 +41,6 @@ export const testData: GenericServerTestCases<Endpoints> = {
],
},
},
getState: {
args: {stateId: "head"},
res: {data: ssz.phase0.BeaconState.defaultValue(), meta: {executionOptimistic: true, finalized: false}},
},
getStateV2: {
args: {stateId: "head"},
res: {
Expand Down
4 changes: 0 additions & 4 deletions packages/api/test/unit/beacon/testData/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export const testData: GenericServerTestCases<Endpoints> = {
meta: {executionOptimistic: true},
},
},
produceBlock: {
args: {slot: 32000, randaoReveal, graffiti},
res: {data: ssz.phase0.BeaconBlock.defaultValue(), meta: {version: ForkName.phase0}},
},
produceBlockV2: {
args: {
slot: 32000,
Expand Down
5 changes: 0 additions & 5 deletions packages/beacon-node/src/api/impl/beacon/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,6 @@ export function getBeaconBlockApi({
};
},

async getBlock({blockId}) {
const {block} = await resolveBlockId(chain, blockId);
return {data: block};
},

async getBlockV2({blockId}) {
const {block, executionOptimistic, finalized} = await resolveBlockId(chain, blockId);
return {
Expand Down
Loading
Loading