From 4c7e221335596040eb9ae164b0668d5564b08106 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 26 Nov 2021 18:21:06 +0300 Subject: [PATCH] check: set lastBlockTime in PrepareRequest handler, fix #55 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 --- check.go | 9 +++++++-- context.go | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/check.go b/check.go index 4b4b9e15..5a206271 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 @@ -57,8 +64,6 @@ func (d *DBFT[H]) checkCommit() { return } - d.lastBlockIndex = d.BlockIndex - d.lastBlockTime = d.Timer.Now() d.block = d.CreateBlock() hash := d.block.Hash() diff --git a/context.go b/context.go index 4a7ce73d..7b27075f 100644 --- a/context.go +++ b/context.go @@ -76,6 +76,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.