|
|
@ -480,11 +480,7 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// already had enough signautres
|
|
|
|
quorumWasMet := len(commitSigs) >= consensus.Quorum() |
|
|
|
if len(commitSigs) >= consensus.Quorum() { |
|
|
|
|
|
|
|
consensus.getLogger().Info("received additional commit message", "validatorPubKey", validatorPubKey) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Verify the signature on commitPayload is correct
|
|
|
|
// Verify the signature on commitPayload is correct
|
|
|
|
var sign bls.Sign |
|
|
|
var sign bls.Sign |
|
|
@ -508,9 +504,23 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) { |
|
|
|
ctxerror.Warn(consensus.getLogger(), err, "commitBitmap.SetKey failed") |
|
|
|
ctxerror.Warn(consensus.getLogger(), err, "commitBitmap.SetKey failed") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(commitSigs) >= consensus.Quorum() { |
|
|
|
quorumIsMet := len(commitSigs) >= consensus.Quorum() |
|
|
|
consensus.getLogger().Info("Enough commits received!", "num", len(commitSigs)) |
|
|
|
rewardThresholdIsMet := len(commitSigs) >= consensus.RewardThreshold() |
|
|
|
consensus.finalizeCommits() |
|
|
|
|
|
|
|
|
|
|
|
if !quorumWasMet && quorumIsMet { |
|
|
|
|
|
|
|
consensus.getLogger().Info("enough commits received for consensus", "num", len(commitSigs)) |
|
|
|
|
|
|
|
go func(viewID uint32) { |
|
|
|
|
|
|
|
time.Sleep(2 * time.Second) |
|
|
|
|
|
|
|
consensus.getLogger().Debug("Commit grace period ended") |
|
|
|
|
|
|
|
consensus.commitFinishChan <- viewID |
|
|
|
|
|
|
|
}(consensus.viewID) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if rewardThresholdIsMet { |
|
|
|
|
|
|
|
go func(viewID uint32) { |
|
|
|
|
|
|
|
consensus.commitFinishChan <- viewID |
|
|
|
|
|
|
|
consensus.getLogger().Debug("enough commits received for block reward", "num", len(commitSigs)) |
|
|
|
|
|
|
|
}(consensus.viewID) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -835,6 +845,15 @@ func (consensus *Consensus) Start(blockChannel chan *types.Block, stopChan chan |
|
|
|
case msg := <-consensus.MsgChan: |
|
|
|
case msg := <-consensus.MsgChan: |
|
|
|
consensus.handleMessageUpdate(msg) |
|
|
|
consensus.handleMessageUpdate(msg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case viewID := <-consensus.commitFinishChan: |
|
|
|
|
|
|
|
func() { |
|
|
|
|
|
|
|
consensus.mutex.Lock() |
|
|
|
|
|
|
|
defer consensus.mutex.Unlock() |
|
|
|
|
|
|
|
if viewID == consensus.viewID { |
|
|
|
|
|
|
|
consensus.finalizeCommits() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
case <-stopChan: |
|
|
|
case <-stopChan: |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|