[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
if consensus.Decider.IsQuorumAchievedByMask(consensus.vc.GetViewIDBitmap(recvMsg.ViewID)) {
consensus.getLogger().Info().Msg("[onViewChange] View Change Message Quorum Reached")
consensus.current.SetMode(Normal)
consensus.getLogger().Info().Msg("[onViewChange] View Change Message Quorum Reached")
consensus.LeaderPubKey = newLeaderKey
consensus.ResetState()
if consensus.vc.IsM1PayloadEmpty() {

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

Loading…
Cancel
Save