diff --git a/consensus/consensus_service.go b/consensus/consensus_service.go index e0b1e7899..5bad092c2 100644 --- a/consensus/consensus_service.go +++ b/consensus/consensus_service.go @@ -2,6 +2,7 @@ package consensus import ( "math/big" + "sync/atomic" "github.com/ethereum/go-ethereum/common" protobuf "github.com/golang/protobuf/proto" @@ -275,9 +276,7 @@ func (consensus *Consensus) checkViewID(msg *FBFTMessage) error { // SetBlockNum sets the blockNum in consensus object, called at node bootstrap func (consensus *Consensus) SetBlockNum(blockNum uint64) { - consensus.infoMutex.Lock() - defer consensus.infoMutex.Unlock() - consensus.blockNum = blockNum + atomic.StoreUint64(&consensus.blockNum, blockNum) } // ReadSignatureBitmapPayload read the payload for signature and bitmap; offset is the beginning position of reading diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index 2f2b17ed1..90a90cd1f 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -3,6 +3,7 @@ package consensus import ( "bytes" "encoding/hex" + "sync/atomic" "time" protobuf "github.com/golang/protobuf/proto" @@ -283,7 +284,7 @@ func (consensus *Consensus) tryCatchup() { // TODO(Chao): Explain the reasoning for these code consensus.blockHash = [32]byte{} - consensus.blockNum = consensus.blockNum + 1 + atomic.AddUint64(&consensus.blockNum, 1) consensus.viewID = committedMsg.ViewID + 1 consensus.LeaderPubKey = committedMsg.SenderPubkey