From 33c826b6595f70b6cdd00dac2b11ac3fd9dc7e33 Mon Sep 17 00:00:00 2001 From: dylanhuang Date: Mon, 22 Jan 2024 14:49:49 +0800 Subject: [PATCH] fix: change BreatheBlockInterval to time period (#1005) --- app/app.go | 2 +- common/utils/times.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 +}