diff --git a/packages/beacon-node/src/chain/validation/blobSidecar.ts b/packages/beacon-node/src/chain/validation/blobSidecar.ts index 53e464d7070..37fa3067b80 100644 --- a/packages/beacon-node/src/chain/validation/blobSidecar.ts +++ b/packages/beacon-node/src/chain/validation/blobSidecar.ts @@ -25,7 +25,7 @@ export async function validateGossipBlobSidecar( const blobSlot = blobSidecar.signedBlockHeader.message.slot; // [REJECT] The sidecar's index is consistent with `MAX_BLOBS_PER_BLOCK` -- i.e. `blob_sidecar.index < MAX_BLOBS_PER_BLOCK`. - const maxBlobsPerBlock = chain.config.getValue(fork, "MAX_BLOBS_PER_BLOCK"); + const maxBlobsPerBlock = chain.config.getMaxBlobsPerBlock(fork); if (blobSidecar.index >= maxBlobsPerBlock) { throw new BlobSidecarGossipError(GossipAction.REJECT, { code: BlobSidecarErrorCode.INDEX_TOO_LARGE, diff --git a/packages/beacon-node/src/chain/validation/block.ts b/packages/beacon-node/src/chain/validation/block.ts index f1a9fdd601c..2b18999db40 100644 --- a/packages/beacon-node/src/chain/validation/block.ts +++ b/packages/beacon-node/src/chain/validation/block.ts @@ -113,7 +113,7 @@ export async function validateGossipBlock( // [REJECT] The length of KZG commitments is less than or equal to the limitation defined in Consensus Layer -- i.e. validate that len(body.signed_beacon_block.message.blob_kzg_commitments) <= MAX_BLOBS_PER_BLOCK if (isForkBlobs(fork)) { const blobKzgCommitmentsLen = (block as deneb.BeaconBlock).body.blobKzgCommitments.length; - const maxBlobsPerBlock = chain.config.getValue(fork, "MAX_BLOBS_PER_BLOCK"); + const maxBlobsPerBlock = chain.config.getMaxBlobsPerBlock(fork); if (blobKzgCommitmentsLen > maxBlobsPerBlock) { throw new BlockGossipError(GossipAction.REJECT, { code: BlockErrorCode.TOO_MANY_KZG_COMMITMENTS, diff --git a/packages/beacon-node/src/network/network.ts b/packages/beacon-node/src/network/network.ts index 5c488d30ccf..505da6718c3 100644 --- a/packages/beacon-node/src/network/network.ts +++ b/packages/beacon-node/src/network/network.ts @@ -506,7 +506,7 @@ export class Network implements INetwork { return collectMaxResponseTyped( this.sendReqRespRequest(peerId, ReqRespMethod.BlobSidecarsByRange, [Version.V1], request), // request's count represent the slots, so the actual max count received could be slots * blobs per slot - request.count * this.config.getValue(fork, "MAX_BLOBS_PER_BLOCK"), + request.count * this.config.getMaxBlobsPerBlock(fork), responseSszTypeByMethod[ReqRespMethod.BlobSidecarsByRange] ); } diff --git a/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts b/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts index a967a472934..557d01a2284 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts @@ -105,7 +105,7 @@ export function validateBlobSidecarsByRangeRequest( throw new ResponseError(RespStatus.INVALID_REQUEST, "startSlot < genesis"); } - const maxRequestBlobSidecars = config.getValue(config.getForkName(startSlot), "MAX_REQUEST_BLOB_SIDECARS"); + const maxRequestBlobSidecars = config.getMaxRequestBlobSidecars(config.getForkName(startSlot)); if (count > maxRequestBlobSidecars) { count = maxRequestBlobSidecars; diff --git a/packages/beacon-node/src/util/types.ts b/packages/beacon-node/src/util/types.ts index d918c89e73a..4133d6db102 100644 --- a/packages/beacon-node/src/util/types.ts +++ b/packages/beacon-node/src/util/types.ts @@ -16,5 +16,5 @@ export const signedBLSToExecutionChangeVersionedType = new ContainerType( export type SignedBLSToExecutionChangeVersioned = ValueOf; export const BlobSidecarsByRootRequestType = (fork: ForkName, config: BeaconConfig) => - new ListCompositeType(ssz.deneb.BlobIdentifier, config.getValue(fork, "MAX_REQUEST_BLOB_SIDECARS")); + new ListCompositeType(ssz.deneb.BlobIdentifier, config.getMaxRequestBlobSidecars(fork)); export type BlobSidecarsByRootRequest = ValueOf>; diff --git a/packages/config/src/forkConfig/index.ts b/packages/config/src/forkConfig/index.ts index 78e4ba615bf..9551627188d 100644 --- a/packages/config/src/forkConfig/index.ts +++ b/packages/config/src/forkConfig/index.ts @@ -14,7 +14,7 @@ import { } from "@lodestar/params"; import {Epoch, SSZTypesFor, Slot, Version, sszTypesFor} from "@lodestar/types"; import {ChainConfig} from "../chainConfig/index.js"; -import {ConfigValue, ForkConfig, ForkInfo} from "./types.js"; +import {ForkConfig, ForkInfo} from "./types.js"; export * from "./types.js"; @@ -130,15 +130,11 @@ export function createForkConfig(config: ChainConfig): ForkConfig { } return sszTypesFor(forkName); }, - getValue(fork: ForkName, name: K): ConfigValue[K] { - switch (name) { - case "MAX_BLOBS_PER_BLOCK": - return isForkPostElectra(fork) ? config.MAX_BLOBS_PER_BLOCK_ELECTRA : config.MAX_BLOBS_PER_BLOCK; - case "MAX_REQUEST_BLOB_SIDECARS": - return isForkPostElectra(fork) ? config.MAX_REQUEST_BLOB_SIDECARS_ELECTRA : config.MAX_REQUEST_BLOB_SIDECARS; - default: - throw Error(`Config value "${name}" does not exist`); - } + getMaxBlobsPerBlock(fork: ForkName): number { + return isForkPostElectra(fork) ? config.MAX_BLOBS_PER_BLOCK_ELECTRA : config.MAX_BLOBS_PER_BLOCK; + }, + getMaxRequestBlobSidecars(fork: ForkName): number { + return isForkPostElectra(fork) ? config.MAX_REQUEST_BLOB_SIDECARS_ELECTRA : config.MAX_REQUEST_BLOB_SIDECARS; }, }; } diff --git a/packages/config/src/forkConfig/types.ts b/packages/config/src/forkConfig/types.ts index 590f14ec4e5..c7874482770 100644 --- a/packages/config/src/forkConfig/types.ts +++ b/packages/config/src/forkConfig/types.ts @@ -10,12 +10,6 @@ export type ForkInfo = { prevForkName: ForkName; }; -/** Set of config values that frequently change across hard-forks */ -export type ConfigValue = { - MAX_BLOBS_PER_BLOCK: number; - MAX_REQUEST_BLOB_SIDECARS: number; -}; - /** * Fork schedule and helper methods */ @@ -45,6 +39,8 @@ export type ForkConfig = { getExecutionForkTypes(slot: Slot): SSZTypesFor; /** Get blobs SSZ types by hard-fork*/ getBlobsForkTypes(slot: Slot): SSZTypesFor; - /** Get config value by hard-fork */ - getValue(fork: ForkName, name: K): ConfigValue[K]; + /** Get max blobs per block by hard-fork */ + getMaxBlobsPerBlock(fork: ForkName): number; + /** Get max request blob sidecars by hard-fork */ + getMaxRequestBlobSidecars(fork: ForkName): number; }; diff --git a/packages/state-transition/src/block/processExecutionPayload.ts b/packages/state-transition/src/block/processExecutionPayload.ts index c267c2f4e67..ddc24e884d9 100644 --- a/packages/state-transition/src/block/processExecutionPayload.ts +++ b/packages/state-transition/src/block/processExecutionPayload.ts @@ -49,7 +49,7 @@ export function processExecutionPayload( } if (isForkBlobs(forkName)) { - const maxBlobsPerBlock = state.config.getValue(forkName, "MAX_BLOBS_PER_BLOCK"); + const maxBlobsPerBlock = state.config.getMaxBlobsPerBlock(forkName); const blobKzgCommitmentsLen = (body as deneb.BeaconBlockBody).blobKzgCommitments?.length ?? 0; if (blobKzgCommitmentsLen > maxBlobsPerBlock) { throw Error(`blobKzgCommitmentsLen exceeds limit=${maxBlobsPerBlock}`);