diff --git a/packages/api/src/beacon/routes/beacon/block.ts b/packages/api/src/beacon/routes/beacon/block.ts index dcf0d07c7a9b..facd3da55059 100644 --- a/packages/api/src/beacon/routes/beacon/block.ts +++ b/packages/api/src/beacon/routes/beacon/block.ts @@ -22,7 +22,7 @@ import { ExecutionOptimisticFinalizedAndVersionMeta, MetaHeader, } from "../../../utils/metadata.js"; -import {getBlindedForkTypes, toForkName} from "../../../utils/fork.js"; +import {getExecutionForkTypes, toForkName} from "../../../utils/fork.js"; import {fromHeaders} from "../../../utils/headers.js"; import {WireFormat} from "../../../utils/wireFormat.js"; @@ -414,7 +414,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = config.getForkName(signedBlindedBlock.message.slot); return { - body: getBlindedForkTypes(fork).SignedBeaconBlock.toJson(signedBlindedBlock), + body: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.toJson(signedBlindedBlock), headers: { [MetaHeader.Version]: fork, }, @@ -423,13 +423,13 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedBlindedBlock: getBlindedForkTypes(fork).SignedBeaconBlock.fromJson(body), + signedBlindedBlock: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.fromJson(body), }; }, writeReqSsz: ({signedBlindedBlock}) => { const fork = config.getForkName(signedBlindedBlock.message.slot); return { - body: getBlindedForkTypes(fork).SignedBeaconBlock.serialize(signedBlindedBlock), + body: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.serialize(signedBlindedBlock), headers: { [MetaHeader.Version]: fork, }, @@ -438,7 +438,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedBlindedBlock: getBlindedForkTypes(fork).SignedBeaconBlock.deserialize(body), + signedBlindedBlock: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.deserialize(body), }; }, schema: { @@ -458,7 +458,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = config.getForkName(signedBlindedBlock.message.slot); return { - body: getBlindedForkTypes(fork).SignedBeaconBlock.toJson(signedBlindedBlock), + body: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.toJson(signedBlindedBlock), headers: { [MetaHeader.Version]: fork, @@ -469,14 +469,14 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedBlindedBlock: getBlindedForkTypes(fork).SignedBeaconBlock.fromJson(body), + signedBlindedBlock: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.fromJson(body), broadcastValidation: query.broadcast_validation as BroadcastValidation, }; }, writeReqSsz: ({signedBlindedBlock, broadcastValidation}) => { const fork = config.getForkName(signedBlindedBlock.message.slot); return { - body: getBlindedForkTypes(fork).SignedBeaconBlock.serialize(signedBlindedBlock), + body: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.serialize(signedBlindedBlock), headers: { [MetaHeader.Version]: fork, }, @@ -486,7 +486,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedBlindedBlock: getBlindedForkTypes(fork).SignedBeaconBlock.deserialize(body), + signedBlindedBlock: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.deserialize(body), broadcastValidation: query.broadcast_validation as BroadcastValidation, }; }, diff --git a/packages/api/src/beacon/routes/validator.ts b/packages/api/src/beacon/routes/validator.ts index cd26f8997764..32a76a536d81 100644 --- a/packages/api/src/beacon/routes/validator.ts +++ b/packages/api/src/beacon/routes/validator.ts @@ -20,7 +20,7 @@ import { } from "@lodestar/types"; import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; import {fromGraffitiHex, toBoolean, toGraffitiHex} from "../../utils/serdes.js"; -import {getBlindedForkTypes, toForkName} from "../../utils/fork.js"; +import {getExecutionForkTypes, toForkName} from "../../utils/fork.js"; import { ArrayOf, EmptyMeta, @@ -685,7 +685,7 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions (executionPayloadBlinded - ? getBlindedForkTypes(version).BeaconBlock + ? getExecutionForkTypes(version).BlindedBeaconBlock : isForkBlobs(version) ? BlockContentsType : ssz[version].BeaconBlock) as Type @@ -753,7 +753,7 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions getBlindedForkTypes(fork).BeaconBlock), + data: WithVersion((fork) => getExecutionForkTypes(fork).BlindedBeaconBlock), meta: VersionCodec, }, }, diff --git a/packages/api/src/builder/routes.ts b/packages/api/src/builder/routes.ts index 7e6a6e24b1b7..971f4a1e63fe 100644 --- a/packages/api/src/builder/routes.ts +++ b/packages/api/src/builder/routes.ts @@ -27,7 +27,7 @@ import { JsonOnlyReq, WithVersion, } from "../utils/codecs.js"; -import {getBlindedForkTypes, getExecutionForkTypes, toForkName} from "../utils/fork.js"; +import {getExecutionForkTypes, toForkName} from "../utils/fork.js"; import {fromHeaders} from "../utils/headers.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes @@ -130,7 +130,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = config.getForkName(signedBlindedBlock.message.slot); return { - body: getBlindedForkTypes(fork).SignedBeaconBlock.toJson(signedBlindedBlock), + body: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.toJson(signedBlindedBlock), headers: { [MetaHeader.Version]: fork, }, @@ -139,7 +139,7 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions { const fork = toForkName(fromHeaders(headers, MetaHeader.Version)); return { - signedBlindedBlock: getBlindedForkTypes(fork).SignedBeaconBlock.fromJson(body), + signedBlindedBlock: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.fromJson(body), }; }, schema: { diff --git a/packages/api/src/utils/fork.ts b/packages/api/src/utils/fork.ts index 0925e750719a..5854a0867d02 100644 --- a/packages/api/src/utils/fork.ts +++ b/packages/api/src/utils/fork.ts @@ -7,7 +7,7 @@ import { isForkExecution, isForkLightClient, } from "@lodestar/params"; -import {SSZBlindedTypesFor, SSZTypesFor, ssz, sszTypesFor} from "@lodestar/types"; +import {SSZTypesFor, sszTypesFor} from "@lodestar/types"; export function toForkName(version: string): ForkName { // Teku returns fork as UPPERCASE @@ -35,13 +35,6 @@ export function getExecutionForkTypes(fork: ForkName): SSZTypesFor { - if (!isForkExecution(fork)) { - throw Error(`Invalid fork=${fork} for blinded fork types`); - } - return ssz.allForksBlinded[fork]; -} - export function getBlobsForkTypes(fork: ForkName): SSZTypesFor { if (!isForkBlobs(fork)) { throw Error(`Invalid fork=${fork} for blobs fork types`); diff --git a/packages/beacon-node/src/api/impl/beacon/blocks/index.ts b/packages/beacon-node/src/api/impl/beacon/blocks/index.ts index d4675de21185..274d88e5d508 100644 --- a/packages/beacon-node/src/api/impl/beacon/blocks/index.ts +++ b/packages/beacon-node/src/api/impl/beacon/blocks/index.ts @@ -240,8 +240,8 @@ export function getBeaconBlockApi({ const slot = signedBlindedBlock.message.slot; const blockRoot = toHex( chain.config - .getBlindedForkTypes(signedBlindedBlock.message.slot) - .BeaconBlock.hashTreeRoot(signedBlindedBlock.message) + .getExecutionForkTypes(signedBlindedBlock.message.slot) + .BlindedBeaconBlock.hashTreeRoot(signedBlindedBlock.message) ); // Either the payload/blobs are cached from i) engine locally or ii) they are from the builder diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 8fb40e4ecb6b..486fc6e8062f 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -416,7 +416,7 @@ export function getValidatorApi({ slot, executionPayloadValue, consensusBlockValue, - root: toHex(config.getBlindedForkTypes(slot).BeaconBlock.hashTreeRoot(block)), + root: toHex(config.getExecutionForkTypes(slot).BlindedBeaconBlock.hashTreeRoot(block)), }); if (chain.opts.persistProducedBlocks) { diff --git a/packages/beacon-node/src/chain/chain.ts b/packages/beacon-node/src/chain/chain.ts index ccd10f7b4d6f..a6912d952b68 100644 --- a/packages/beacon-node/src/chain/chain.ts +++ b/packages/beacon-node/src/chain/chain.ts @@ -620,7 +620,7 @@ export class BeaconChain implements IBeaconChain { const bodyRoot = blockType === BlockType.Full ? this.config.getForkTypes(slot).BeaconBlockBody.hashTreeRoot(body) - : this.config.getBlindedForkTypes(slot).BeaconBlockBody.hashTreeRoot(body as BlindedBeaconBlockBody); + : this.config.getExecutionForkTypes(slot).BlindedBeaconBlockBody.hashTreeRoot(body as BlindedBeaconBlockBody); this.logger.debug("Computing block post state from the produced body", { slot, bodyRoot: toHexString(bodyRoot), @@ -640,7 +640,7 @@ export class BeaconChain implements IBeaconChain { const blockRoot = blockType === BlockType.Full ? this.config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block) - : this.config.getBlindedForkTypes(slot).BeaconBlock.hashTreeRoot(block as BlindedBeaconBlock); + : this.config.getExecutionForkTypes(slot).BlindedBeaconBlock.hashTreeRoot(block as BlindedBeaconBlock); const blockRootHex = toHex(blockRoot); // track the produced block for consensus broadcast validations @@ -777,7 +777,7 @@ export class BeaconChain implements IBeaconChain { persistBlock(data: BeaconBlock | BlindedBeaconBlock, suffix?: string): void { const slot = data.slot; if (isBlindedBeaconBlock(data)) { - const sszType = this.config.getBlindedForkTypes(slot).BeaconBlock; + const sszType = this.config.getExecutionForkTypes(slot).BlindedBeaconBlock; void this.persistSszObject("BlindedBeaconBlock", sszType.serialize(data), sszType.hashTreeRoot(data), suffix); } else { const sszType = this.config.getForkTypes(slot).BeaconBlock; diff --git a/packages/config/src/forkConfig/index.ts b/packages/config/src/forkConfig/index.ts index 45213d0a611d..358c2d752001 100644 --- a/packages/config/src/forkConfig/index.ts +++ b/packages/config/src/forkConfig/index.ts @@ -101,13 +101,6 @@ export function createForkConfig(config: ChainConfig): ForkConfig { } return ssz.allForksExecution[forkName]; }, - getBlindedForkTypes(slot: Slot): (typeof ssz.allForksBlinded)[ForkExecution] { - const forkName = this.getForkName(slot); - if (!isForkExecution(forkName)) { - throw Error(`Invalid slot=${slot} fork=${forkName} for blinded fork types`); - } - return ssz.allForksBlinded[forkName]; - }, getLightClientForkTypes(slot: Slot): SSZTypesFor { const forkName = this.getForkName(slot); if (!isForkLightClient(forkName)) { diff --git a/packages/config/src/forkConfig/types.ts b/packages/config/src/forkConfig/types.ts index 93f34a62bc83..2905e6f03c34 100644 --- a/packages/config/src/forkConfig/types.ts +++ b/packages/config/src/forkConfig/types.ts @@ -1,5 +1,5 @@ import {ForkAll, ForkBlobs, ForkExecution, ForkLightClient, ForkName, ForkSeq} from "@lodestar/params"; -import {Epoch, SSZBlindedTypesFor, SSZTypesFor, Slot, Version} from "@lodestar/types"; +import {Epoch, SSZTypesFor, Slot, Version} from "@lodestar/types"; export type ForkInfo = { name: ForkName; @@ -34,8 +34,6 @@ export type ForkConfig = { getLightClientForkTypes(slot: Slot): SSZTypesFor; /** Get execution SSZ types by hard-fork*/ getExecutionForkTypes(slot: Slot): SSZTypesFor; - /** Get blinded SSZ types by hard-fork */ - getBlindedForkTypes(slot: Slot): SSZBlindedTypesFor; /** Get blobs SSZ types by hard-fork*/ getBlobsForkTypes(slot: Slot): SSZTypesFor; }; diff --git a/packages/state-transition/src/signatureSets/proposer.ts b/packages/state-transition/src/signatureSets/proposer.ts index b5e501bd16c7..e5ae7fd1f6f1 100644 --- a/packages/state-transition/src/signatureSets/proposer.ts +++ b/packages/state-transition/src/signatureSets/proposer.ts @@ -20,7 +20,7 @@ export function getBlockProposerSignatureSet( const domain = config.getDomain(state.slot, DOMAIN_BEACON_PROPOSER, signedBlock.message.slot); const blockType = isBlindedBeaconBlock(signedBlock.message) - ? config.getBlindedForkTypes(signedBlock.message.slot).BeaconBlock + ? config.getExecutionForkTypes(signedBlock.message.slot).BlindedBeaconBlock : config.getForkTypes(signedBlock.message.slot).BeaconBlock; return { diff --git a/packages/state-transition/src/util/blindedBlock.ts b/packages/state-transition/src/util/blindedBlock.ts index 2b9510bd1e99..d63b40a9fe88 100644 --- a/packages/state-transition/src/util/blindedBlock.ts +++ b/packages/state-transition/src/util/blindedBlock.ts @@ -25,7 +25,7 @@ export function blindedOrFullBlockHashTreeRoot( ): Root { return isBlindedBeaconBlock(blindedOrFull) ? // Blinded - config.getBlindedForkTypes(blindedOrFull.slot).BeaconBlock.hashTreeRoot(blindedOrFull) + config.getExecutionForkTypes(blindedOrFull.slot).BlindedBeaconBlock.hashTreeRoot(blindedOrFull) : // Full config.getForkTypes(blindedOrFull.slot).BeaconBlock.hashTreeRoot(blindedOrFull); } @@ -36,7 +36,7 @@ export function blindedOrFullBlockToHeader( ): BeaconBlockHeader { const bodyRoot = isBlindedBeaconBlock(blindedOrFull) ? // Blinded - config.getBlindedForkTypes(blindedOrFull.slot).BeaconBlockBody.hashTreeRoot(blindedOrFull.body) + config.getExecutionForkTypes(blindedOrFull.slot).BlindedBeaconBlockBody.hashTreeRoot(blindedOrFull.body) : // Full config.getForkTypes(blindedOrFull.slot).BeaconBlockBody.hashTreeRoot(blindedOrFull.body); diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 7838a02d06e2..e0745834c7d1 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,8 +1,8 @@ export * from "./types.js"; import * as ssz from "./sszTypes.js"; import {sszTypesFor} from "./sszTypes.js"; -import type {SSZBlindedTypesFor, SSZTypesFor} from "./sszTypes.js"; -export {sszTypesFor, SSZBlindedTypesFor, SSZTypesFor, ssz}; +import type {SSZTypesFor} from "./sszTypes.js"; +export {sszTypesFor, SSZTypesFor, ssz}; // Typeguards export * from "./utils/typeguards.js"; // String type diff --git a/packages/types/src/sszTypes.ts b/packages/types/src/sszTypes.ts index 1ee5b9340630..eae1bbcdeaba 100644 --- a/packages/types/src/sszTypes.ts +++ b/packages/types/src/sszTypes.ts @@ -110,44 +110,6 @@ const blobsForks: ForkBlobs[] = [ForkName.deneb]; export const allForksExecution = pick(typesByFork, ...executionForks); export const allForksLightClient = pick(typesByFork, ...lightCLientForks); export const allForksBlobs = pick(typesByFork, ...blobsForks); -export const allForksBlinded = { - bellatrix: { - BeaconBlockBody: bellatrix.BlindedBeaconBlockBody, - BeaconBlock: bellatrix.BlindedBeaconBlock, - SignedBeaconBlock: bellatrix.SignedBlindedBeaconBlock, - }, - capella: { - BeaconBlockBody: capella.BlindedBeaconBlockBody, - BeaconBlock: capella.BlindedBeaconBlock, - SignedBeaconBlock: capella.SignedBlindedBeaconBlock, - }, - deneb: { - BeaconBlockBody: deneb.BlindedBeaconBlockBody, - BeaconBlock: deneb.BlindedBeaconBlock, - SignedBeaconBlock: deneb.SignedBlindedBeaconBlock, - }, -}; - -// TODO: These helpers should be removed along with `allForksBlinded` -type SSZBlindedTypesByFork = { - [F in keyof typeof allForksBlinded]: { - [T in keyof (typeof allForksBlinded)[F]]: (typeof allForksBlinded)[F][T]; - }; -}; - -// TODO: These helpers should be removed along with `allForksBlinded` -export type SSZBlindedTypesFor< - F extends ForkExecution, - K extends keyof SSZBlindedTypesByFork[F] | void = void, -> = K extends void - ? // It compiles fine, need to debug the error - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error - {[K2 in keyof SSZBlindedTypesByFork[F]]: UnionSSZForksTypeOf} - : // It compiles fine, need to debug the error - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error - UnionSSZForksTypeOf]>; /** * A type of union of forks must accept as any parameter the UNION of all fork types.