From 7e39c1d0a825ced5edc56aa0b6c35261f900c101 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Fri, 12 Feb 2021 08:30:10 -0700 Subject: [PATCH] fix: account for start time in calculating time elapsed (#821) --- x/incentive/keeper/rewards.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/x/incentive/keeper/rewards.go b/x/incentive/keeper/rewards.go index 617332ae..dd0baac0 100644 --- a/x/incentive/keeper/rewards.go +++ b/x/incentive/keeper/rewards.go @@ -642,10 +642,16 @@ func (k Keeper) ZeroHardLiquidityProviderClaim(ctx sdk.Context, claim types.Hard // CalculateTimeElapsed calculates the number of reward-eligible seconds that have passed since the previous // time rewards were accrued, taking into account the end time of the reward period func CalculateTimeElapsed(start, end, blockTime time.Time, previousAccrualTime time.Time) sdk.Int { - if end.Before(blockTime) && - (end.Before(previousAccrualTime) || end.Equal(previousAccrualTime)) { + if (end.Before(blockTime) && + (end.Before(previousAccrualTime) || end.Equal(previousAccrualTime))) || + (start.After(previousAccrualTime)) || + (start.Equal(blockTime)) { return sdk.ZeroInt() } + if start.After(previousAccrualTime) && start.Before(blockTime) { + previousAccrualTime = start + } + if end.Before(blockTime) { return sdk.NewInt(int64(math.RoundToEven( end.Sub(previousAccrualTime).Seconds(),