Skip to content

Commit

Permalink
Address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed Aug 5, 2024
1 parent 0d3e2bd commit c657fd9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
8 changes: 4 additions & 4 deletions packages/api/src/beacon/routes/beacon/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
SignedBlindedBeaconBlock,
SignedBlockContents,
sszTypesFor,
BeaconBlockBody,
} from "@lodestar/types";
import {ForkName, ForkPreExecution, isForkBlobs, isForkExecution} from "@lodestar/params";
import {ForkName, ForkPreElectra, ForkPreExecution, isForkBlobs, isForkExecution} from "@lodestar/params";
import {Endpoint, RequestCodec, RouteDefinitions, Schema} from "../../../utils/index.js";
import {EmptyMeta, EmptyResponseCodec, EmptyResponseData, WithVersion} from "../../../utils/codecs.js";
import {
Expand All @@ -26,7 +27,6 @@ import {
import {getExecutionForkTypes, toForkName} from "../../../utils/fork.js";
import {fromHeaders} from "../../../utils/headers.js";
import {WireFormat} from "../../../utils/wireFormat.js";
import {AttestationList, AttestationListPhase0} from "./pool.js";

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

Expand Down Expand Up @@ -101,7 +101,7 @@ export type Endpoints = {
"GET",
BlockArgs,
{params: {block_id: string}},
AttestationListPhase0,
BeaconBlockBody<ForkPreElectra>["attestations"],
ExecutionOptimisticAndFinalizedMeta
>;

Expand All @@ -113,7 +113,7 @@ export type Endpoints = {
"GET",
BlockArgs,
{params: {block_id: string}},
AttestationList,
BeaconBlockBody["attestations"],
ExecutionOptimisticFinalizedAndVersionMeta
>;

Expand Down
28 changes: 9 additions & 19 deletions packages/api/src/beacon/routes/beacon/pool.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {ForkSeq} from "@lodestar/params";
import {phase0, capella, CommitteeIndex, Slot, ssz, electra} from "@lodestar/types";
import {ForkPreElectra, ForkSeq, isForkElectra} from "@lodestar/params";
import {phase0, capella, CommitteeIndex, Slot, ssz, electra, AttesterSlashing} from "@lodestar/types";
import {Schema, Endpoint, RouteDefinitions} from "../../../utils/index.js";
import {
ArrayOf,
Expand Down Expand Up @@ -171,7 +171,7 @@ export type Endpoints = {
*/
submitPoolAttesterSlashings: Endpoint<
"POST",
{attesterSlashing: phase0.AttesterSlashing},
{attesterSlashing: AttesterSlashing<ForkPreElectra>},
{body: unknown},
EmptyResponseData,
EmptyMeta
Expand Down Expand Up @@ -262,9 +262,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
schema: {query: {slot: Schema.Uint, committee_index: Schema.Uint}},
},
resp: {
data: WithVersion((fork) =>
ForkSeq[fork] >= ForkSeq.electra ? AttestationListTypeElectra : AttestationListTypePhase0
),
data: WithVersion((fork) => (isForkElectra(fork) ? AttestationListTypeElectra : AttestationListTypePhase0)),
meta: VersionCodec,
},
},
Expand All @@ -283,7 +281,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
req: EmptyRequestCodec,
resp: {
data: WithVersion((fork) =>
ForkSeq[fork] >= ForkSeq.electra ? AttesterSlashingListTypeElectra : AttesterSlashingListTypePhase0
isForkElectra(fork) ? AttesterSlashingListTypeElectra : AttesterSlashingListTypePhase0
),
meta: VersionCodec,
},
Expand Down Expand Up @@ -346,11 +344,8 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
parseReqJson: ({body, headers}) => {
const versionHeader = fromHeaders(headers, MetaHeader.Version, false);
const fork =
versionHeader !== undefined
? toForkName(versionHeader)
: config.getForkName(Number((body as {data: {slot: string}}[])[0]?.data.slot ?? 0));
const versionHeader = fromHeaders(headers, MetaHeader.Version, true);
const fork = toForkName(versionHeader);

return {
signedAttestations:
Expand Down Expand Up @@ -415,13 +410,8 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
parseReqJson: ({body, headers}) => {
const versionHeader = fromHeaders(headers, MetaHeader.Version, false);
const fork =
versionHeader !== undefined
? toForkName(versionHeader)
: config.getForkName(
Number((body as {attestations1: {data: {slot: string}}})?.attestations1.data.slot ?? 0)
);
const versionHeader = fromHeaders(headers, MetaHeader.Version, true);
const fork = toForkName(versionHeader);

return {
attesterSlashing:
Expand Down
11 changes: 2 additions & 9 deletions packages/api/src/beacon/routes/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,15 +912,8 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
parseReqJson: ({body, headers}) => {
const versionHeader = fromHeaders(headers, MetaHeader.Version, false);
const fork =
versionHeader !== undefined
? toForkName(versionHeader)
: config.getForkName(
Number(
(body as {message: {aggregate: {data: {slot: string}}}}[])[0]?.message.aggregate.data.slot ?? 0
)
);
const versionHeader = fromHeaders(headers, MetaHeader.Version, true);
const fork = toForkName(versionHeader);

return {
signedAggregateAndProofs:
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/api/impl/beacon/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function getBeaconPoolApi({
async getPoolAttestationsV2({slot, committeeIndex}) {
// Already filtered by slot
let attestations = chain.aggregatedAttestationPool.getAll(slot);
const fork = chain.config.getForkName(slot ?? attestations[0].data.slot) ?? ForkName.phase0;
const fork = chain.config.getForkName(slot ?? attestations[0]?.data.slot ?? chain.clock.currentSlot);

if (committeeIndex !== undefined) {
attestations = attestations.filter((attestation) => committeeIndex === attestation.data.index);
Expand Down
1 change: 1 addition & 0 deletions packages/validator/test/utils/apiStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function getApiClientStub(): ApiClientStub {
publishBlindedBlockV2: vi.fn(),
publishBlockV2: vi.fn(),
submitPoolSyncCommitteeSignatures: vi.fn(),
submitPoolAttestations: vi.fn(),
submitPoolAttestationsV2: vi.fn(),
},
validator: {
Expand Down

0 comments on commit c657fd9

Please sign in to comment.