Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move helper to get max blobs per block to fork config #7322

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/beacon-node/src/chain/validation/blobSidecar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainConfig, getBlobSidecarSubnetCount, getMaxBlobsPerBlock} from "@lodestar/config";
import {ChainConfig} from "@lodestar/config";
import {
ForkName,
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH,
Expand All @@ -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 = getMaxBlobsPerBlock(fork, chain.config);
const maxBlobsPerBlock = chain.config.getMaxBlobsPerBlock(fork);
if (blobSidecar.index >= maxBlobsPerBlock) {
throw new BlobSidecarGossipError(GossipAction.REJECT, {
code: BlobSidecarErrorCode.INDEX_TOO_LARGE,
Expand Down Expand Up @@ -244,5 +244,7 @@ function validateInclusionProof(blobSidecar: deneb.BlobSidecar): boolean {
}

function computeSubnetForBlobSidecar(fork: ForkName, config: ChainConfig, blobIndex: BlobIndex): number {
return blobIndex % getBlobSidecarSubnetCount(fork, config);
return (
blobIndex % (isForkPostElectra(fork) ? config.BLOB_SIDECAR_SUBNET_COUNT_ELECTRA : config.BLOB_SIDECAR_SUBNET_COUNT)
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noting here, we don't want a getter for this as it's not used as much and will be no longer relevant with peerdas

}
6 changes: 3 additions & 3 deletions packages/beacon-node/src/chain/validation/block.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ChainForkConfig, getMaxBlobsPerBlock} from "@lodestar/config";
import {ForkName, isForkBlobs, isForkPostElectra} from "@lodestar/params";
import {ChainForkConfig} from "@lodestar/config";
import {ForkName, isForkBlobs} from "@lodestar/params";
import {
computeStartSlotAtEpoch,
computeTimeAtSlot,
Expand Down 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 = getMaxBlobsPerBlock(fork, chain.config);
const maxBlobsPerBlock = chain.config.getMaxBlobsPerBlock(fork);
if (blobKzgCommitmentsLen > maxBlobsPerBlock) {
throw new BlockGossipError(GossipAction.REJECT, {
code: BlockErrorCode.TOO_MANY_KZG_COMMITMENTS,
Expand Down
6 changes: 4 additions & 2 deletions packages/beacon-node/src/network/gossip/topic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChainConfig, ForkDigestContext, getBlobSidecarSubnetCount} from "@lodestar/config";
import {ChainConfig, ForkDigestContext} from "@lodestar/config";
import {
ATTESTATION_SUBNET_COUNT,
ForkName,
Expand Down Expand Up @@ -230,7 +230,9 @@ export function getCoreTopicsAtFork(

// After Deneb also track blob_sidecar_{subnet_id}
if (ForkSeq[fork] >= ForkSeq.deneb) {
const subnetCount = getBlobSidecarSubnetCount(fork, config);
const subnetCount = isForkPostElectra(fork)
? config.BLOB_SIDECAR_SUBNET_COUNT_ELECTRA
: config.BLOB_SIDECAR_SUBNET_COUNT;

for (let subnet = 0; subnet < subnetCount; subnet++) {
topics.push({type: GossipType.blob_sidecar, subnet});
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/score";
import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types";
import {PeerId} from "@libp2p/interface";
import {routes} from "@lodestar/api";
import {BeaconConfig, getMaxBlobsPerBlock} from "@lodestar/config";
import {BeaconConfig} from "@lodestar/config";
import {LoggerNode} from "@lodestar/logger/node";
import {ForkName, ForkSeq, isForkPostElectra} from "@lodestar/params";
import {ForkSeq, isForkPostElectra} from "@lodestar/params";
import {ResponseIncoming} from "@lodestar/reqresp";
import {computeStartSlotAtEpoch, computeTimeAtSlot} from "@lodestar/state-transition";
import {
Expand Down Expand Up @@ -510,7 +510,7 @@ export class Network implements INetwork {
request
),
// request's count represent the slots, so the actual max count received could be slots * blobs per slot
request.count * getMaxBlobsPerBlock(fork, this.config),
request.count * this.config.getMaxBlobsPerBlock(fork),
responseSszTypeByMethod[ReqRespMethod.BlobSidecarsByRange]
);
}
Expand Down
13 changes: 0 additions & 13 deletions packages/config/src/constantsHelper.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/config/src/forkConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
isForkBlobs,
isForkExecution,
isForkLightClient,
isForkPostElectra,
} from "@lodestar/params";
import {Epoch, SSZTypesFor, Slot, Version, sszTypesFor} from "@lodestar/types";
import {ChainConfig} from "../chainConfig/index.js";
Expand Down Expand Up @@ -129,5 +130,8 @@ export function createForkConfig(config: ChainConfig): ForkConfig {
}
return sszTypesFor(forkName);
},
getMaxBlobsPerBlock(fork: ForkName): number {
return isForkPostElectra(fork) ? config.MAX_BLOBS_PER_BLOCK_ELECTRA : config.MAX_BLOBS_PER_BLOCK;
},
};
}
2 changes: 2 additions & 0 deletions packages/config/src/forkConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export type ForkConfig = {
getExecutionForkTypes(slot: Slot): SSZTypesFor<ForkExecution>;
/** Get blobs SSZ types by hard-fork*/
getBlobsForkTypes(slot: Slot): SSZTypesFor<ForkBlobs>;
/** Get max blobs per block by hard-fork */
getMaxBlobsPerBlock(fork: ForkName): number;
};
1 change: 0 additions & 1 deletion packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from "./chainConfig/index.js";
export * from "./genesisConfig/index.js";
export * from "./forkConfig/index.js";
export * from "./beaconConfig.js";
export * from "./constantsHelper.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {byteArrayEquals} from "@chainsafe/ssz";
import {getMaxBlobsPerBlock} from "@lodestar/config";
import {ForkName, ForkSeq, isForkBlobs} from "@lodestar/params";
import {BeaconBlockBody, BlindedBeaconBlockBody, deneb, isExecutionPayload} from "@lodestar/types";
import {toHex, toRootHex} from "@lodestar/utils";
Expand Down Expand Up @@ -50,7 +49,7 @@ export function processExecutionPayload(
}

if (isForkBlobs(forkName)) {
const maxBlobsPerBlock = getMaxBlobsPerBlock(forkName, state.config);
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
Loading