From 8aa57bbca5f9893f2d63c0fba7b82b2731d41fe0 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 9 Nov 2020 22:21:37 -0800 Subject: [PATCH] be more lenient on grace period --- consensus/leader.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/consensus/leader.go b/consensus/leader.go index fca20e08a..7a764c967 100644 --- a/consensus/leader.go +++ b/consensus/leader.go @@ -303,9 +303,15 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) { consensus.preCommitAndPropose(blockObj) } - consensus.getLogger().Info().Msg("[OnCommit] Starting Grace Period") go func(viewID uint64) { - time.Sleep(1000 * time.Millisecond) + waitTime := 1000 * time.Millisecond + maxWaitTime := time.Until(consensus.NextBlockDue) + if maxWaitTime > waitTime { + waitTime = maxWaitTime + } + consensus.getLogger().Info().Str("waitTime", waitTime.String()). + Msg("[OnCommit] Starting Grace Period") + time.Sleep(waitTime) logger.Info().Msg("[OnCommit] Commit Grace Period Ended") consensus.mutex.Lock()