Skip to content

Commit

Permalink
Caplin: Better old-state pruning (#11219)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 authored Jul 18, 2024
1 parent eacf236 commit 5521c78
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cl/phase1/forkchoice/fork_graph/fork_graph_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,23 @@ func (f *forkGraphDisk) MarkHeaderAsInvalid(blockRoot libcommon.Hash) {
f.badBlocks.Store(blockRoot, struct{}{})
}

func (f *forkGraphDisk) hasBeaconState(blockRoot libcommon.Hash) bool {
_, err := f.fs.Stat(getBeaconStateFilename(blockRoot))
return err == nil
}

func (f *forkGraphDisk) Prune(pruneSlot uint64) (err error) {
pruneSlot -= f.beaconCfg.SlotsPerEpoch * 2
oldRoots := make([]libcommon.Hash, 0, f.beaconCfg.SlotsPerEpoch)
highestCrossedEpochSlot := uint64(0)
highestStoredBeaconStateSlot := uint64(0)
f.blocks.Range(func(key, value interface{}) bool {
hash := key.(libcommon.Hash)
signedBlock := value.(*cltypes.SignedBeaconBlock)
if signedBlock.Block.Slot%f.beaconCfg.SlotsPerEpoch == 0 && highestCrossedEpochSlot < signedBlock.Block.Slot {
highestCrossedEpochSlot = signedBlock.Block.Slot
if signedBlock.Block.Slot < highestStoredBeaconStateSlot {
return true
}
if f.hasBeaconState(hash) {
highestStoredBeaconStateSlot = signedBlock.Block.Slot
}
if signedBlock.Block.Slot >= pruneSlot {
return true
Expand All @@ -433,7 +441,7 @@ func (f *forkGraphDisk) Prune(pruneSlot uint64) (err error) {

return true
})
if pruneSlot >= highestCrossedEpochSlot {
if pruneSlot >= highestStoredBeaconStateSlot {
return
}

Expand Down

0 comments on commit 5521c78

Please sign in to comment.