Added HandleMessageUpdate locks.

pull/4509/head
frozen 2 years ago committed by Casey Gardiner
parent e7b3b175c0
commit 0369740c10
  1. 7
      consensus/consensus_service.go
  2. 8
      consensus/consensus_v2.go
  3. 2
      consensus/leader.go
  4. 11
      consensus/view_change.go

@ -468,7 +468,12 @@ func (consensus *Consensus) isLeader() bool {
// SetViewIDs set both current view ID and view changing ID to the height
// of the blockchain. It is used during client startup to recover the state
func (consensus *Consensus) SetViewIDs(height uint64) {
fmt.Println("SetViewIDs", height)
consensus.setViewIDs(height)
}
// SetViewIDs set both current view ID and view changing ID to the height
// of the blockchain. It is used during client startup to recover the state
func (consensus *Consensus) setViewIDs(height uint64) {
consensus.SetCurBlockViewID(height)
consensus.SetViewChangingID(height)
}

@ -56,6 +56,8 @@ func (consensus *Consensus) isViewChangingMode() bool {
// HandleMessageUpdate will update the consensus state according to received message
func (consensus *Consensus) HandleMessageUpdate(ctx context.Context, msg *msg_pb.Message, senderKey *bls.SerializedPublicKey) error {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
// when node is in ViewChanging mode, it still accepts normal messages into FBFTLog
// in order to avoid possible trap forever but drop PREPARE and COMMIT
// which are message types specifically for a node acting as leader
@ -144,7 +146,7 @@ func (consensus *Consensus) finalCommit() {
Msg("[finalCommit] Finalizing Consensus")
beforeCatchupNum := consensus.BlockNum()
leaderPriKey, err := consensus.GetConsensusLeaderPrivateKey()
leaderPriKey, err := consensus.getConsensusLeaderPrivateKey()
if err != nil {
consensus.getLogger().Error().Err(err).Msg("[finalCommit] leader not found")
return
@ -559,7 +561,7 @@ func (consensus *Consensus) preCommitAndPropose(blk *types.Block) error {
return errors.New("block to pre-commit is nil")
}
leaderPriKey, err := consensus.GetConsensusLeaderPrivateKey()
leaderPriKey, err := consensus.getConsensusLeaderPrivateKey()
if err != nil {
consensus.getLogger().Error().Err(err).Msg("[preCommitAndPropose] leader not found")
return err
@ -804,7 +806,7 @@ func (consensus *Consensus) postCatchup(initBN uint64) {
// GenerateVrfAndProof generates new VRF/Proof from hash of previous block
func (consensus *Consensus) GenerateVrfAndProof(newHeader *block.Header) error {
key, err := consensus.GetConsensusLeaderPrivateKey()
key, err := consensus.getConsensusLeaderPrivateKey()
if err != nil {
return errors.New("[GenerateVrfAndProof] no leader private key provided")
}

@ -190,8 +190,6 @@ func (consensus *Consensus) onPrepare(recvMsg *FBFTMessage) {
}
func (consensus *Consensus) onCommit(recvMsg *FBFTMessage) {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
//// Read - Start
if !consensus.isRightBlockNumAndViewID(recvMsg) {
return

@ -347,10 +347,6 @@ func (consensus *Consensus) startNewView(viewID uint64, newLeaderPriKey *bls.Pri
// onViewChange is called when the view change message is received.
func (consensus *Consensus) onViewChange(recvMsg *FBFTMessage) {
//fmt.Printf("[onViewChange] received view change message from %+v\n", recvMsg)
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.getLogger().Debug().
Uint64("viewID", recvMsg.ViewID).
Uint64("blockNum", recvMsg.BlockNum).
@ -359,7 +355,7 @@ func (consensus *Consensus) onViewChange(recvMsg *FBFTMessage) {
// if not leader, noop
newLeaderKey := recvMsg.LeaderPubkey
newLeaderPriKey, err := consensus.GetLeaderPrivateKey(newLeaderKey.Object)
newLeaderPriKey, err := consensus.getLeaderPrivateKey(newLeaderKey.Object)
if err != nil {
consensus.getLogger().Debug().
Err(err).
@ -454,9 +450,6 @@ func (consensus *Consensus) onViewChange(recvMsg *FBFTMessage) {
// Or the validator will enter announce phase to wait for the new block proposed
// from the new leader
func (consensus *Consensus) onNewView(recvMsg *FBFTMessage) {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.getLogger().Info().
Uint64("viewID", recvMsg.ViewID).
Uint64("blockNum", recvMsg.BlockNum).
@ -543,7 +536,7 @@ func (consensus *Consensus) onNewView(recvMsg *FBFTMessage) {
consensus.consensusTimeout[timeoutViewChange].Stop()
// newView message verified success, override my state
consensus.SetViewIDs(recvMsg.ViewID)
consensus.setViewIDs(recvMsg.ViewID)
consensus.LeaderPubKey = senderKey
consensus.ResetViewChangeState()

Loading…
Cancel
Save