Skip to content

Commit

Permalink
Fixing new caplin snapshots interval retirement (#12124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio2002 authored Sep 29, 2024
1 parent bef0fad commit bf0d328
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
18 changes: 7 additions & 11 deletions cl/antiquary/antiquary.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (a *Antiquary) Loop() error {
return err
}
// Check for snapshots retirement every 3 minutes
retirementTicker := time.NewTicker(3 * time.Minute)
retirementTicker := time.NewTicker(12 * time.Second)
defer retirementTicker.Stop()
for {
select {
Expand Down Expand Up @@ -258,13 +258,12 @@ func (a *Antiquary) Loop() error {
if from >= to {
continue
}
from = (from / snaptype.Erigon2MergeLimit) * snaptype.Erigon2MergeLimit
from = (from / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit
to = min(to, to-safetyMargin) // We don't want to retire snapshots that are too close to the finalized head
to = (to / snaptype.Erigon2MergeLimit) * snaptype.Erigon2MergeLimit
if to-from < snaptype.Erigon2MergeLimit {
to = (to / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit
if to-from < snaptype.CaplinMergeLimit {
continue
}

if err := a.antiquate(from, to); err != nil {
return err
}
Expand All @@ -279,9 +278,6 @@ const caplinSnapshotBuildSemaWeight int64 = 1

// Antiquate will antiquate a specific block range (aka. retire snapshots), this should be ran in the background.
func (a *Antiquary) antiquate(from, to uint64) error {
if a.downloader == nil {
return nil // Just skip if we don't have a downloader
}
if a.snBuildSema != nil {
if !a.snBuildSema.TryAcquire(caplinSnapshotBuildSemaWeight) {
return nil
Expand Down Expand Up @@ -373,14 +369,14 @@ func (a *Antiquary) antiquateBlobs() error {
if currentBlobsProgress >= a.sn.BlocksAvailable() {
return nil
}
minimunBlobsProgress := ((a.cfg.DenebForkEpoch * a.cfg.SlotsPerEpoch) / snaptype.Erigon2MergeLimit) * snaptype.Erigon2MergeLimit
minimunBlobsProgress := ((a.cfg.DenebForkEpoch * a.cfg.SlotsPerEpoch) / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit
currentBlobsProgress = max(currentBlobsProgress, minimunBlobsProgress)
// read the finalized head
to, err := beacon_indicies.ReadHighestFinalized(roTx)
if err != nil {
return err
}
if to <= currentBlobsProgress || to-currentBlobsProgress < snaptype.Erigon2MergeLimit {
if to <= currentBlobsProgress || to-currentBlobsProgress < snaptype.CaplinMergeLimit {
return nil
}
roTx.Rollback()
Expand All @@ -389,7 +385,7 @@ func (a *Antiquary) antiquateBlobs() error {
if err := freezeblocks.DumpBlobsSidecar(a.ctx, a.blobStorage, a.mainDB, currentBlobsProgress, to, a.sn.Salt, a.dirs, 1, log.LvlDebug, a.logger); err != nil {
return err
}
to = (to / snaptype.Erigon2MergeLimit) * snaptype.Erigon2MergeLimit
to = (to / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit
a.logger.Info("[Antiquary] Finished Antiquating blobs", "from", currentBlobsProgress, "to", to)
if err := a.sn.ReopenFolder(); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions erigon-lib/chain/snapcfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ func (c Cfg) MergeLimit(t snaptype.Enum, fromBlock uint64) uint64 {
// not the same as other snapshots which follow a block based sharding scheme
// TODO: If we add any more sharding schemes (we currently have blocks, state & beacon block schemes)
// - we may need to add some kind of sharding scheme identifier to snaptype.Type
if snaptype.IsCaplinType(t) {
return snaptype.CaplinMergeLimit
}
if hasType {
if snaptype.IsCaplinType(t) {
return snaptype.CaplinMergeLimit
}
return snaptype.Erigon2MergeLimit
}

Expand Down
10 changes: 1 addition & 9 deletions turbo/snapshotsync/freezeblocks/caplin_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ Loop:
continue
}
var processed bool = true

switch f.Type.Enum() {
case snaptype.CaplinEnums.BeaconBlocks:
var sn *DirtySegment
Expand Down Expand Up @@ -791,17 +790,10 @@ func (s *CaplinSnapshots) FrozenBlobs() uint64 {
if s.beaconCfg.DenebForkEpoch == math.MaxUint64 {
return 0
}
minSegFrom := ((s.beaconCfg.SlotsPerEpoch * s.beaconCfg.DenebForkEpoch) / snaptype.CaplinMergeLimit) * snaptype.CaplinMergeLimit
foundMinSeg := false
ret := uint64(0)
for _, seg := range s.BlobSidecars.VisibleSegments {
if seg.from == minSegFrom {
foundMinSeg = true
}
ret = max(ret, seg.to)
}
if !foundMinSeg {
return 0
}

return ret
}

0 comments on commit bf0d328

Please sign in to comment.