Skip to content

Commit

Permalink
[consensus] optimize onCommit
Browse files Browse the repository at this point in the history
restore the original grace period function

Signed-off-by: Leo Chen <leo@harmony.one>
  • Loading branch information
Leo Chen committed Jul 15, 2020
1 parent 50c6919 commit 82d7210
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions consensus/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 82d7210

Please sign in to comment.