diff --git a/app/app.go b/app/app.go index 5e9d67228..c101bf248 100644 --- a/app/app.go +++ b/app/app.go @@ -898,7 +898,7 @@ func (app *BNBBeaconChain) isBreatheBlock(height int64, lastBlockTime time.Time, // lastBlockTime is zero if this blockTime is for the first block (first block doesn't mean height = 1, because after // state sync from breathe block, the height is breathe block + 1) if app.baseConfig.BreatheBlockInterval > 0 { - return height%int64(app.baseConfig.BreatheBlockInterval) == 0 + return !lastBlockTime.IsZero() && !utils.SamePeriodInUTC(lastBlockTime, blockTime, int64(app.baseConfig.BreatheBlockInterval)) } else { return !lastBlockTime.IsZero() && !utils.SameDayInUTC(lastBlockTime, blockTime) } diff --git a/common/utils/times.go b/common/utils/times.go index ba8d9f1ec..788fe200e 100644 --- a/common/utils/times.go +++ b/common/utils/times.go @@ -12,3 +12,7 @@ func Now() time.Time { func SameDayInUTC(first, second time.Time) bool { return first.Unix()/SecondsPerDay == second.Unix()/SecondsPerDay } + +func SamePeriodInUTC(first, second time.Time, period int64) bool { + return first.Unix()/period == second.Unix()/period +}