Skip to content

Commit 8ddde04

Browse files
committed
trigger pruning every ticker
1 parent 75c241b commit 8ddde04

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

block/internal/submitting/submitter.go

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -360,42 +360,47 @@ func (s *Submitter) processDAInclusionLoop() {
360360
s.logger.Error().Err(err).Uint64("height", nextHeight).Msg("failed to persist DA included height")
361361
}
362362

363-
// Run height-based pruning if enabled.
364-
if s.config.Node.PruningEnabled && s.config.Node.PruningKeepRecent > 0 && s.config.Node.PruningInterval > 0 {
365-
// Trigger pruning only when we reach the configured interval.
366-
if currentDAIncluded%s.config.Node.PruningInterval == 0 {
367-
// We must make sure not to prune blocks that have not yet been included in DA.
368-
daIncludedHeight := s.GetDAIncludedHeight()
369-
370-
storeHeight, err := s.store.Height(s.ctx)
371-
if err != nil {
372-
s.logger.Error().Err(err).Msg("failed to get store height for pruning")
373-
break
374-
}
363+
// Delete height cache for that height
364+
// This can only be performed after the height has been persisted to store
365+
s.cache.DeleteHeight(nextHeight)
366+
}
375367

376-
upperBound := min(storeHeight, daIncludedHeight)
377-
if upperBound <= s.config.Node.PruningKeepRecent {
378-
// Not enough fully included blocks to prune while respecting keep-recent.
379-
break
380-
}
368+
// Run height-based pruning if enabled.
369+
if s.config.Node.PruningEnabled && s.config.Node.PruningKeepRecent > 0 && s.config.Node.PruningInterval > 0 {
370+
currentDAIncluded = s.GetDAIncludedHeight()
381371

382-
targetHeight := upperBound - s.config.Node.PruningKeepRecent
372+
var lastPruned uint64
373+
if bz, err := s.store.GetMetadata(s.ctx, store.LastPrunedBlockHeightKey); err == nil && len(bz) == 8 {
374+
lastPruned = binary.LittleEndian.Uint64(bz)
375+
}
383376

384-
if err := s.store.PruneBlocks(s.ctx, targetHeight); err != nil {
385-
s.logger.Error().Err(err).Uint64("target_height", targetHeight).Msg("failed to prune old block data")
386-
}
377+
storeHeight, err := s.store.Height(s.ctx)
378+
if err != nil {
379+
s.logger.Error().Err(err).Msg("failed to get store height for pruning")
380+
continue
381+
}
382+
if storeHeight <= lastPruned+uint64(s.config.Node.PruningInterval) {
383+
continue
384+
}
387385

388-
if pruner, ok := s.exec.(coreexecutor.ExecPruner); ok {
389-
if err := pruner.PruneExec(s.ctx, targetHeight); err != nil {
390-
s.logger.Error().Err(err).Uint64("target_height", targetHeight).Msg("failed to prune execution metadata")
391-
}
392-
}
393-
}
386+
// Never prune blocks that are not DA included
387+
upperBound := min(storeHeight, currentDAIncluded)
388+
if upperBound <= s.config.Node.PruningKeepRecent {
389+
// Not enough fully included blocks to prune
390+
continue
394391
}
395392

396-
// Delete height cache for that height
397-
// This can only be performed after the height has been persisted to store
398-
s.cache.DeleteHeight(nextHeight)
393+
targetHeight := upperBound - s.config.Node.PruningKeepRecent
394+
395+
if err := s.store.PruneBlocks(s.ctx, targetHeight); err != nil {
396+
s.logger.Error().Err(err).Uint64("target_height", targetHeight).Msg("failed to prune old block data")
397+
}
398+
399+
if pruner, ok := s.exec.(coreexecutor.ExecPruner); ok {
400+
if err := pruner.PruneExec(s.ctx, targetHeight); err != nil {
401+
s.logger.Error().Err(err).Uint64("target_height", targetHeight).Msg("failed to prune execution metadata")
402+
}
403+
}
399404
}
400405
}
401406
}

0 commit comments

Comments
 (0)