|
|
|
@ -242,7 +242,7 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) { |
|
|
|
|
|
|
|
|
|
consensus.mutex.Lock() |
|
|
|
|
defer consensus.mutex.Unlock() |
|
|
|
|
if len(prepareSigs) >= ((len(consensus.PublicKeys)*2)/3 + 1) { |
|
|
|
|
if len(prepareSigs) >= consensus.Quorum() { |
|
|
|
|
// already have enough signatures
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
@ -270,7 +270,7 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) { |
|
|
|
|
prepareSigs[validatorAddress] = &sign |
|
|
|
|
prepareBitmap.SetKey(validatorPubKey, true) // Set the bitmap indicating that this validator signed.
|
|
|
|
|
|
|
|
|
|
if len(prepareSigs) >= ((len(consensus.PublicKeys)*2)/3 + 1) { |
|
|
|
|
if len(prepareSigs) >= consensus.Quorum() { |
|
|
|
|
consensus.switchPhase(Commit) |
|
|
|
|
|
|
|
|
|
// Construct and broadcast prepared message
|
|
|
|
@ -431,9 +431,7 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len((commitSigs)) >= ((len(consensus.PublicKeys)*2)/3 + 1) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
quorumWasMet := len(commitSigs) >= consensus.Quorum() |
|
|
|
|
|
|
|
|
|
// Verify the signature on prepare multi-sig and bitmap is correct
|
|
|
|
|
var sign bls.Sign |
|
|
|
@ -453,8 +451,20 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) { |
|
|
|
|
// Set the bitmap indicating that this validator signed.
|
|
|
|
|
commitBitmap.SetKey(validatorPubKey, true) |
|
|
|
|
|
|
|
|
|
if len(commitSigs) >= ((len(consensus.PublicKeys)*2)/3 + 1) { |
|
|
|
|
quorumIsMet := len(commitSigs) >= consensus.Quorum() |
|
|
|
|
|
|
|
|
|
if !quorumWasMet && quorumIsMet { |
|
|
|
|
utils.GetLogInstance().Info("Enough commits received!", "num", len(commitSigs), "state", consensus.state) |
|
|
|
|
go func(round uint64) { |
|
|
|
|
time.Sleep(1 * time.Second) |
|
|
|
|
utils.GetLogger().Debug("Commit grace period ended", "round", round) |
|
|
|
|
consensus.commitFinishChan <- round |
|
|
|
|
}(consensus.round) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (consensus *Consensus) finalizeCommits() { |
|
|
|
|
utils.GetLogger().Info("finalizing block", "num", len(consensus.commitSigs), "state", consensus.state) |
|
|
|
|
consensus.switchPhase(Announce) |
|
|
|
|
|
|
|
|
|
// Construct and broadcast committed message
|
|
|
|
@ -495,12 +505,10 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) { |
|
|
|
|
consensus.blockNum++ |
|
|
|
|
|
|
|
|
|
consensus.OnConsensusDone(&blockObj) |
|
|
|
|
utils.GetLogInstance().Debug("HOORAY!!!!!!! CONSENSUS REACHED!!!!!!!", "viewID", consensus.viewID, "numOfSignatures", len(commitSigs)) |
|
|
|
|
utils.GetLogInstance().Debug("HOORAY!!!!!!! CONSENSUS REACHED!!!!!!!", "viewID", consensus.viewID, "numOfSignatures", len(consensus.commitSigs)) |
|
|
|
|
|
|
|
|
|
// Send signal to Node so the new block can be added and new round of consensus can be triggered
|
|
|
|
|
consensus.ReadySignal <- struct{}{} |
|
|
|
|
} |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (consensus *Consensus) onCommitted(msg *msg_pb.Message) { |
|
|
|
@ -737,6 +745,16 @@ func (consensus *Consensus) Start(blockChannel chan *types.Block, stopChan chan |
|
|
|
|
|
|
|
|
|
case msg := <-consensus.MsgChan: |
|
|
|
|
consensus.handleMessageUpdate(msg) |
|
|
|
|
|
|
|
|
|
case round := <-consensus.commitFinishChan: |
|
|
|
|
func() { |
|
|
|
|
consensus.mutex.Lock() |
|
|
|
|
defer consensus.mutex.Unlock() |
|
|
|
|
if round == consensus.round { |
|
|
|
|
consensus.finalizeCommits() |
|
|
|
|
} |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
case <-stopChan: |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|