diff --git a/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts b/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts index 620b98be63d..ce563c8f3d8 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts @@ -1,4 +1,5 @@ -import {GENESIS_SLOT, MAX_REQUEST_BLOCKS} from "@lodestar/params"; +import {BeaconConfig} from "@lodestar/config"; +import {GENESIS_SLOT, MAX_REQUEST_BLOCKS, MAX_REQUEST_BLOCKS_DENEB, isForkBlobs} from "@lodestar/params"; import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp"; import {deneb, phase0} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; @@ -12,7 +13,7 @@ export async function* onBeaconBlocksByRange( chain: IBeaconChain, db: IBeaconDb ): AsyncIterable { - const {startSlot, count} = validateBeaconBlocksByRangeRequest(request); + const {startSlot, count} = validateBeaconBlocksByRangeRequest(chain.config, request); const endSlot = startSlot + count; const finalized = db.blockArchive; @@ -69,6 +70,7 @@ export async function* onBeaconBlocksByRange( } export function validateBeaconBlocksByRangeRequest( + config: BeaconConfig, request: deneb.BlobSidecarsByRangeRequest ): deneb.BlobSidecarsByRangeRequest { const {startSlot} = request; @@ -84,9 +86,10 @@ export function validateBeaconBlocksByRangeRequest( // step > 1 is deprecated, see https://github.com/ethereum/consensus-specs/pull/2856 - if (count > MAX_REQUEST_BLOCKS) { - // TODO: This is probably not right as `BeaconBlocksByRangeV2` takes at most `MAX_REQUEST_BLOCKS_DENEB` - count = MAX_REQUEST_BLOCKS; + const maxRequestBlocks = isForkBlobs(config.getForkName(startSlot)) ? MAX_REQUEST_BLOCKS_DENEB : MAX_REQUEST_BLOCKS; + + if (count > maxRequestBlocks) { + count = maxRequestBlocks; } return {startSlot, count}; diff --git a/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts b/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts index 9cac846fdb6..557d01a2284 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts @@ -1,4 +1,5 @@ -import {BLOBSIDECAR_FIXED_SIZE, GENESIS_SLOT, MAX_REQUEST_BLOCKS_DENEB} from "@lodestar/params"; +import {BeaconConfig} from "@lodestar/config"; +import {BLOBSIDECAR_FIXED_SIZE, GENESIS_SLOT} from "@lodestar/params"; import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp"; import {Slot, deneb} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; @@ -12,7 +13,7 @@ export async function* onBlobSidecarsByRange( db: IBeaconDb ): AsyncIterable { // Non-finalized range of blobs - const {startSlot, count} = validateBlobSidecarsByRangeRequest(request); + const {startSlot, count} = validateBlobSidecarsByRangeRequest(chain.config, request); const endSlot = startSlot + count; const finalized = db.blobSidecarsArchive; @@ -90,6 +91,7 @@ export function* iterateBlobBytesFromWrapper( } export function validateBlobSidecarsByRangeRequest( + config: BeaconConfig, request: deneb.BlobSidecarsByRangeRequest ): deneb.BlobSidecarsByRangeRequest { const {startSlot} = request; @@ -103,8 +105,10 @@ export function validateBlobSidecarsByRangeRequest( throw new ResponseError(RespStatus.INVALID_REQUEST, "startSlot < genesis"); } - if (count > MAX_REQUEST_BLOCKS_DENEB) { - count = MAX_REQUEST_BLOCKS_DENEB; + const maxRequestBlobSidecars = config.getMaxRequestBlobSidecars(config.getForkName(startSlot)); + + if (count > maxRequestBlobSidecars) { + count = maxRequestBlobSidecars; } return {startSlot, count}; diff --git a/packages/beacon-node/src/network/reqresp/rateLimit.ts b/packages/beacon-node/src/network/reqresp/rateLimit.ts index ce8a996a49a..7553310b96d 100644 --- a/packages/beacon-node/src/network/reqresp/rateLimit.ts +++ b/packages/beacon-node/src/network/reqresp/rateLimit.ts @@ -1,10 +1,10 @@ -import {ChainConfig} from "@lodestar/config"; +import {BeaconConfig} from "@lodestar/config"; import {MAX_REQUEST_BLOCKS, MAX_REQUEST_LIGHT_CLIENT_UPDATES} from "@lodestar/params"; import {InboundRateLimitQuota} from "@lodestar/reqresp"; import {ReqRespMethod, RequestBodyByMethod} from "./types.js"; import {requestSszTypeByMethod} from "./types.js"; -export const rateLimitQuotas: (config: ChainConfig) => Record = (config) => ({ +export const rateLimitQuotas: (config: BeaconConfig) => Record = (config) => ({ [ReqRespMethod.Status]: { // Rationale: https://github.com/sigp/lighthouse/blob/bf533c8e42cc73c35730e285c21df8add0195369/beacon_node/lighthouse_network/src/rpc/mod.rs#L118-L130 byPeer: {quota: 5, quotaTimeMs: 15_000}, @@ -67,7 +67,7 @@ export const rateLimitQuotas: (config: ChainConfig) => Record( - config: ChainConfig, + config: BeaconConfig, method: T, fn: (req: RequestBodyByMethod[T]) => number ): (reqData: Uint8Array) => number { diff --git a/packages/beacon-node/src/network/reqresp/types.ts b/packages/beacon-node/src/network/reqresp/types.ts index ac14b24eaf2..476262bc51a 100644 --- a/packages/beacon-node/src/network/reqresp/types.ts +++ b/packages/beacon-node/src/network/reqresp/types.ts @@ -1,5 +1,5 @@ import {Type} from "@chainsafe/ssz"; -import {ChainConfig} from "@lodestar/config"; +import {BeaconConfig} from "@lodestar/config"; import {ForkLightClient, ForkName, isForkLightClient} from "@lodestar/params"; import {Protocol, ProtocolHandler, ReqRespRequest} from "@lodestar/reqresp"; import { @@ -72,7 +72,7 @@ type ResponseBodyByMethod = { /** Request SSZ type for each method and ForkName */ // TODO Electra: Currently setting default fork to deneb because not every caller of requestSszTypeByMethod can provide fork info export const requestSszTypeByMethod: ( - config: ChainConfig, + config: BeaconConfig, fork?: ForkName ) => { [K in ReqRespMethod]: RequestBodyByMethod[K] extends null ? null : Type; diff --git a/packages/beacon-node/src/util/types.ts b/packages/beacon-node/src/util/types.ts index 2a99fc34bcc..4133d6db102 100644 --- a/packages/beacon-node/src/util/types.ts +++ b/packages/beacon-node/src/util/types.ts @@ -1,6 +1,6 @@ import {ContainerType, ListCompositeType, ValueOf} from "@chainsafe/ssz"; -import {ChainConfig} from "@lodestar/config"; -import {ForkName, isForkPostElectra} from "@lodestar/params"; +import {BeaconConfig} from "@lodestar/config"; +import {ForkName} from "@lodestar/params"; import {ssz} from "@lodestar/types"; // Misc SSZ types used only in the beacon-node package, no need to upstream to types @@ -15,9 +15,6 @@ export const signedBLSToExecutionChangeVersionedType = new ContainerType( ); export type SignedBLSToExecutionChangeVersioned = ValueOf; -export const BlobSidecarsByRootRequestType = (fork: ForkName, config: ChainConfig) => - new ListCompositeType( - ssz.deneb.BlobIdentifier, - isForkPostElectra(fork) ? config.MAX_REQUEST_BLOB_SIDECARS_ELECTRA : config.MAX_REQUEST_BLOB_SIDECARS - ); +export const BlobSidecarsByRootRequestType = (fork: ForkName, config: BeaconConfig) => + 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 6540106bb88..9551627188d 100644 --- a/packages/config/src/forkConfig/index.ts +++ b/packages/config/src/forkConfig/index.ts @@ -133,5 +133,8 @@ export function createForkConfig(config: ChainConfig): ForkConfig { 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 420cd6bcd24..c7874482770 100644 --- a/packages/config/src/forkConfig/types.ts +++ b/packages/config/src/forkConfig/types.ts @@ -41,4 +41,6 @@ export type ForkConfig = { getBlobsForkTypes(slot: Slot): SSZTypesFor; /** Get max blobs per block by hard-fork */ getMaxBlobsPerBlock(fork: ForkName): number; + /** Get max request blob sidecars by hard-fork */ + getMaxRequestBlobSidecars(fork: ForkName): number; };