Skip to content

Commit

Permalink
check: set lastBlockTime in PrepareRequest handler, fix #55
Browse files Browse the repository at this point in the history
It's the earliest point, if a view change happens the timer is reset (because
new view comes with a new set of transactions, potentially picking up ones
received between views).

Signed-off-by: Roman Khimov <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed Dec 31, 2024
1 parent b2ba0cd commit 42d6f59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 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
1 change: 1 addition & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 42d6f59

Please sign in to comment.