diff --git a/packages/api/src/beacon/routes/beacon/block.ts b/packages/api/src/beacon/routes/beacon/block.ts index 7c6e9c67c56b..2c141e3bdefd 100644 --- a/packages/api/src/beacon/routes/beacon/block.ts +++ b/packages/api/src/beacon/routes/beacon/block.ts @@ -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 { @@ -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 @@ -101,7 +101,7 @@ export type Endpoints = { "GET", BlockArgs, {params: {block_id: string}}, - AttestationListPhase0, + BeaconBlockBody["attestations"], ExecutionOptimisticAndFinalizedMeta >; @@ -113,7 +113,7 @@ export type Endpoints = { "GET", BlockArgs, {params: {block_id: string}}, - AttestationList, + BeaconBlockBody["attestations"], ExecutionOptimisticFinalizedAndVersionMeta >; diff --git a/packages/api/src/beacon/routes/beacon/pool.ts b/packages/api/src/beacon/routes/beacon/pool.ts index 2f4ffcbb1c67..497bdfe98a17 100644 --- a/packages/api/src/beacon/routes/beacon/pool.ts +++ b/packages/api/src/beacon/routes/beacon/pool.ts @@ -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, @@ -171,7 +171,7 @@ export type Endpoints = { */ submitPoolAttesterSlashings: Endpoint< "POST", - {attesterSlashing: phase0.AttesterSlashing}, + {attesterSlashing: AttesterSlashing}, {body: unknown}, EmptyResponseData, EmptyMeta @@ -262,9 +262,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions - ForkSeq[fork] >= ForkSeq.electra ? AttestationListTypeElectra : AttestationListTypePhase0 - ), + data: WithVersion((fork) => (isForkElectra(fork) ? AttestationListTypeElectra : AttestationListTypePhase0)), meta: VersionCodec, }, }, @@ -283,7 +281,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions - ForkSeq[fork] >= ForkSeq.electra ? AttesterSlashingListTypeElectra : AttesterSlashingListTypePhase0 + isForkElectra(fork) ? AttesterSlashingListTypeElectra : AttesterSlashingListTypePhase0 ), meta: VersionCodec, }, @@ -346,11 +344,8 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { - 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: @@ -415,13 +410,8 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { - 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: diff --git a/packages/api/src/beacon/routes/validator.ts b/packages/api/src/beacon/routes/validator.ts index 9ce7595332bd..510160b2e027 100644 --- a/packages/api/src/beacon/routes/validator.ts +++ b/packages/api/src/beacon/routes/validator.ts @@ -912,15 +912,8 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { - 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: diff --git a/packages/beacon-node/src/api/impl/beacon/pool/index.ts b/packages/beacon-node/src/api/impl/beacon/pool/index.ts index 6f4d84ab659c..5a66ebfe174e 100644 --- a/packages/beacon-node/src/api/impl/beacon/pool/index.ts +++ b/packages/beacon-node/src/api/impl/beacon/pool/index.ts @@ -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); diff --git a/packages/validator/test/utils/apiStub.ts b/packages/validator/test/utils/apiStub.ts index 508674811b2f..839e273a3c10 100644 --- a/packages/validator/test/utils/apiStub.ts +++ b/packages/validator/test/utils/apiStub.ts @@ -19,6 +19,7 @@ export function getApiClientStub(): ApiClientStub { publishBlindedBlockV2: vi.fn(), publishBlockV2: vi.fn(), submitPoolSyncCommitteeSignatures: vi.fn(), + submitPoolAttestations: vi.fn(), submitPoolAttestationsV2: vi.fn(), }, validator: {