diff --git a/CHANGELOG.md b/CHANGELOG.md index 47068308..862f9a7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ New features: Behaviour changes: Improvements: + * timer adjustment for most of the consensus time, more accurate block + intervals (#55) Bugs fixed: * inappropriate log on attempt to construct Commit for anti-MEV enabled WatchOnly diff --git a/check.go b/check.go index cfc84e46..f8f19231 100644 --- a/check.go +++ b/check.go @@ -5,6 +5,13 @@ import ( ) func (d *DBFT[H]) checkPrepare() { + if d.lastBlockIndex != d.BlockIndex || d.lastBlockView != d.ViewNumber { + // Notice that lastBlockTimestamp is left unchanged because + // this must be the value from the last header. + d.lastBlockTime = d.Timer.Now() + d.lastBlockIndex = d.BlockIndex + d.lastBlockView = d.ViewNumber + } if !d.hasAllTransactions() { d.Logger.Debug("check prepare: some transactions are missing", zap.Any("hashes", d.MissingTransactions)) return @@ -138,8 +145,6 @@ func (d *DBFT[H]) checkCommit() { d.Logger.Fatal("block processing failed", zap.Error(err)) } - d.lastBlockIndex = d.BlockIndex - d.lastBlockTime = d.Timer.Now() d.blockProcessed = true // Do not initialize consensus process immediately. It's the caller's duty to diff --git a/context.go b/context.go index 4618c80f..1ad088da 100644 --- a/context.go +++ b/context.go @@ -90,6 +90,7 @@ type Context[H Hash] struct { lastBlockTimestamp uint64 // ns-precision timestamp from the last header (used for the next block timestamp calculations). lastBlockTime time.Time // Wall clock time of when the last block was first seen (used for timer adjustments). lastBlockIndex uint32 + lastBlockView byte } // N returns total number of validators.