Skip to content

Commit

Permalink
Simplify and comment pruningRange for storage rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis committed Nov 22, 2023
1 parent 762a598 commit 5fa1b5c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/storage/storage_prunable.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ func (s *Storage) Rollback(targetSlot iotago.SlotIndex) error {
return s.prunable.Rollback(s.pruningRange(targetSlot))
}

func (s *Storage) pruningRange(targetSlot iotago.SlotIndex) (targetEpoch iotago.EpochIndex, startPruneRange iotago.SlotIndex, endPruneRange iotago.SlotIndex) {
func (s *Storage) pruningRange(targetSlot iotago.SlotIndex) (targetEpoch iotago.EpochIndex, startSlot iotago.SlotIndex, endSlot iotago.SlotIndex) {
timeProvider := s.Settings().APIProvider().APIForSlot(targetSlot).TimeProvider()

targetEpoch = timeProvider.EpochFromSlot(targetSlot)

startPruneRange = targetSlot + 1
endPruneRange = s.Settings().LatestStoredSlot()
startSlot = targetSlot + 1
endSlot = s.Settings().LatestStoredSlot()

// If the targetSlot is the last slot of the previous epoch, we need to prune
if timeProvider.EpochFromSlot(startPruneRange) > targetEpoch {
endPruneRange = timeProvider.EpochEnd(targetEpoch)
// If startSlot is in the next epoch, there's no need to prune a range of slots as the next epoch is going to be pruned on epoch-level anyway.
if timeProvider.EpochFromSlot(startSlot) > targetEpoch {
endSlot = 0
}

return targetEpoch, startPruneRange, endPruneRange
return targetEpoch, startSlot, endSlot
}

0 comments on commit 5fa1b5c

Please sign in to comment.