From eb3b33c900e528e093f861bfebe90b61658954a5 Mon Sep 17 00:00:00 2001 From: yan-soon Date: Thu, 18 Jul 2024 14:34:38 +0800 Subject: [PATCH] remove naming of updateMtx field to improve code readability --- oracle/reactor.go | 8 ++++---- oracle/service/runner/runner.go | 16 ++++++++-------- oracle/service/types/info.go | 8 ++++---- state/execution.go | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/oracle/reactor.go b/oracle/reactor.go index 91392f1970a..96ac07da7de 100644 --- a/oracle/reactor.go +++ b/oracle/reactor.go @@ -189,7 +189,7 @@ func (oracleR *Reactor) Receive(e p2p.Envelope) { } preLockTime := time.Now().UnixMilli() - oracleR.OracleInfo.GossipVoteBuffer.UpdateMtx.Lock() + oracleR.OracleInfo.GossipVoteBuffer.Lock() currentGossipVote, ok := oracleR.OracleInfo.GossipVoteBuffer.Buffer[pubKey.Address().String()] if !ok { @@ -204,7 +204,7 @@ func (oracleR *Reactor) Receive(e p2p.Envelope) { oracleR.OracleInfo.GossipVoteBuffer.Buffer[pubKey.Address().String()] = msg } } - oracleR.OracleInfo.GossipVoteBuffer.UpdateMtx.Unlock() + oracleR.OracleInfo.GossipVoteBuffer.Unlock() postLockTime := time.Now().UnixMilli() diff := postLockTime - preLockTime if diff > 100 { @@ -261,7 +261,7 @@ func (oracleR *Reactor) broadcastVoteRoutine(peer p2p.Peer) { } preLockTime := time.Now().UnixMilli() - oracleR.OracleInfo.GossipVoteBuffer.UpdateMtx.RLock() + oracleR.OracleInfo.GossipVoteBuffer.RLock() votes := []*oracleproto.GossipedVotes{} for _, gossipVote := range oracleR.OracleInfo.GossipVoteBuffer.Buffer { // stop sending gossip votes that have passed the maxGossipVoteAge @@ -271,7 +271,7 @@ func (oracleR *Reactor) broadcastVoteRoutine(peer p2p.Peer) { votes = append(votes, gossipVote) } - oracleR.OracleInfo.GossipVoteBuffer.UpdateMtx.RUnlock() + oracleR.OracleInfo.GossipVoteBuffer.RUnlock() postLockTime := time.Now().UnixMilli() diff := postLockTime - preLockTime if diff > 100 { diff --git a/oracle/service/runner/runner.go b/oracle/service/runner/runner.go index 3b6598a6c45..34b5d5d9a11 100644 --- a/oracle/service/runner/runner.go +++ b/oracle/service/runner/runner.go @@ -53,13 +53,13 @@ func ProcessSignVoteQueue(oracleInfo *types.OracleInfo, consensusState *cs.State // batch sign the new votes, along with existing votes in gossipVoteBuffer, if any // append new batch into unsignedVotesBuffer, need to mutex lock as it will clash with concurrent pruning - oracleInfo.UnsignedVoteBuffer.UpdateMtx.Lock() + oracleInfo.UnsignedVoteBuffer.Lock() oracleInfo.UnsignedVoteBuffer.Buffer = append(oracleInfo.UnsignedVoteBuffer.Buffer, votes...) unsignedVotes := []*oracleproto.Vote{} unsignedVotes = append(unsignedVotes, oracleInfo.UnsignedVoteBuffer.Buffer...) - oracleInfo.UnsignedVoteBuffer.UpdateMtx.Unlock() + oracleInfo.UnsignedVoteBuffer.Unlock() // sort the votes so that we can rebuild it in a deterministic order, when uncompressing SortOracleVotes(unsignedVotes) @@ -86,10 +86,10 @@ func ProcessSignVoteQueue(oracleInfo *types.OracleInfo, consensusState *cs.State // need to mutex lock as it will clash with concurrent gossip preLockTime := time.Now().UnixMilli() - oracleInfo.GossipVoteBuffer.UpdateMtx.Lock() + oracleInfo.GossipVoteBuffer.Lock() address := oracleInfo.PubKey.Address().String() oracleInfo.GossipVoteBuffer.Buffer[address] = newGossipVote - oracleInfo.GossipVoteBuffer.UpdateMtx.Unlock() + oracleInfo.GossipVoteBuffer.Unlock() postLockTime := time.Now().UnixMilli() diff := postLockTime - preLockTime if diff > 100 { @@ -131,7 +131,7 @@ func PruneVoteBuffers(oracleInfo *types.OracleInfo, consensusState *cs.State) { latestAllowableTimestamp = oracleInfo.BlockTimestamps[0] } - oracleInfo.UnsignedVoteBuffer.UpdateMtx.Lock() + oracleInfo.UnsignedVoteBuffer.Lock() newVotes := []*oracleproto.Vote{} unsignedVoteBuffer := oracleInfo.UnsignedVoteBuffer.Buffer visitedVoteMap := make(map[string]struct{}) @@ -160,10 +160,10 @@ func PruneVoteBuffers(oracleInfo *types.OracleInfo, consensusState *cs.State) { } } oracleInfo.UnsignedVoteBuffer.Buffer = newVotes - oracleInfo.UnsignedVoteBuffer.UpdateMtx.Unlock() + oracleInfo.UnsignedVoteBuffer.Unlock() preLockTime := time.Now().UnixMilli() - oracleInfo.GossipVoteBuffer.UpdateMtx.Lock() + oracleInfo.GossipVoteBuffer.Lock() gossipBuffer := oracleInfo.GossipVoteBuffer.Buffer // prune gossipedVotes that are older than the latestAllowableTimestamp, which is the max(earliest block timestamp collected, current time - maxOracleGossipAge) @@ -173,7 +173,7 @@ func PruneVoteBuffers(oracleInfo *types.OracleInfo, consensusState *cs.State) { } } oracleInfo.GossipVoteBuffer.Buffer = gossipBuffer - oracleInfo.GossipVoteBuffer.UpdateMtx.Unlock() + oracleInfo.GossipVoteBuffer.Unlock() postLockTime := time.Now().UnixMilli() diff := postLockTime - preLockTime if diff > 100 { diff --git a/oracle/service/types/info.go b/oracle/service/types/info.go index cd16f6f9435..5d291efb1c5 100644 --- a/oracle/service/types/info.go +++ b/oracle/service/types/info.go @@ -22,13 +22,13 @@ type OracleInfo struct { BlockTimestamps []int64 } type GossipVoteBuffer struct { - Buffer map[string]*oracleproto.GossipedVotes - UpdateMtx cmtsync.RWMutex + Buffer map[string]*oracleproto.GossipedVotes + cmtsync.RWMutex } type UnsignedVoteBuffer struct { - Buffer []*oracleproto.Vote - UpdateMtx cmtsync.RWMutex + Buffer []*oracleproto.Vote + cmtsync.RWMutex } var MainAccountSigPrefix = []byte{0x00} diff --git a/state/execution.go b/state/execution.go index 846a9d3a6d6..c88c872589d 100644 --- a/state/execution.go +++ b/state/execution.go @@ -169,13 +169,13 @@ func (blockExec *BlockExecutor) CreateProposalBlock( // check if oracle's gossipVoteMap has any results preLockTime := time.Now().UnixMilli() - blockExec.oracleInfo.GossipVoteBuffer.UpdateMtx.RLock() + blockExec.oracleInfo.GossipVoteBuffer.RLock() oracleVotesBuffer := blockExec.oracleInfo.GossipVoteBuffer.Buffer votes := []*oracleproto.GossipedVotes{} for _, vote := range oracleVotesBuffer { votes = append(votes, vote) } - blockExec.oracleInfo.GossipVoteBuffer.UpdateMtx.RUnlock() + blockExec.oracleInfo.GossipVoteBuffer.RUnlock() postLockTime := time.Now().UnixMilli() diff := postLockTime - preLockTime if diff > 100 {