From 0f02ec9bf10bab477fc9e4f324a635d1d511fa83 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 9 Nov 2020 05:15:19 +0000 Subject: [PATCH 1/2] [viewchange] use last known viewID from blockchain Signed-off-by: Leo Chen --- consensus/view_change.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/consensus/view_change.go b/consensus/view_change.go index 6b6db7695..a3864cee4 100644 --- a/consensus/view_change.go +++ b/consensus/view_change.go @@ -125,6 +125,7 @@ func (consensus *Consensus) getNextViewID() (uint64, time.Duration) { return consensus.fallbackNextViewID() } blockTimestamp := curHeader.Time().Int64() + lastBlockViewID := curHeader.ViewID().Uint64() curTimestamp := time.Now().Unix() // timestamp messed up in current validator node @@ -133,13 +134,13 @@ func (consensus *Consensus) getNextViewID() (uint64, time.Duration) { } // diff only increases diff := uint64((curTimestamp - blockTimestamp) / viewChangeTimeout) - nextViewID := diff + consensus.GetCurBlockViewID() + nextViewID := diff + lastBlockViewID consensus.getLogger().Info(). Int64("curTimestamp", curTimestamp). Int64("blockTimestamp", blockTimestamp). Uint64("nextViewID", nextViewID). - Uint64("curViewID", consensus.GetCurBlockViewID()). + Uint64("lastBlockViewID", lastBlockViewID). Msg("[getNextViewID]") // duration is always the fixed view change duration for synchronous view change From 42e38aa4d70cae0e1d6e22ce8372f430bf5ace7f Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Sun, 8 Nov 2020 22:15:48 -0800 Subject: [PATCH 2/2] start timer after sync --- consensus/consensus_v2.go | 1 + 1 file changed, 1 insertion(+) diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index 515646987..75d0876b0 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -325,6 +325,7 @@ func (consensus *Consensus) Start( consensus.SetViewIDs(consensus.Blockchain.CurrentHeader().ViewID().Uint64() + 1) mode := consensus.UpdateConsensusInformation() consensus.current.SetMode(mode) + consensus.consensusTimeout[timeoutConsensus].Start() consensus.getLogger().Info().Str("Mode", mode.String()).Msg("Node is IN SYNC") } consensus.mutex.Unlock()