Skip to content

Commit

Permalink
Revert "Add a more generic getter to fork config"
Browse files Browse the repository at this point in the history
This reverts commit 40b51d2.
  • Loading branch information
nflaig committed Jan 17, 2025
1 parent f6a9d5b commit 2f0656b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/validation/blobSidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/validation/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export const signedBLSToExecutionChangeVersionedType = new ContainerType(
export type SignedBLSToExecutionChangeVersioned = ValueOf<typeof signedBLSToExecutionChangeVersionedType>;

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<ReturnType<typeof BlobSidecarsByRootRequestType>>;
16 changes: 6 additions & 10 deletions packages/config/src/forkConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -130,15 +130,11 @@ export function createForkConfig(config: ChainConfig): ForkConfig {
}
return sszTypesFor(forkName);
},
getValue<K extends keyof ConfigValue>(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;
},
};
}
12 changes: 4 additions & 8 deletions packages/config/src/forkConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -45,6 +39,8 @@ export type ForkConfig = {
getExecutionForkTypes(slot: Slot): SSZTypesFor<ForkExecution>;
/** Get blobs SSZ types by hard-fork*/
getBlobsForkTypes(slot: Slot): SSZTypesFor<ForkBlobs>;
/** Get config value by hard-fork */
getValue<K extends keyof ConfigValue>(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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down

0 comments on commit 2f0656b

Please sign in to comment.