Prune blobs (#5283)

* Prune blobs

* Address review feedback
This commit is contained in:
henridf 2023-08-10 17:15:34 -07:00 committed by GitHub
parent 3c9fc49411
commit 9ceed40090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -795,6 +795,11 @@ proc putBlobSidecar*(
value: BlobSidecar) =
db.blobs.putSZSSZ(blobkey(value.block_root, value.index), value)
proc delBlobSidecar*(
db: BeaconChainDB,
root: Eth2Digest, index: BlobIndex) : bool =
db.blobs.del(blobkey(root, index)).expectDb()
proc updateImmutableValidators*(
db: BeaconChainDB, validators: openArray[Validator]) =
# Must be called before storing a state that references the new validators

View File

@ -1170,6 +1170,25 @@ proc onSlotEnd(node: BeaconNode, slot: Slot) {.async.} =
# This is the last pruning to do as it clears the "needPruning" condition.
node.consensusManager[].pruneStateCachesAndForkChoice()
# prune blobs
let blobPruneEpoch = (slot.epoch -
MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS - 1)
if slot.is_epoch() and blobPruneEpoch >= node.dag.cfg.DENEB_FORK_EPOCH:
var blocks: array[SLOTS_PER_EPOCH.int, BlockId]
var count = 0
let
startIndex = node.dag.getBlockRange(blobPruneEpoch.start_slot, 1,
blocks.toOpenArray(0, SLOTS_PER_EPOCH - 1))
for i in startIndex..<SLOTS_PER_EPOCH:
let blck = node.dag.getForkedBlock(blocks[int(i)]).valueOr: continue
withBlck(blck):
when typeof(blck).toFork() < ConsensusFork.Deneb: continue
else:
for j in 0..len(blck.message.body.blob_kzg_commitments) - 1:
if node.db.delBlobSidecar(blocks[int(i)].root, BlobIndex(j)):
count = count + 1
debug "pruned blobs", count, blobPruneEpoch
if node.config.historyMode == HistoryMode.Prune:
if not (slot + 1).is_epoch():
# The epoch slot already is "heavy" due to the epoch processing, leave