Skip to content

Commit d74a613

Browse files
authored
Allow runtime config of MAX_REQUEST_BLOB_SIDECARS (#6964)
With `MAX_REQUEST_BLOB_SIDECARS` becoming dynamic, we can no longer use the value from network config in the `List` datatype and have to rely on an upper bound constant for the maximum supported value instead and then check the actual length at runtime. As a side effect, this also extends `BlobIdentifierList` to use the correct electra specific request limit instead of the Deneb constant.
1 parent d963bc3 commit d74a613

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

beacon_chain/spec/datatypes/constants.nim

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,3 @@ const
9393

9494
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-beta.0/specs/electra/beacon-chain.md#execution-1
9595
MAX_BLOBS_PER_BLOCK_ELECTRA* = 9'u64
96-
97-
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/electra/p2p-interface.md#configuration
98-
MAX_REQUEST_BLOB_SIDECARS_ELECTRA* =
99-
MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK_ELECTRA

beacon_chain/spec/network.nim

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ const
3030
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.9/specs/altair/light-client/p2p-interface.md#configuration
3131
MAX_REQUEST_LIGHT_CLIENT_UPDATES* = 128
3232

33-
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/deneb/p2p-interface.md#configuration
34-
MAX_REQUEST_BLOB_SIDECARS*: uint64 =
35-
MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK
36-
3733
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/fulu/p2p-interface.md#configuration
3834
MAX_REQUEST_DATA_COLUMN_SIDECARS*: uint64 =
3935
MAX_REQUEST_BLOCKS_DENEB * NUMBER_OF_COLUMNS

beacon_chain/spec/presets.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const
3232
MESSAGE_DOMAIN_VALID_SNAPPY*: array[4, byte] = [0x01, 0x00, 0x00, 0x00]
3333

3434
MAX_SUPPORTED_BLOBS_PER_BLOCK*: uint64 = 9 # revisit getShortMap(Blobs) if >9
35+
MAX_SUPPORTED_REQUEST_BLOB_SIDECARS*: uint64 = 1152
3536

3637
type
3738
Version* = distinct array[4, byte]
@@ -869,15 +870,14 @@ proc readRuntimeConfig*(
869870
checkCompatibility ATTESTATION_SUBNET_PREFIX_BITS
870871

871872
checkCompatibility MAX_REQUEST_BLOCKS_DENEB
872-
checkCompatibility MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK,
873-
"MAX_REQUEST_BLOB_SIDECARS"
874873
checkCompatibility BLOB_SIDECAR_SUBNET_COUNT
875874
checkCompatibility MAX_BLOBS_PER_BLOCK_ELECTRA
876-
checkCompatibility MAX_REQUEST_BLOB_SIDECARS_ELECTRA
877875

878876
for suffix in ["", "_ELECTRA"]:
879877
checkCompatibility MAX_SUPPORTED_BLOBS_PER_BLOCK,
880878
"MAX_BLOBS_PER_BLOCK" & suffix, `<=`
879+
checkCompatibility MAX_SUPPORTED_REQUEST_BLOB_SIDECARS,
880+
"MAX_REQUEST_BLOB_SIDECARS" & suffix, `<=`
881881

882882
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-beta.0/specs/phase0/fork-choice.md#configuration
883883
# Isn't being used as a preset in the usual way: at any time, there's one correct value

beacon_chain/sync/sync_manager.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type
9292
BeaconBlocksRes =
9393
NetRes[List[ref ForkedSignedBeaconBlock, Limit MAX_REQUEST_BLOCKS]]
9494
BlobSidecarsRes =
95-
NetRes[List[ref BlobSidecar, Limit(MAX_REQUEST_BLOB_SIDECARS_ELECTRA)]]
95+
NetRes[List[ref BlobSidecar, Limit(MAX_SUPPORTED_REQUEST_BLOB_SIDECARS)]]
9696

9797
SyncBlockData* = object
9898
blocks*: seq[ref ForkedSignedBeaconBlock]

beacon_chain/sync/sync_protocol.nim

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ type
3737
slot: Slot
3838

3939
BlockRootsList* = List[Eth2Digest, Limit MAX_REQUEST_BLOCKS]
40-
BlobIdentifierList* = List[BlobIdentifier, Limit (MAX_REQUEST_BLOB_SIDECARS)]
41-
DataColumnIdentifierList* = List[DataColumnIdentifier, Limit (MAX_REQUEST_DATA_COLUMN_SIDECARS)]
40+
BlobIdentifierList* = List[
41+
BlobIdentifier, Limit MAX_SUPPORTED_REQUEST_BLOB_SIDECARS]
42+
DataColumnIdentifierList* = List[
43+
DataColumnIdentifier, Limit (MAX_REQUEST_DATA_COLUMN_SIDECARS)]
4244

4345
proc readChunkPayload*(
4446
conn: Connection, peer: Peer, MsgType: type (ref ForkedSignedBeaconBlock)):
@@ -108,11 +110,13 @@ proc readChunkPayload*(
108110

109111
template getBlobSidecarsByRoot(
110112
versionNumber: static string, peer: Peer, dag: ChainDAGRef, response: auto,
111-
blobIds: BlobIdentifierList) =
113+
blobIds: BlobIdentifierList, maxReqSidecars: uint64) =
112114
trace "got v" & versionNumber & " blobs range request",
113115
peer, len = blobIds.len
114116
if blobIds.len == 0:
115117
raise newException(InvalidInputsError, "No blobs requested")
118+
if blobIds.lenu64 > maxReqSidecars:
119+
raise newException(InvalidInputsError, "Exceeding blob request limit")
116120

117121
let count = blobIds.len
118122

@@ -145,8 +149,8 @@ template getBlobSidecarsByRoot(
145149

146150
template getBlobSidecarsByRange(
147151
versionNumber: static string, peer: Peer, dag: ChainDAGRef, response: auto,
148-
startSlot: Slot, reqCount: uint64, blobsPerBlock: static uint64,
149-
maxReqSidecars: static uint64) =
152+
startSlot: Slot, reqCount: uint64, blobsPerBlock: uint64,
153+
maxReqSidecars: uint64) =
150154
trace "got v" & versionNumber & " blobs range request",
151155
peer, startSlot, count = reqCount
152156
if reqCount == 0:
@@ -161,9 +165,9 @@ template getBlobSidecarsByRange(
161165
if startSlot.epoch < epochBoundary:
162166
raise newException(ResourceUnavailableError, BlobsOutOfRange)
163167

164-
var blockIds: array[int(maxReqSidecars), BlockId]
168+
var blockIds: array[MAX_SUPPORTED_REQUEST_BLOB_SIDECARS.int, BlockId]
165169
let
166-
count = int min(reqCount, blockIds.lenu64)
170+
count = int min(reqCount, maxReqSidecars)
167171
endIndex = count - 1
168172
startIndex =
169173
dag.getBlockRange(startSlot, blockIds.toOpenArray(0, endIndex))
@@ -334,7 +338,7 @@ p2pProtocol BeaconSync(version = 1,
334338
peer: Peer,
335339
blobIds: BlobIdentifierList,
336340
response: MultipleChunksResponse[
337-
ref BlobSidecar, Limit(MAX_REQUEST_BLOB_SIDECARS_ELECTRA)])
341+
ref BlobSidecar, Limit(MAX_SUPPORTED_REQUEST_BLOB_SIDECARS)])
338342
{.async, libp2pProtocol("blob_sidecars_by_root", 1).} =
339343
# TODO Semantically, this request should return a non-ref, but doing so
340344
# runs into extreme inefficiency due to the compiler introducing
@@ -348,15 +352,17 @@ p2pProtocol BeaconSync(version = 1,
348352
# client call that returns `seq[ref BlobSidecar]` will
349353
# will be generated by the libp2p macro - we guarantee that seq items
350354
# are `not-nil` in the implementation
351-
getBlobSidecarsByRoot("1", peer, peer.networkState.dag, response, blobIds)
355+
getBlobSidecarsByRoot(
356+
"1", peer, peer.networkState.dag, response, blobIds,
357+
peer.networkState.dag.cfg.MAX_REQUEST_BLOB_SIDECARS_ELECTRA)
352358

353359
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/deneb/p2p-interface.md#blobsidecarsbyrange-v1
354360
proc blobSidecarsByRange(
355361
peer: Peer,
356362
startSlot: Slot,
357363
reqCount: uint64,
358364
response: MultipleChunksResponse[
359-
ref BlobSidecar, Limit(MAX_REQUEST_BLOB_SIDECARS_ELECTRA)])
365+
ref BlobSidecar, Limit(MAX_SUPPORTED_REQUEST_BLOB_SIDECARS)])
360366
{.async, libp2pProtocol("blob_sidecars_by_range", 1).} =
361367
# TODO This code is more complicated than it needs to be, since the type
362368
# of the multiple chunks response is not actually used in this server
@@ -368,7 +374,8 @@ p2pProtocol BeaconSync(version = 1,
368374
# are `not-nil` in the implementation
369375
getBlobSidecarsByRange(
370376
"1", peer, peer.networkState.dag, response, startSlot, reqCount,
371-
MAX_BLOBS_PER_BLOCK_ELECTRA, MAX_REQUEST_BLOB_SIDECARS_ELECTRA)
377+
peer.networkState.dag.cfg.MAX_BLOBS_PER_BLOCK_ELECTRA,
378+
peer.networkState.dag.cfg.MAX_REQUEST_BLOB_SIDECARS_ELECTRA)
372379

373380
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/fulu/p2p-interface.md#datacolumnsidecarsbyroot-v1
374381
proc dataColumnSidecarsByRoot(
@@ -420,7 +427,7 @@ p2pProtocol BeaconSync(version = 1,
420427
debug "Data column root request done",
421428
peer, roots = colIds.len, count, found
422429

423-
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/fulu/p2p-interface.md#datacolumnsidecarsbyrange-v1
430+
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/fulu/p2p-interface.md#datacolumnsidecarsbyrange-v1
424431
proc dataColumnSidecarsByRange(
425432
peer: Peer,
426433
startSlot: Slot,

0 commit comments

Comments
 (0)