Skip to content

Commit 71f84e7

Browse files
committed
Missing sidecars helper functions.
1 parent 02d9e44 commit 71f84e7

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

beacon_chain/consensus_object_pools/blob_quarantine.nim

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,28 @@ func fetchMissingSidecars*(
619619
res.add(BlobIdentifier(block_root: blockRoot, index: BlobIndex(bindex)))
620620
res
621621

622+
func getMissingSidecarIndices*(
623+
quarantine: BlobQuarantine,
624+
blockRoot: Eth2Digest,
625+
blck: deneb.SignedBeaconBlock | electra.SignedBeaconBlock
626+
): seq[BlobIndex] =
627+
## Function returns sequence of BlobIndex for blobs which are missing for
628+
## block root ``blockRoot`` and block ``blck``.
629+
var res: seq[BlobIndex]
630+
let record = quarantine.roots.getOrDefault(blockRoot)
631+
632+
let commitmentsCount = len(blck.message.body.blob_kzg_commitments)
633+
if (commitmentsCount == 0) or (record.count == commitmentsCount):
634+
# Fast-path if ``blck`` does not have any blobs or if quarantine's record
635+
# holds enough blobs.
636+
return res
637+
638+
for bindex in 0 ..< commitmentsCount:
639+
let index = quarantine.getIndex(BlobIndex(bindex))
640+
if len(record.sidecars) == 0 or record.sidecars[index].isEmpty():
641+
res.add(BlobIndex(bindex))
642+
res
643+
622644
func fetchMissingSidecars*(
623645
quarantine: ColumnQuarantine,
624646
blockRoot: Eth2Digest,
@@ -696,6 +718,40 @@ func fetchMissingSidecars*(
696718
DataColumnsByRootIdentifier(
697719
block_root: blockRoot, indices: DataColumnIndices(res))
698720

721+
func getMissingSidecarIndices*(
722+
quarantine: ColumnQuarantine,
723+
blockRoot: Eth2Digest,
724+
blck: fulu.SignedBeaconBlock | gloas.SignedBeaconBlock,
725+
): seq[ColumnIndex] =
726+
var res: seq[ColumnIndex]
727+
let record = quarantine.roots.getOrDefault(blockRoot)
728+
729+
if len(blck.message.body.blob_kzg_commitments) == 0:
730+
# Fast-path if block does not have any columns
731+
return res
732+
733+
let supernode = (len(quarantine.custodyColumns) == NUMBER_OF_COLUMNS)
734+
if supernode:
735+
if len(record.sidecars) > NUMBER_OF_COLUMNS div 2:
736+
return res
737+
if len(record.sidecars) == 0:
738+
for index in 0 ..< NUMBER_OF_COLUMNS:
739+
res.add(ColumnIndex(index))
740+
else:
741+
for index in 0 ..< NUMBER_OF_COLUMNS:
742+
if record.sidecars[index].isEmpty():
743+
res.add(ColumnIndex(index))
744+
else:
745+
if len(record.sidecars) == 0:
746+
for column in quarantine.custodyMap.items():
747+
res.add(column)
748+
else:
749+
for column in quarantine.custodyMap.items():
750+
let index = quarantine.getIndex(column)
751+
if (index == -1) or (record.sidecars[index].isEmpty()):
752+
res.add(column)
753+
res
754+
699755
proc pruneAfterFinalization*(
700756
quarantine: var BlobQuarantine,
701757
epoch: Epoch,

beacon_chain/sync/sync_overseer2.nim

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,41 @@ func decreaseBlocksCount(blocksCount: var int) =
152152
return
153153
blocksCount = blocksCount div 2
154154

155+
func getMissingSidecarsLog(
156+
overseer: SyncOverseerRef2,
157+
blck: ref ForkedSignedBeaconBlock,
158+
fullSupernodeLog = false
159+
): string =
160+
var res = "["
161+
withBlck(blck[]):
162+
when consensusFork < ConsensusFork.Deneb:
163+
discard
164+
elif consensusFork in [ConsensusFork.Deneb, ConsensusFork.Electra]:
165+
let indices =
166+
overseer.blobQuarantine[].getMissingSidecarIndices(
167+
forkyBlck.root, forkyBlck)
168+
if len(indices) > 0:
169+
res.add(indices.mapIt($uint8(it)).join(","))
170+
elif consensusFork == ConsensusFork.Fulu:
171+
let indices =
172+
overseer.columnQuarantine[].getMissingSidecarIndices(
173+
forkyBlck.root, forkyBlck)
174+
if len(indices) > 0:
175+
if overseer.config.peerdasSupernode:
176+
if fullSupernodeLog:
177+
res.add(indices.mapIt($uint8(it)).join(","))
178+
else:
179+
let superCount = (NUMBER_OF_COLUMNS div 2) - 1
180+
res.add($len(indices))
181+
res.add(" of ")
182+
res.add($superCount)
183+
else:
184+
res.add(indices.mapIt($uint8(it)).join(","))
185+
else:
186+
raiseAssert "Unsupported fork"
187+
res.add("]")
188+
res
189+
155190
func consensusForkAtEpoch(
156191
overseer: SyncOverseerRef2,
157192
epoch: Epoch

0 commit comments

Comments
 (0)