From 37ca1ea3f3bfa7e403ff8fe3cc4975d1533414b7 Mon Sep 17 00:00:00 2001 From: Giulio Date: Wed, 17 Jul 2024 21:28:13 +0200 Subject: [PATCH] save --- .../forkchoice/fork_graph/fork_graph_disk.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go index 73e06e2a0c4..a23839c53c6 100644 --- a/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go +++ b/cl/phase1/forkchoice/fork_graph/fork_graph_disk.go @@ -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 @@ -433,7 +441,7 @@ func (f *forkGraphDisk) Prune(pruneSlot uint64) (err error) { return true }) - if pruneSlot >= highestCrossedEpochSlot { + if pruneSlot >= highestStoredBeaconStateSlot { return }