Skip to content

Commit d963bc3

Browse files
authored
Use MAX_BLOBS_PER_BLOCK_ELECTRA from config in sync manager (#6963)
Since v1.5.0-alpha.4 the `MAX_BLOBS_PER_BLOCK` are part of config and are not preset constants anymore. This means we have to pass it into the sync manager so it can use the configured value.
1 parent bbf6484 commit d963bc3

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

beacon_chain/nimbus_beacon_node.nim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,9 @@ proc initFullNode(
507507
{}
508508
syncManager = newSyncManager[Peer, PeerId](
509509
node.network.peerPool,
510-
dag.cfg.DENEB_FORK_EPOCH, dag.cfg.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS,
510+
dag.cfg.DENEB_FORK_EPOCH,
511+
dag.cfg.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS,
512+
dag.cfg.MAX_BLOBS_PER_BLOCK_ELECTRA,
511513
SyncQueueKind.Forward, getLocalHeadSlot,
512514
getLocalWallSlot, getFirstSlotAtFinalizedEpoch, getBackfillSlot,
513515
getFrontfillSlot, isWithinWeakSubjectivityPeriod,
@@ -516,7 +518,9 @@ proc initFullNode(
516518
flags = syncManagerFlags)
517519
backfiller = newSyncManager[Peer, PeerId](
518520
node.network.peerPool,
519-
dag.cfg.DENEB_FORK_EPOCH, dag.cfg.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS,
521+
dag.cfg.DENEB_FORK_EPOCH,
522+
dag.cfg.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS,
523+
dag.cfg.MAX_BLOBS_PER_BLOCK_ELECTRA,
520524
SyncQueueKind.Backward, getLocalHeadSlot,
521525
getLocalWallSlot, getFirstSlotAtFinalizedEpoch, getBackfillSlot,
522526
getFrontfillSlot, isWithinWeakSubjectivityPeriod,
@@ -530,7 +534,9 @@ proc initFullNode(
530534
getLocalWallSlot()
531535
untrustedManager = newSyncManager[Peer, PeerId](
532536
node.network.peerPool,
533-
dag.cfg.DENEB_FORK_EPOCH, dag.cfg.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS,
537+
dag.cfg.DENEB_FORK_EPOCH,
538+
dag.cfg.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS,
539+
dag.cfg.MAX_BLOBS_PER_BLOCK_ELECTRA,
534540
SyncQueueKind.Backward, getLocalHeadSlot,
535541
getLocalWallSlot, getFirstSlotAtFinalizedEpoch, getUntrustedBackfillSlot,
536542
getFrontfillSlot, isWithinWeakSubjectivityPeriod,

beacon_chain/sync/sync_manager.nim

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type
5757
pool: PeerPool[A, B]
5858
DENEB_FORK_EPOCH: Epoch
5959
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: uint64
60+
MAX_BLOBS_PER_BLOCK_ELECTRA: uint64
6061
responseTimeout: chronos.Duration
6162
maxHeadAge: uint64
6263
isWithinWeakSubjectivityPeriod: GetBoolCallback
@@ -142,6 +143,7 @@ proc newSyncManager*[A, B](
142143
pool: PeerPool[A, B],
143144
denebEpoch: Epoch,
144145
minEpochsForBlobSidecarsRequests: uint64,
146+
maxBlobsPerBlockElectra: uint64,
145147
direction: SyncQueueKind,
146148
getLocalHeadSlotCb: GetSlotCallback,
147149
getLocalWallSlotCb: GetSlotCallback,
@@ -170,6 +172,7 @@ proc newSyncManager*[A, B](
170172
pool: pool,
171173
DENEB_FORK_EPOCH: denebEpoch,
172174
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: minEpochsForBlobSidecarsRequests,
175+
MAX_BLOBS_PER_BLOCK_ELECTRA: maxBlobsPerBlockElectra,
173176
getLocalHeadSlot: getLocalHeadSlotCb,
174177
getLocalWallSlot: getLocalWallSlotCb,
175178
isWithinWeakSubjectivityPeriod: weakSubjectivityPeriodCb,
@@ -230,7 +233,9 @@ proc getBlobSidecars[A, B](man: SyncManager[A, B], peer: A,
230233
sync_ident = man.ident,
231234
topics = "syncman"
232235

233-
blobSidecarsByRange(peer, req.data.slot, req.data.count)
236+
blobSidecarsByRange(
237+
peer, req.data.slot, req.data.count,
238+
maxResponseItems = (req.data.count * man.MAX_BLOBS_PER_BLOCK_ELECTRA).Limit)
234239

235240
proc remainingSlots(man: SyncManager): uint64 =
236241
let
@@ -293,7 +298,8 @@ func checkBlobs(blobs: seq[BlobSidecars]): Result[void, string] =
293298

294299
proc getSyncBlockData*[T](
295300
peer: T,
296-
slot: Slot
301+
slot: Slot,
302+
maxBlobsPerBlockElectra: uint64
297303
): Future[SyncBlockDataRes] {.async: (raises: [CancelledError]).} =
298304
mixin getScore
299305

@@ -353,7 +359,8 @@ proc getSyncBlockData*[T](
353359
peer_score = peer.getScore(),
354360
peer_speed = peer.netKbps(),
355361
topics = "syncman"
356-
let res = await blobSidecarsByRange(peer, slot, 1'u64)
362+
let res = await blobSidecarsByRange(
363+
peer, slot, 1'u64, maxResponseItems = maxBlobsPerBlockElectra.Limit)
357364
if res.isErr():
358365
peer.updateScore(PeerScoreNoValues)
359366
return err(
@@ -449,7 +456,8 @@ proc getSyncBlockData[A, B](
449456

450457
if len(blobData) > 0:
451458
let blobSlots = mapIt(blobData, it[].signed_block_header.message.slot)
452-
checkBlobsResponse(sr, blobSlots).isOkOr:
459+
checkBlobsResponse(
460+
sr, blobSlots, man.MAX_BLOBS_PER_BLOCK_ELECTRA).isOkOr:
453461
peer.updateScore(PeerScoreBadResponse)
454462
return err("Incorrect blobs sequence received, reason: " & $error)
455463

beacon_chain/sync/sync_overseer.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ proc getPeerBlock(
8989
let peer = await overseer.pool.acquire()
9090
try:
9191
let
92-
res = (await getSyncBlockData(peer, slot)).valueOr:
92+
maxBlobs = overseer.consensusManager.dag.cfg.MAX_BLOBS_PER_BLOCK_ELECTRA
93+
res = (await getSyncBlockData(peer, slot, maxBlobs)).valueOr:
9394
return err(error)
9495
blob =
9596
if res.blobs.isSome():

beacon_chain/sync/sync_queue.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,13 +968,15 @@ proc checkResponse*[T](req: SyncRequest[T],
968968

969969
ok()
970970

971-
proc checkBlobsResponse*[T](req: SyncRequest[T],
972-
data: openArray[Slot]): Result[void, cstring] =
971+
proc checkBlobsResponse*[T](
972+
req: SyncRequest[T],
973+
data: openArray[Slot],
974+
maxBlobsPerBlockElectra: uint64): Result[void, cstring] =
973975
if len(data) == 0:
974976
# Impossible to verify empty response.
975977
return ok()
976978

977-
if lenu64(data) > (req.data.count * MAX_BLOBS_PER_BLOCK_ELECTRA):
979+
if lenu64(data) > (req.data.count * maxBlobsPerBlockElectra):
978980
# Number of blobs in response should be less or equal to number of
979981
# requested (blocks * MAX_BLOBS_PER_BLOCK_ELECTRA).
980982
# NOTE: This is not strict check, proper check will be done in blobs
@@ -991,7 +993,7 @@ proc checkBlobsResponse*[T](req: SyncRequest[T],
991993
return err("Incorrect order")
992994
if slot == pslot:
993995
inc(counter)
994-
if counter > MAX_BLOBS_PER_BLOCK_ELECTRA:
996+
if counter > maxBlobsPerBlockElectra:
995997
# NOTE: This is not strict check, proper check will be done in blobs
996998
# validation.
997999
return err("Number of blobs in the block exceeds the limit")

tests/test_sync_manager.nim

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,14 +1363,21 @@ suite "SyncManager test suite":
13631363
checkResponse(r3, @[Slot(13), Slot(13)]).isOk() == false
13641364

13651365
test "[SyncQueue] checkBlobsResponse() test":
1366+
const maxBlobsPerBlockElectra = 9
1367+
1368+
proc checkBlobsResponse[T](
1369+
req: SyncRequest[T],
1370+
data: openArray[Slot]): Result[void, cstring] =
1371+
checkBlobsResponse(req, data, maxBlobsPerBlockElectra)
1372+
13661373
let
13671374
r1 = SyncRequest[SomeTPeer](data: SyncRange.init(Slot(11), 1'u64))
13681375
r2 = SyncRequest[SomeTPeer](data: SyncRange.init(Slot(11), 2'u64))
13691376
r3 = SyncRequest[SomeTPeer](data: SyncRange.init(Slot(11), 3'u64))
13701377

1371-
d1 = Slot(11).repeat(MAX_BLOBS_PER_BLOCK_ELECTRA)
1372-
d2 = Slot(12).repeat(MAX_BLOBS_PER_BLOCK_ELECTRA)
1373-
d3 = Slot(13).repeat(MAX_BLOBS_PER_BLOCK_ELECTRA)
1378+
d1 = Slot(11).repeat(maxBlobsPerBlockElectra)
1379+
d2 = Slot(12).repeat(maxBlobsPerBlockElectra)
1380+
d3 = Slot(13).repeat(maxBlobsPerBlockElectra)
13741381

13751382
check:
13761383
checkBlobsResponse(r1, [Slot(11)]).isOk() == true

0 commit comments

Comments
 (0)