Skip to content

Commit

Permalink
remove naming of updateMtx field to improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-soon committed Jul 18, 2024
1 parent c7eee39 commit eb3b33c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions oracle/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions oracle/service/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions oracle/service/types/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit eb3b33c

Please sign in to comment.