From 7b3b4feedce0b9e6b2938435c025a10522fbd6c0 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 2 May 2024 09:35:39 +0200 Subject: [PATCH] Fixed prunable rollback deleting the rewards If we rolled back to the last slot of an epoch (e.g. when loading a snapshot) on resuming from storage or starting warpsync we wrongly deleted the rewards --- pkg/storage/prunable/prunable.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/storage/prunable/prunable.go b/pkg/storage/prunable/prunable.go index e90f2b0b8..c7590a651 100644 --- a/pkg/storage/prunable/prunable.go +++ b/pkg/storage/prunable/prunable.go @@ -194,9 +194,13 @@ func (p *Prunable) Rollback(targetEpoch iotago.EpochIndex, startPruneRange iotag return ierrors.Wrapf(err, "failed to rollback decided upgrade signals epochs to target epoch %d", targetEpoch) } - lastPrunedPoolRewardsEpoch, err := p.poolRewards.RollbackEpochs(targetEpoch) - if err != nil { - return ierrors.Wrapf(err, "failed to rollback pool rewards epochs to target epoch %d", targetEpoch) + var lastPrunedPoolRewardsEpoch iotago.EpochIndex + // Do not rollback the epoch if the targetSlot is the end of the epoch, because that is when we calculated the rewards. + if targetSlot := startPruneRange - 1; p.apiProvider.APIForSlot(targetSlot).TimeProvider().EpochEnd(targetEpoch) != targetSlot { + lastPrunedPoolRewardsEpoch, err = p.poolRewards.RollbackEpochs(targetEpoch) + if err != nil { + return ierrors.Wrapf(err, "failed to rollback pool rewards epochs to target epoch %d", targetEpoch) + } } for epochToPrune := targetEpoch + 1; epochToPrune <= max(