Skip to content

Commit 27db04c

Browse files
authored
Merge pull request #56 from nspcc-dev/move-lastblock-time
check: set lastBlockTime in PrepareRequest handler, fix #55
2 parents b2ba0cd + b3c1c3b commit 27db04c

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ New features:
99
Behaviour changes:
1010

1111
Improvements:
12+
* timer adjustment for most of the consensus time, more accurate block
13+
intervals (#55)
1214

1315
Bugs fixed:
1416
* inappropriate log on attempt to construct Commit for anti-MEV enabled WatchOnly

check.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import (
55
)
66

77
func (d *DBFT[H]) checkPrepare() {
8+
if d.lastBlockIndex != d.BlockIndex || d.lastBlockView != d.ViewNumber {
9+
// Notice that lastBlockTimestamp is left unchanged because
10+
// this must be the value from the last header.
11+
d.lastBlockTime = d.Timer.Now()
12+
d.lastBlockIndex = d.BlockIndex
13+
d.lastBlockView = d.ViewNumber
14+
}
815
if !d.hasAllTransactions() {
916
d.Logger.Debug("check prepare: some transactions are missing", zap.Any("hashes", d.MissingTransactions))
1017
return
@@ -138,8 +145,6 @@ func (d *DBFT[H]) checkCommit() {
138145
d.Logger.Fatal("block processing failed", zap.Error(err))
139146
}
140147

141-
d.lastBlockIndex = d.BlockIndex
142-
d.lastBlockTime = d.Timer.Now()
143148
d.blockProcessed = true
144149

145150
// Do not initialize consensus process immediately. It's the caller's duty to

context.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ type Context[H Hash] struct {
8888
LastSeenMessage []*HeightView
8989

9090
lastBlockTimestamp uint64 // ns-precision timestamp from the last header (used for the next block timestamp calculations).
91-
lastBlockTime time.Time // Wall clock time of when the last block was first seen (used for timer adjustments).
91+
lastBlockTime time.Time // Wall clock time of when we started (as in PrepareRequest) creating the last block (used for timer adjustments).
9292
lastBlockIndex uint32
93+
lastBlockView byte
9394
}
9495

9596
// N returns total number of validators.

0 commit comments

Comments
 (0)