Skip to content

Commit d01bb65

Browse files
committed
Missing sidecars helper functions.
1 parent 53a24dd commit d01bb65

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
@@ -617,6 +617,28 @@ func fetchMissingSidecars*(
617617
res.add(BlobIdentifier(block_root: blockRoot, index: BlobIndex(bindex)))
618618
res
619619

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

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