fix: ensure time elapsed is not negative (#855)

This commit is contained in:
Kevin Davis 2021-02-28 10:33:56 -07:00 committed by GitHub
parent 9d60358fcd
commit 5ff0e4eea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -671,13 +671,13 @@ func CalculateTimeElapsed(start, end, blockTime time.Time, previousAccrualTime t
} }
if end.Before(blockTime) { if end.Before(blockTime) {
return sdk.NewInt(int64(math.RoundToEven( return sdk.MaxInt(sdk.ZeroInt(), sdk.NewInt(int64(math.RoundToEven(
end.Sub(previousAccrualTime).Seconds(), end.Sub(previousAccrualTime).Seconds(),
))) ))))
} }
return sdk.NewInt(int64(math.RoundToEven( return sdk.MaxInt(sdk.ZeroInt(), sdk.NewInt(int64(math.RoundToEven(
blockTime.Sub(previousAccrualTime).Seconds(), blockTime.Sub(previousAccrualTime).Seconds(),
))) ))))
} }
// SimulateHardSynchronization calculates a user's outstanding hard rewards by simulating reward synchronization // SimulateHardSynchronization calculates a user's outstanding hard rewards by simulating reward synchronization