From 9ceefe17e23321b2d3dbe930aa4d86d63bdb92a8 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 31 Jan 2020 17:22:37 +0300 Subject: [PATCH] consensus: check current chain height before processing timer The chain may already be more current than our dBFT state (like when the node has commited something at view 0, but all the other nodes changed view and accepted something at view 1), so in this case we should reinit dBFT on new height. --- pkg/consensus/consensus.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index c6662ba10..96847d904 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -168,7 +168,14 @@ func (s *service) eventLoop() { s.log.Debug("timer fired", zap.Uint32("height", hv.Height), zap.Uint("view", uint(hv.View))) - s.dbft.OnTimeout(hv) + if s.Chain.BlockHeight() >= s.dbft.BlockIndex { + s.log.Debug("chain already advanced", + zap.Uint32("dbft index", s.dbft.BlockIndex), + zap.Uint32("chain index", s.Chain.BlockHeight())) + s.dbft.InitializeConsensus(0) + } else { + s.dbft.OnTimeout(hv) + } case msg := <-s.messages: fields := []zap.Field{ zap.Uint16("from", msg.validatorIndex),