diff --git a/packages/api/src/beacon/routes/beacon/pool.ts b/packages/api/src/beacon/routes/beacon/pool.ts index 4b512c242465..aa2c36d3bc92 100644 --- a/packages/api/src/beacon/routes/beacon/pool.ts +++ b/packages/api/src/beacon/routes/beacon/pool.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import {ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; -import {ForkPreElectra, ForkSeq, isForkElectra} from "@lodestar/params"; +import {isForkElectra} from "@lodestar/params"; import {phase0, capella, CommitteeIndex, Slot, ssz, electra, AttesterSlashing} from "@lodestar/types"; import {Schema, Endpoint, RouteDefinitions} from "../../../utils/index.js"; import { @@ -171,7 +171,7 @@ export type Endpoints = { */ submitPoolAttesterSlashings: Endpoint< "POST", - {attesterSlashing: AttesterSlashing}, + {attesterSlashing: phase0.AttesterSlashing}, {body: unknown}, EmptyResponseData, EmptyMeta @@ -334,44 +334,37 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { - const fork = config.getForkName(signedAttestations[0].data.slot); + const fork = config.getForkName(signedAttestations[0]?.data.slot ?? 0); return { - body: - ForkSeq[fork] >= ForkSeq.electra - ? AttestationListTypeElectra.toJson(signedAttestations as AttestationListElectra) - : AttestationListTypePhase0.toJson(signedAttestations as AttestationListPhase0), + body: isForkElectra(fork) + ? AttestationListTypeElectra.toJson(signedAttestations as AttestationListElectra) + : AttestationListTypePhase0.toJson(signedAttestations as AttestationListPhase0), headers: {[MetaHeader.Version]: fork}, }; }, parseReqJson: ({body, headers}) => { - const versionHeader = fromHeaders(headers, MetaHeader.Version, true); - const fork = toForkName(versionHeader); - + const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedAttestations: - ForkSeq[fork] >= ForkSeq.electra - ? AttestationListTypeElectra.fromJson(body) - : AttestationListTypePhase0.fromJson(body), + signedAttestations: isForkElectra(fork) + ? AttestationListTypeElectra.fromJson(body) + : AttestationListTypePhase0.fromJson(body), }; }, writeReqSsz: ({signedAttestations}) => { - const fork = config.getForkName(signedAttestations[0].data.slot); + const fork = config.getForkName(signedAttestations[0]?.data.slot ?? 0); return { - body: - ForkSeq[fork] >= ForkSeq.electra - ? AttestationListTypeElectra.serialize(signedAttestations as AttestationListElectra) - : AttestationListTypePhase0.serialize(signedAttestations as AttestationListPhase0), + body: isForkElectra(fork) + ? AttestationListTypeElectra.serialize(signedAttestations as AttestationListElectra) + : AttestationListTypePhase0.serialize(signedAttestations as AttestationListPhase0), headers: {[MetaHeader.Version]: fork}, }; }, parseReqSsz: ({body, headers}) => { - const versionHeader = fromHeaders(headers, MetaHeader.Version, true); - const fork = toForkName(versionHeader); + const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedAttestations: - ForkSeq[fork] >= ForkSeq.electra - ? AttestationListTypeElectra.deserialize(body) - : AttestationListTypePhase0.deserialize(body), + signedAttestations: isForkElectra(fork) + ? AttestationListTypeElectra.deserialize(body) + : AttestationListTypePhase0.deserialize(body), }; }, schema: { @@ -402,42 +395,35 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = config.getForkName(Number(attesterSlashing.attestation1.data.slot)); return { - body: - ForkSeq[fork] >= ForkSeq.electra - ? ssz.electra.AttesterSlashing.toJson(attesterSlashing) - : ssz.phase0.AttesterSlashing.toJson(attesterSlashing), + body: isForkElectra(fork) + ? ssz.electra.AttesterSlashing.toJson(attesterSlashing) + : ssz.phase0.AttesterSlashing.toJson(attesterSlashing), headers: {[MetaHeader.Version]: fork}, }; }, parseReqJson: ({body, headers}) => { - const versionHeader = fromHeaders(headers, MetaHeader.Version, true); - const fork = toForkName(versionHeader); - + const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - attesterSlashing: - ForkSeq[fork] >= ForkSeq.electra - ? ssz.electra.AttesterSlashing.fromJson(body) - : ssz.phase0.AttesterSlashing.fromJson(body), + attesterSlashing: isForkElectra(fork) + ? ssz.electra.AttesterSlashing.fromJson(body) + : ssz.phase0.AttesterSlashing.fromJson(body), }; }, writeReqSsz: ({attesterSlashing}) => { const fork = config.getForkName(Number(attesterSlashing.attestation1.data.slot)); return { - body: - ForkSeq[fork] >= ForkSeq.electra - ? ssz.electra.AttesterSlashing.serialize(attesterSlashing as electra.AttesterSlashing) - : ssz.electra.AttesterSlashing.serialize(attesterSlashing as phase0.AttesterSlashing), + body: isForkElectra(fork) + ? ssz.electra.AttesterSlashing.serialize(attesterSlashing as electra.AttesterSlashing) + : ssz.electra.AttesterSlashing.serialize(attesterSlashing as phase0.AttesterSlashing), headers: {[MetaHeader.Version]: fork}, }; }, parseReqSsz: ({body, headers}) => { - const versionHeader = fromHeaders(headers, MetaHeader.Version, true); - const fork = toForkName(versionHeader); + const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - attesterSlashing: - ForkSeq[fork] >= ForkSeq.electra - ? ssz.electra.AttesterSlashing.deserialize(body) - : ssz.phase0.AttesterSlashing.deserialize(body), + attesterSlashing: isForkElectra(fork) + ? ssz.electra.AttesterSlashing.deserialize(body) + : ssz.phase0.AttesterSlashing.deserialize(body), }; }, schema: { diff --git a/packages/api/src/beacon/routes/validator.ts b/packages/api/src/beacon/routes/validator.ts index 510160b2e027..ed7c0fd9ba0a 100644 --- a/packages/api/src/beacon/routes/validator.ts +++ b/packages/api/src/beacon/routes/validator.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import {ContainerType, fromHexString, toHexString, Type, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; -import {isForkBlobs, ForkSeq} from "@lodestar/params"; +import {isForkBlobs, isForkElectra} from "@lodestar/params"; import { altair, BLSSignature, @@ -203,7 +203,7 @@ export const AttesterDutyListType = ArrayOf(AttesterDutyType); export const ProposerDutyListType = ArrayOf(ProposerDutyType); export const SyncDutyListType = ArrayOf(SyncDutyType); export const SignedAggregateAndProofListPhase0Type = ArrayOf(ssz.phase0.SignedAggregateAndProof); -export const SignedAggregateAndProofListElectaType = ArrayOf(ssz.electra.SignedAggregateAndProof); +export const SignedAggregateAndProofListElectraType = ArrayOf(ssz.electra.SignedAggregateAndProof); export const SignedContributionAndProofListType = ArrayOf(ssz.altair.SignedContributionAndProof); export const BeaconCommitteeSubscriptionListType = ArrayOf(BeaconCommitteeSubscriptionType); export const SyncCommitteeSubscriptionListType = ArrayOf(SyncCommitteeSubscriptionType); @@ -221,8 +221,8 @@ export type ProposerDutyList = ValueOf; export type SyncDuty = ValueOf; export type SyncDutyList = ValueOf; export type SignedAggregateAndProofListPhase0 = ValueOf; -export type SignedAggregateAndProofListElecta = ValueOf; -export type SignedAggregateAndProofList = SignedAggregateAndProofListPhase0 | SignedAggregateAndProofListElecta; +export type SignedAggregateAndProofListElectra = ValueOf; +export type SignedAggregateAndProofList = SignedAggregateAndProofListPhase0 | SignedAggregateAndProofListElectra; export type SignedContributionAndProofList = ValueOf; export type BeaconCommitteeSubscription = ValueOf; export type BeaconCommitteeSubscriptionList = ValueOf; @@ -869,9 +869,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions - ForkSeq[fork] >= ForkSeq.electra ? ssz.electra.Attestation : ssz.phase0.Attestation - ), + data: WithVersion((fork) => (isForkElectra(fork) ? ssz.electra.Attestation : ssz.phase0.Attestation)), meta: VersionCodec, }, }, @@ -900,50 +898,43 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = config.getForkName(signedAggregateAndProofs[0]?.message.aggregate.data.slot ?? 0); return { - body: - ForkSeq[fork] >= ForkSeq.electra - ? SignedAggregateAndProofListElectaType.toJson( - signedAggregateAndProofs as SignedAggregateAndProofListElecta - ) - : SignedAggregateAndProofListPhase0Type.toJson( - signedAggregateAndProofs as SignedAggregateAndProofListPhase0 - ), + body: isForkElectra(fork) + ? SignedAggregateAndProofListElectraType.toJson( + signedAggregateAndProofs as SignedAggregateAndProofListElectra + ) + : SignedAggregateAndProofListPhase0Type.toJson( + signedAggregateAndProofs as SignedAggregateAndProofListPhase0 + ), headers: {[MetaHeader.Version]: fork}, }; }, parseReqJson: ({body, headers}) => { - const versionHeader = fromHeaders(headers, MetaHeader.Version, true); - const fork = toForkName(versionHeader); - + const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedAggregateAndProofs: - ForkSeq[fork] >= ForkSeq.electra - ? SignedAggregateAndProofListElectaType.fromJson(body) - : SignedAggregateAndProofListPhase0Type.fromJson(body), + signedAggregateAndProofs: isForkElectra(fork) + ? SignedAggregateAndProofListElectraType.fromJson(body) + : SignedAggregateAndProofListPhase0Type.fromJson(body), }; }, writeReqSsz: ({signedAggregateAndProofs}) => { const fork = config.getForkName(signedAggregateAndProofs[0]?.message.aggregate.data.slot ?? 0); return { - body: - ForkSeq[fork] >= ForkSeq.electra - ? SignedAggregateAndProofListElectaType.serialize( - signedAggregateAndProofs as SignedAggregateAndProofListElecta - ) - : SignedAggregateAndProofListPhase0Type.serialize( - signedAggregateAndProofs as SignedAggregateAndProofListPhase0 - ), + body: isForkElectra(fork) + ? SignedAggregateAndProofListElectraType.serialize( + signedAggregateAndProofs as SignedAggregateAndProofListElectra + ) + : SignedAggregateAndProofListPhase0Type.serialize( + signedAggregateAndProofs as SignedAggregateAndProofListPhase0 + ), headers: {[MetaHeader.Version]: fork}, }; }, parseReqSsz: ({body, headers}) => { - const versionHeader = fromHeaders(headers, MetaHeader.Version, true); - const fork = toForkName(versionHeader); + const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedAggregateAndProofs: - ForkSeq[fork] >= ForkSeq.electra - ? SignedAggregateAndProofListElectaType.deserialize(body) - : SignedAggregateAndProofListPhase0Type.deserialize(body), + signedAggregateAndProofs: isForkElectra(fork) + ? SignedAggregateAndProofListElectraType.deserialize(body) + : SignedAggregateAndProofListPhase0Type.deserialize(body), }; }, schema: { 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 5a66ebfe174e..bc8c838a5401 100644 --- a/packages/beacon-node/src/api/impl/beacon/pool/index.ts +++ b/packages/beacon-node/src/api/impl/beacon/pool/index.ts @@ -52,6 +52,7 @@ export function getBeaconPoolApi({ }, async getPoolAttesterSlashingsV2() { + // TODO Electra: Determine fork based on data returned by api return {data: chain.opPool.getAllAttesterSlashings(), meta: {version: ForkName.phase0}}; }, diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 543831c778a6..298e7c6f4483 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -1083,7 +1083,7 @@ export function getValidatorApi( if (!aggregate) { throw new ApiError( 404, - `No aggregated attestation for slot=${slot} committeeIndex=${committeeIndex}, dataRoot=${dataRootHex}` + `No aggregated attestation for slot=${slot}, committeeIndex=${committeeIndex}, dataRoot=${dataRootHex}` ); } diff --git a/packages/beacon-node/src/chain/opPools/attestationPool.ts b/packages/beacon-node/src/chain/opPools/attestationPool.ts index a8c8940a0a0f..f125b8c941db 100644 --- a/packages/beacon-node/src/chain/opPools/attestationPool.ts +++ b/packages/beacon-node/src/chain/opPools/attestationPool.ts @@ -234,7 +234,7 @@ function attestationToAggregate(attestation: Attestation): AggregateFast { } /** - * Unwrap AggregateFast to phase0.Attestation + * Unwrap AggregateFast to Attestation */ function fastToAttestation(aggFast: AggregateFast): Attestation { return {...aggFast, signature: aggFast.signature.toBytes()};