fix: account for start time in calculating time elapsed (#821)

This commit is contained in:
Kevin Davis 2021-02-12 08:30:10 -07:00 committed by GitHub
parent fe2a131b31
commit 7e39c1d0a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 // 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 // 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 { func CalculateTimeElapsed(start, end, blockTime time.Time, previousAccrualTime time.Time) sdk.Int {
if end.Before(blockTime) && if (end.Before(blockTime) &&
(end.Before(previousAccrualTime) || end.Equal(previousAccrualTime)) { (end.Before(previousAccrualTime) || end.Equal(previousAccrualTime))) ||
(start.After(previousAccrualTime)) ||
(start.Equal(blockTime)) {
return sdk.ZeroInt() return sdk.ZeroInt()
} }
if start.After(previousAccrualTime) && start.Before(blockTime) {
previousAccrualTime = start
}
if end.Before(blockTime) { if end.Before(blockTime) {
return sdk.NewInt(int64(math.RoundToEven( return sdk.NewInt(int64(math.RoundToEven(
end.Sub(previousAccrualTime).Seconds(), end.Sub(previousAccrualTime).Seconds(),