Skip to content

Commit

Permalink
Merge pull request #56 from nspcc-dev/move-lastblock-time
Browse files Browse the repository at this point in the history
check: set lastBlockTime in PrepareRequest handler, fix #55
  • Loading branch information
AnnaShaleva authored Jan 10, 2025
2 parents b2ba0cd + b3c1c3b commit 27db04c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ type Context[H Hash] struct {
LastSeenMessage []*HeightView

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).
lastBlockTime time.Time // Wall clock time of when we started (as in PrepareRequest) creating the last block (used for timer adjustments).
lastBlockIndex uint32
lastBlockView byte
}

// N returns total number of validators.
Expand Down

0 comments on commit 27db04c

Please sign in to comment.