[consensus] optimize onCommit

restore the original grace period function

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3220/head
Leo Chen 4 years ago
parent b560f88978
commit 0435e2d203
  1. 23
      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)
}
}

Loading…
Cancel
Save