ensure blob quarantine insertion always succeeds (#5369)
This commit is contained in:
parent
6daa7542a7
commit
f2d3859d80
|
@ -7,18 +7,16 @@
|
||||||
|
|
||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import ../spec/datatypes/deneb
|
||||||
std/[sequtils, strutils, tables],
|
from std/sequtils import mapIt
|
||||||
../spec/datatypes/deneb
|
from std/strutils import join
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
MaxBlobs = SLOTS_PER_EPOCH * MAX_BLOBS_PER_BLOCK
|
MaxBlobs = SLOTS_PER_EPOCH * MAX_BLOBS_PER_BLOCK
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
BlobQuarantine* = object
|
BlobQuarantine* = object
|
||||||
blobs*: Table[(Eth2Digest, BlobIndex), ref BlobSidecar]
|
blobs*: OrderedTable[(Eth2Digest, BlobIndex), ref BlobSidecar]
|
||||||
BlobFetchRecord* = object
|
BlobFetchRecord* = object
|
||||||
block_root*: Eth2Digest
|
block_root*: Eth2Digest
|
||||||
indices*: seq[BlobIndex]
|
indices*: seq[BlobIndex]
|
||||||
|
@ -31,7 +29,14 @@ func shortLog*(x: seq[BlobFetchRecord]): string =
|
||||||
|
|
||||||
func put*(quarantine: var BlobQuarantine, blobSidecar: ref BlobSidecar) =
|
func put*(quarantine: var BlobQuarantine, blobSidecar: ref BlobSidecar) =
|
||||||
if quarantine.blobs.lenu64 > MaxBlobs:
|
if quarantine.blobs.lenu64 > MaxBlobs:
|
||||||
return
|
# FIFO if full. For example, sync manager and request manager can race to
|
||||||
|
# put blobs in at the same time, so one gets blob insert -> block resolve
|
||||||
|
# -> blob insert sequence, which leaves garbage blobs.
|
||||||
|
var oldest_blob_key: (Eth2Digest, BlobIndex)
|
||||||
|
for k in quarantine.blobs.keys:
|
||||||
|
oldest_blob_key = k
|
||||||
|
break
|
||||||
|
quarantine.blobs.del oldest_blob_key
|
||||||
discard quarantine.blobs.hasKeyOrPut((blobSidecar.block_root,
|
discard quarantine.blobs.hasKeyOrPut((blobSidecar.block_root,
|
||||||
blobSidecar.index), blobSidecar)
|
blobSidecar.index), blobSidecar)
|
||||||
|
|
||||||
|
@ -43,7 +48,7 @@ func blobIndices*(quarantine: BlobQuarantine, digest: Eth2Digest):
|
||||||
r.add(i)
|
r.add(i)
|
||||||
r
|
r
|
||||||
|
|
||||||
func hasBlob*(quarantine: BlobQuarantine, blobSidecar: BlobSidecar) : bool =
|
func hasBlob*(quarantine: BlobQuarantine, blobSidecar: BlobSidecar): bool =
|
||||||
quarantine.blobs.hasKey((blobSidecar.block_root, blobSidecar.index))
|
quarantine.blobs.hasKey((blobSidecar.block_root, blobSidecar.index))
|
||||||
|
|
||||||
func popBlobs*(quarantine: var BlobQuarantine, digest: Eth2Digest):
|
func popBlobs*(quarantine: var BlobQuarantine, digest: Eth2Digest):
|
||||||
|
@ -55,18 +60,6 @@ func popBlobs*(quarantine: var BlobQuarantine, digest: Eth2Digest):
|
||||||
r.add(b)
|
r.add(b)
|
||||||
r
|
r
|
||||||
|
|
||||||
func peekBlobs*(quarantine: var BlobQuarantine, digest: Eth2Digest):
|
|
||||||
seq[ref BlobSidecar] =
|
|
||||||
var r: seq[ref BlobSidecar] = @[]
|
|
||||||
for i in 0..<MAX_BLOBS_PER_BLOCK:
|
|
||||||
quarantine.blobs.withValue((digest, i), value):
|
|
||||||
r.add(value[])
|
|
||||||
r
|
|
||||||
|
|
||||||
func removeBlobs*(quarantine: var BlobQuarantine, digest: Eth2Digest) =
|
|
||||||
for i in 0..<MAX_BLOBS_PER_BLOCK:
|
|
||||||
quarantine.blobs.del((digest, i))
|
|
||||||
|
|
||||||
func hasBlobs*(quarantine: BlobQuarantine, blck: deneb.SignedBeaconBlock):
|
func hasBlobs*(quarantine: BlobQuarantine, blck: deneb.SignedBeaconBlock):
|
||||||
bool =
|
bool =
|
||||||
let idxs = quarantine.blobIndices(blck.root)
|
let idxs = quarantine.blobIndices(blck.root)
|
||||||
|
|
|
@ -305,7 +305,6 @@ proc processSignedBlobSidecar*(
|
||||||
|
|
||||||
debug "Blob validated, putting in blob quarantine"
|
debug "Blob validated, putting in blob quarantine"
|
||||||
self.blobQuarantine[].put(newClone(signedBlobSidecar.message))
|
self.blobQuarantine[].put(newClone(signedBlobSidecar.message))
|
||||||
var toAdd: seq[deneb.SignedBeaconBlock]
|
|
||||||
|
|
||||||
var skippedBlocks = false
|
var skippedBlocks = false
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue