add Electra blob support to block/blob quarantines, block processor, and request manager (#6201)

This commit is contained in:
tersec 2024-04-11 09:31:39 +00:00 committed by GitHub
parent 205d63a897
commit e51c5ec783
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 45 deletions

View File

@ -71,7 +71,8 @@ func hasBlob*(
func popBlobs*(
quarantine: var BlobQuarantine, digest: Eth2Digest,
blck: deneb.SignedBeaconBlock): seq[ref BlobSidecar] =
blck: deneb.SignedBeaconBlock | electra.SignedBeaconBlock):
seq[ref BlobSidecar] =
var r: seq[ref BlobSidecar] = @[]
for idx, kzg_commitment in blck.message.body.blob_kzg_commitments:
var b: ref BlobSidecar
@ -79,15 +80,15 @@ func popBlobs*(
r.add(b)
r
func hasBlobs*(quarantine: BlobQuarantine, blck: deneb.SignedBeaconBlock):
bool =
func hasBlobs*(quarantine: BlobQuarantine,
blck: deneb.SignedBeaconBlock | electra.SignedBeaconBlock): bool =
for idx, kzg_commitment in blck.message.body.blob_kzg_commitments:
if (blck.root, BlobIndex idx, kzg_commitment) notin quarantine.blobs:
return false
true
func blobFetchRecord*(quarantine: BlobQuarantine, blck: deneb.SignedBeaconBlock):
BlobFetchRecord =
func blobFetchRecord*(quarantine: BlobQuarantine,
blck: deneb.SignedBeaconBlock | electra.SignedBeaconBlock): BlobFetchRecord =
var indices: seq[BlobIndex]
for i in 0..<len(blck.message.body.blob_kzg_commitments):
let idx = BlobIndex(i)

View File

@ -52,7 +52,7 @@ type
## below) - if so, upon resolving the parent, it should be
## added to the blobless table, after verifying its signature.
blobless*: OrderedTable[Eth2Digest, deneb.SignedBeaconBlock]
blobless*: OrderedTable[Eth2Digest, ForkedSignedBeaconBlock]
## Blocks that we don't have blobs for. When we have received
## all blobs for this block, we can proceed to resolving the
## block as well. A blobless block inserted into this table must
@ -181,13 +181,15 @@ func removeUnviableOrphanTree(
func removeUnviableBloblessTree(
quarantine: var Quarantine,
toCheck: var seq[Eth2Digest],
tbl: var OrderedTable[Eth2Digest, deneb.SignedBeaconBlock]) =
tbl: var OrderedTable[Eth2Digest, ForkedSignedBeaconBlock]) =
var
toRemove: seq[Eth2Digest] # Can't modify while iterating
while toCheck.len > 0:
let root = toCheck.pop()
for k, v in tbl.mpairs():
let blockRoot = v.message.parent_root
let blockRoot =
withBlck(v):
forkyBlck.message.parent_root
if blockRoot == root:
toCheck.add(k)
toRemove.add(k)
@ -226,8 +228,9 @@ func cleanupBlobless(quarantine: var Quarantine, finalizedSlot: Slot) =
var toDel: seq[Eth2Digest]
for k, v in quarantine.blobless:
if not isViable(finalizedSlot, v.message.slot):
toDel.add k
withBlck(v):
if not isViable(finalizedSlot, forkyBlck.message.slot):
toDel.add k
for k in toDel:
quarantine.addUnviable k
@ -300,7 +303,7 @@ iterator pop*(quarantine: var Quarantine, root: Eth2Digest):
proc addBlobless*(
quarantine: var Quarantine, finalizedSlot: Slot,
signedBlock: deneb.SignedBeaconBlock): bool =
signedBlock: deneb.SignedBeaconBlock | electra.SignedBeaconBlock): bool =
if not isViable(finalizedSlot, signedBlock.message.slot):
quarantine.addUnviable(signedBlock.root)
@ -316,19 +319,20 @@ proc addBlobless*(
quarantine.blobless.del oldest_blobless_key
debug "block quarantine: Adding blobless", blck = shortLog(signedBlock)
quarantine.blobless[signedBlock.root] = signedBlock
quarantine.blobless[signedBlock.root] =
ForkedSignedBeaconBlock.init(signedBlock)
quarantine.missing.del(signedBlock.root)
true
func popBlobless*(
quarantine: var Quarantine,
root: Eth2Digest): Opt[ForkedSignedBeaconBlock] =
var blck: deneb.SignedBeaconBlock
var blck: ForkedSignedBeaconBlock
if quarantine.blobless.pop(root, blck):
Opt.some(ForkedSignedBeaconBlock.init(blck))
Opt.some(blck)
else:
Opt.none(ForkedSignedBeaconBlock)
iterator peekBlobless*(quarantine: var Quarantine): deneb.SignedBeaconBlock =
iterator peekBlobless*(quarantine: var Quarantine): ForkedSignedBeaconBlock =
for k, v in quarantine.blobless.mpairs():
yield v

View File

@ -768,8 +768,7 @@ proc storeBlock(
quarantined = shortLog(quarantined.root)
withBlck(quarantined):
debugRaiseAssert "electra has blobs"
when typeof(forkyBlck).kind < ConsensusFork.Deneb or typeof(forkyBlck).kind == ConsensusFork.Electra:
when typeof(forkyBlck).kind < ConsensusFork.Deneb:
self[].enqueueBlock(
MsgSource.gossip, quarantined, Opt.none(BlobSidecars))
else:

View File

@ -241,11 +241,8 @@ proc processSignedBeaconBlock*(
# propagation of seemingly good blocks
trace "Block validated"
debugRaiseAssert "electra has blobs"
let blobs =
when typeof(signedBlock).kind >= ConsensusFork.Electra:
Opt.none(BlobSidecars)
elif typeof(signedBlock).kind >= ConsensusFork.Deneb:
when typeof(signedBlock).kind >= ConsensusFork.Deneb:
if self.blobQuarantine[].hasBlobs(signedBlock):
Opt.some(self.blobQuarantine[].popBlobs(signedBlock.root, signedBlock))
else:
@ -307,10 +304,7 @@ proc processBlobSidecar*(
if (let o = self.quarantine[].popBlobless(block_root); o.isSome):
let blobless = o.unsafeGet()
withBlck(blobless):
when consensusFork >= ConsensusFork.Electra:
debugRaiseAssert "no electra here yet"
let x = 5
elif consensusFork >= ConsensusFork.Deneb:
when consensusFork >= ConsensusFork.Deneb:
if self.blobQuarantine[].hasBlobs(forkyBlck):
self.blockProcessor[].enqueueBlock(
MsgSource.gossip, blobless,

View File

@ -303,27 +303,30 @@ proc getMissingBlobs(rman: RequestManager): seq[BlobIdentifier] =
fetches: seq[BlobIdentifier]
ready: seq[Eth2Digest]
for blobless in rman.quarantine[].peekBlobless():
# give blobs a chance to arrive over gossip
if blobless.message.slot == wallSlot and delay < waitDur:
debug "Not handling missing blobs early in slot"
continue
withBlck(blobless):
when consensusFork >= ConsensusFork.Deneb:
# give blobs a chance to arrive over gossip
if forkyBlck.message.slot == wallSlot and delay < waitDur:
debug "Not handling missing blobs early in slot"
continue
if not rman.blobQuarantine[].hasBlobs(forkyBlck):
let missing = rman.blobQuarantine[].blobFetchRecord(forkyBlck)
if len(missing.indices) == 0:
warn "quarantine missing blobs, but missing indices is empty",
blk=blobless.root,
commitments=len(forkyBlck.message.body.blob_kzg_commitments)
for idx in missing.indices:
let id = BlobIdentifier(block_root: blobless.root, index: idx)
if id notin fetches:
fetches.add(id)
else:
# this is a programming error should it occur.
warn "missing blob handler found blobless block with all blobs",
blk=blobless.root,
commitments=len(forkyBlck.message.body.blob_kzg_commitments)
ready.add(blobless.root)
if not rman.blobQuarantine[].hasBlobs(blobless):
let missing = rman.blobQuarantine[].blobFetchRecord(blobless)
if len(missing.indices) == 0:
warn "quarantine missing blobs, but missing indices is empty",
blk=blobless.root,
commitments=len(blobless.message.body.blob_kzg_commitments)
for idx in missing.indices:
let id = BlobIdentifier(block_root: blobless.root, index: idx)
if id notin fetches:
fetches.add(id)
else:
# this is a programming error should it occur.
warn "missing blob handler found blobless block with all blobs",
blk=blobless.root,
commitments=len(blobless.message.body.blob_kzg_commitments)
ready.add(blobless.root)
for root in ready:
let blobless = rman.quarantine[].popBlobless(root).valueOr:
continue