Fixed locks.

pull/4509/head
frozen 2 years ago committed by Casey Gardiner
parent e08ce0a0a8
commit d1a0e9cbf2
  1. 11
      consensus/consensus_service.go
  2. 9
      consensus/consensus_v2.go

@ -74,6 +74,8 @@ func (consensus *Consensus) signAndMarshalConsensusMessage(message *msg_pb.Messa
// UpdatePublicKeys updates the PublicKeys for
// quorum on current subcommittee, protected by a mutex
func (consensus *Consensus) UpdatePublicKeys(pubKeys, allowlist []bls_cosi.PublicKeyWrapper) int64 {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.Decider.UpdateParticipants(pubKeys, allowlist)
consensus.getLogger().Info().Msg("My Committee updated")
for i := range pubKeys {
@ -94,7 +96,7 @@ func (consensus *Consensus) UpdatePublicKeys(pubKeys, allowlist []bls_cosi.Publi
}
// reset states after update public keys
// TODO: incorporate bitmaps in the decider, so their state can't be inconsistent.
consensus.UpdateBitmaps()
consensus.updateBitmaps()
consensus.resetState()
// do not reset view change state if it is in view changing mode
@ -126,7 +128,7 @@ func (consensus *Consensus) signConsensusMessage(message *msg_pb.Message,
}
// UpdateBitmaps update the bitmaps for prepare and commit phase
func (consensus *Consensus) UpdateBitmaps() {
func (consensus *Consensus) updateBitmaps() {
consensus.getLogger().Debug().
Str("MessageType", consensus.phase.String()).
Msg("[UpdateBitmaps] Updating consensus bitmaps")
@ -440,9 +442,8 @@ func (consensus *Consensus) UpdateConsensusInformation() Mode {
// IsLeader check if the node is a leader or not by comparing the public key of
// the node with the leader public key
func (consensus *Consensus) IsLeader() bool {
// TODO: if remove locks blockchain stucks.
//consensus.mutex.RLock()
//defer consensus.mutex.RUnlock()
consensus.mutex.RLock()
defer consensus.mutex.RUnlock()
return consensus.isLeader()
}

@ -703,11 +703,14 @@ func (consensus *Consensus) commitBlock(blk *types.Block, committedMsg *FBFTMess
}
consensus.FinishFinalityCount()
consensus.PostConsensusJob(blk)
consensus.SetupForNewConsensus(blk, committedMsg)
go func() {
consensus.PostConsensusJob(blk)
}()
consensus.setupForNewConsensus(blk, committedMsg)
utils.Logger().Info().Uint64("blockNum", blk.NumberU64()).
Str("hash", blk.Header().Hash().Hex()).
Msg("Added New Block to Blockchain!!!")
return nil
}
@ -756,7 +759,7 @@ func (consensus *Consensus) rotateLeader(epoch *big.Int) {
}
// SetupForNewConsensus sets the state for new consensus
func (consensus *Consensus) SetupForNewConsensus(blk *types.Block, committedMsg *FBFTMessage) {
func (consensus *Consensus) setupForNewConsensus(blk *types.Block, committedMsg *FBFTMessage) {
atomic.StoreUint64(&consensus.blockNum, blk.NumberU64()+1)
consensus.SetCurBlockViewID(committedMsg.ViewID + 1)
consensus.LeaderPubKey = committedMsg.SenderPubkeys[0]

Loading…
Cancel
Save