From e51c5ec78327b043e025b093fbaf64f4321d60a4 Mon Sep 17 00:00:00 2001 From: tersec Date: Thu, 11 Apr 2024 09:31:39 +0000 Subject: [PATCH] add Electra blob support to block/blob quarantines, block processor, and request manager (#6201) --- .../blob_quarantine.nim | 11 ++--- .../block_quarantine.nim | 24 ++++++----- .../gossip_processing/block_processor.nim | 3 +- .../gossip_processing/eth2_processor.nim | 10 +---- beacon_chain/sync/request_manager.nim | 43 ++++++++++--------- 5 files changed, 46 insertions(+), 45 deletions(-) diff --git a/beacon_chain/consensus_object_pools/blob_quarantine.nim b/beacon_chain/consensus_object_pools/blob_quarantine.nim index 346b9d239..da58361d8 100644 --- a/beacon_chain/consensus_object_pools/blob_quarantine.nim +++ b/beacon_chain/consensus_object_pools/blob_quarantine.nim @@ -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.. 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 diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index 31a9e5277..d149098a0 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -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: diff --git a/beacon_chain/gossip_processing/eth2_processor.nim b/beacon_chain/gossip_processing/eth2_processor.nim index 2047bd23d..c2bfafb05 100644 --- a/beacon_chain/gossip_processing/eth2_processor.nim +++ b/beacon_chain/gossip_processing/eth2_processor.nim @@ -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, diff --git a/beacon_chain/sync/request_manager.nim b/beacon_chain/sync/request_manager.nim index 3e83bb383..79767e553 100644 --- a/beacon_chain/sync/request_manager.nim +++ b/beacon_chain/sync/request_manager.nim @@ -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