Skip to content

Commit ca26acd

Browse files
committed
move pruning to it's own function
1 parent 86eb1a2 commit ca26acd

1 file changed

Lines changed: 36 additions & 30 deletions

File tree

block/internal/submitting/submitter.go

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -366,42 +366,48 @@ func (s *Submitter) processDAInclusionLoop() {
366366
}
367367

368368
// 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()
369+
s.pruneBlocks()
370+
}
371+
}
372+
}
371373

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-
}
374+
func (s *Submitter) pruneBlocks() {
375+
if !s.config.Node.PruningEnabled || s.config.Node.PruningKeepRecent == 0 || s.config.Node.PruningInterval == 0 {
376+
return
377+
}
376378

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+s.config.Node.PruningInterval {
383-
continue
384-
}
379+
currentDAIncluded := s.GetDAIncludedHeight()
385380

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
391-
}
381+
var lastPruned uint64
382+
if bz, err := s.store.GetMetadata(s.ctx, store.LastPrunedBlockHeightKey); err == nil && len(bz) == 8 {
383+
lastPruned = binary.LittleEndian.Uint64(bz)
384+
}
392385

393-
targetHeight := upperBound - s.config.Node.PruningKeepRecent
386+
storeHeight, err := s.store.Height(s.ctx)
387+
if err != nil {
388+
s.logger.Error().Err(err).Msg("failed to get store height for pruning")
389+
return
390+
}
391+
if storeHeight <= lastPruned+s.config.Node.PruningInterval {
392+
return
393+
}
394394

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-
}
395+
// Never prune blocks that are not DA included
396+
upperBound := min(storeHeight, currentDAIncluded)
397+
if upperBound <= s.config.Node.PruningKeepRecent {
398+
// Not enough fully included blocks to prune
399+
return
400+
}
398401

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-
}
404-
}
402+
targetHeight := upperBound - s.config.Node.PruningKeepRecent
403+
404+
if err := s.store.PruneBlocks(s.ctx, targetHeight); err != nil {
405+
s.logger.Error().Err(err).Uint64("target_height", targetHeight).Msg("failed to prune old block data")
406+
}
407+
408+
if pruner, ok := s.exec.(coreexecutor.ExecPruner); ok {
409+
if err := pruner.PruneExec(s.ctx, targetHeight); err != nil {
410+
s.logger.Error().Err(err).Uint64("target_height", targetHeight).Msg("failed to prune execution metadata")
405411
}
406412
}
407413
}

0 commit comments

Comments
 (0)