From ad09336c89cb6855a34e9dc05f8f8686b1decdb4 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 19 Mar 2021 21:46:50 +0000 Subject: [PATCH] [bootstrap] do not stop bootstrap timer When the node initially rebooted, it may enter 'Syncing' mode, while it will stop the bootstrap timer. When the network is in viewchange mode, itself can't enter view change mode anymore and will stuck in syncing mode forever. This PR is a fix of this long time issue, https://github.com/harmony-one/harmony/issues/3572 Signed-off-by: Leo Chen --- consensus/consensus_service.go | 3 +++ consensus/consensus_v2.go | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index 526b64392..a5e93e53c 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -174,6 +174,9 @@ func (consensus *Consensus) IsValidatorInCommittee(pubKey bls.SerializedPublicKe // SetMode sets the mode of consensus func (consensus *Consensus) SetMode(m Mode) { + consensus.getLogger().Debug(). + Str("Mode", m.String()). + Msg("[SetMode]") consensus.current.SetMode(m) } diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index 63c701816..75fe63031 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -317,9 +317,26 @@ func (consensus *Consensus) Start( continue } for k, v := range consensus.consensusTimeout { - if consensus.current.Mode() == Syncing || - consensus.current.Mode() == Listening { + // stop timer in listening mode + if consensus.current.Mode() == Listening { v.Stop() + continue + } + + if consensus.current.Mode() == Syncing { + // never stop bootstrap timer here in syncing mode as it only starts once + // if it is stopped, bootstrap will be stopped and nodes + // can't start view change or join consensus + // the bootstrap timer will be stopped once consensus is reached or view change + // is succeeded + if k != timeoutBootstrap { + consensus.getLogger().Debug(). + Str("k", k.String()). + Str("Mode", consensus.current.Mode().String()). + Msg("[ConsensusMainLoop] consensusTimeout stopped!!!") + v.Stop() + continue + } } if !v.CheckExpire() { continue