mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25:18 +00:00
fix: ensure time elapsed is not negative (#855)
This commit is contained in:
parent
9d60358fcd
commit
5ff0e4eea4
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user