[viewchange] add RLock for m1Payload functions

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3388/head
Leo Chen 4 years ago
parent cadec98dd9
commit b6deec9a5a
  1. 2
      consensus/view_change.go
  2. 3
      consensus/view_change_construct.go

@ -230,8 +230,8 @@ func (consensus *Consensus) onViewChange(msg *msg_pb.Message) {
// received enough view change messages, change state to normal consensus // received enough view change messages, change state to normal consensus
if consensus.Decider.IsQuorumAchievedByMask(consensus.vc.GetViewIDBitmap(recvMsg.ViewID)) { if consensus.Decider.IsQuorumAchievedByMask(consensus.vc.GetViewIDBitmap(recvMsg.ViewID)) {
consensus.getLogger().Info().Msg("[onViewChange] View Change Message Quorum Reached")
consensus.current.SetMode(Normal) consensus.current.SetMode(Normal)
consensus.getLogger().Info().Msg("[onViewChange] View Change Message Quorum Reached")
consensus.LeaderPubKey = newLeaderKey consensus.LeaderPubKey = newLeaderKey
consensus.ResetState() consensus.ResetState()
if consensus.vc.IsM1PayloadEmpty() { if consensus.vc.IsM1PayloadEmpty() {

@ -438,6 +438,7 @@ func (vc *viewChange) InitPayload(
} }
// isM1PayloadEmpty returns true if m1Payload is not set // isM1PayloadEmpty returns true if m1Payload is not set
// this is an unlocked internal function call
func (vc *viewChange) isM1PayloadEmpty() bool { func (vc *viewChange) isM1PayloadEmpty() bool {
return len(vc.m1Payload) == 0 return len(vc.m1Payload) == 0
} }
@ -458,6 +459,8 @@ func (vc *viewChange) GetViewIDBitmap(viewID uint64) *bls_cosi.Mask {
// GetM1Payload returns the m1Payload // GetM1Payload returns the m1Payload
func (vc *viewChange) GetM1Payload() []byte { func (vc *viewChange) GetM1Payload() []byte {
vc.vcLock.RLock()
defer vc.vcLock.RUnlock()
return vc.m1Payload return vc.m1Payload
} }

Loading…
Cancel
Save