Skip to content

Commit

Permalink
Add helper to get max request blob sidecars by fork
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Jan 16, 2025
1 parent bb0a4c4 commit 2922390
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {BeaconConfig} from "@lodestar/config";
import {BLOBSIDECAR_FIXED_SIZE, GENESIS_SLOT, isForkPostElectra} from "@lodestar/params";
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";
Expand Down Expand Up @@ -105,9 +105,7 @@ export function validateBlobSidecarsByRangeRequest(
throw new ResponseError(RespStatus.INVALID_REQUEST, "startSlot < genesis");
}

const maxRequestBlobSidecars = isForkPostElectra(config.getForkName(startSlot))
? config.MAX_REQUEST_BLOB_SIDECARS_ELECTRA
: config.MAX_REQUEST_BLOB_SIDECARS;
const maxRequestBlobSidecars = config.getMaxRequestBlobSidecars(config.getForkName(startSlot));

if (count > maxRequestBlobSidecars) {
count = maxRequestBlobSidecars;
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/src/network/reqresp/rateLimit.ts
Original file line number Diff line number Diff line change
@@ -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<ReqRespMethod, InboundRateLimitQuota> = (config) => ({
export const rateLimitQuotas: (config: BeaconConfig) => Record<ReqRespMethod, InboundRateLimitQuota> = (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},
Expand Down Expand Up @@ -67,7 +67,7 @@ export const rateLimitQuotas: (config: ChainConfig) => Record<ReqRespMethod, Inb

// Helper to produce a getRequestCount function
function getRequestCountFn<T extends ReqRespMethod>(
config: ChainConfig,
config: BeaconConfig,
method: T,
fn: (req: RequestBodyByMethod[T]) => number
): (reqData: Uint8Array) => number {
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/network/reqresp/types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<RequestBodyByMethod[K]>;
Expand Down
11 changes: 4 additions & 7 deletions packages/beacon-node/src/util/types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,9 +15,6 @@ export const signedBLSToExecutionChangeVersionedType = new ContainerType(
);
export type SignedBLSToExecutionChangeVersioned = ValueOf<typeof signedBLSToExecutionChangeVersionedType>;

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<ReturnType<typeof BlobSidecarsByRootRequestType>>;
3 changes: 3 additions & 0 deletions packages/config/src/forkConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};
}
2 changes: 2 additions & 0 deletions packages/config/src/forkConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ export type ForkConfig = {
getBlobsForkTypes(slot: Slot): SSZTypesFor<ForkBlobs>;
/** Get max blobs per block by hard-fork */
getMaxBlobsPerBlock(fork: ForkName): number;
/** Get max request blob sidecars by hard-fork */
getMaxRequestBlobSidecars(fork: ForkName): number;
};

0 comments on commit 2922390

Please sign in to comment.