From 0435e2d2034cb825baf6786d7edeb3df1674d5a8 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 15 Jul 2020 07:41:27 +0000 Subject: [PATCH] [consensus] optimize onCommit restore the original grace period function Signed-off-by: Leo Chen --- consensus/leader.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/consensus/leader.go b/consensus/leader.go index 34661a880..f369771a1 100644 --- a/consensus/leader.go +++ b/consensus/leader.go @@ -265,25 +265,28 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) { viewID := consensus.viewID + if consensus.Decider.IsAllSigsCollected() { + go func(viewID uint64) { + logger.Info().Msg("[OnCommit] 100% Enough commits received") + consensus.commitFinishChan <- viewID + }(viewID) + + consensus.msgSender.StopRetry(msg_pb.MessageType_PREPARED) + return + } + quorumIsMet := consensus.Decider.IsQuorumAchieved(quorum.Commit) if !quorumWasMet && quorumIsMet { logger.Info().Msg("[OnCommit] 2/3 Enough commits received") - next := consensus.NextBlockDue consensus.getLogger().Info().Msg("[OnCommit] Starting Grace Period") - time.AfterFunc(2*time.Second, func() { - <-time.After(time.Until(next)) + go func(viewID uint64) { + time.Sleep(2 * time.Second) logger.Info().Msg("[OnCommit] Commit Grace Period Ended") consensus.commitFinishChan <- viewID - }) + }(viewID) consensus.msgSender.StopRetry(msg_pb.MessageType_PREPARED) } - if consensus.Decider.IsAllSigsCollected() { - go func(viewID uint64) { - consensus.commitFinishChan <- viewID - logger.Info().Msg("[OnCommit] 100% Enough commits received") - }(consensus.viewID) - } }