Browse Source

Merge pull request #1420 from tendermint/1414-data-race

protect Record* peerStateStats functions by mutex
pull/1344/merge
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
0ae66f75ce
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions
  1. +16
    -3
      consensus/reactor.go

+ 16
- 3
consensus/reactor.go View File

@ -1087,6 +1087,9 @@ func (ps *PeerState) ensureVoteBitArrays(height int64, numValidators int) {
// It returns the total number of votes (1 per block). This essentially means // It returns the total number of votes (1 per block). This essentially means
// the number of blocks for which peer has been sending us votes. // the number of blocks for which peer has been sending us votes.
func (ps *PeerState) RecordVote(vote *types.Vote) int { func (ps *PeerState) RecordVote(vote *types.Vote) int {
ps.mtx.Lock()
defer ps.mtx.Unlock()
if ps.stats.lastVoteHeight >= vote.Height { if ps.stats.lastVoteHeight >= vote.Height {
return ps.stats.votes return ps.stats.votes
} }
@ -1098,13 +1101,20 @@ func (ps *PeerState) RecordVote(vote *types.Vote) int {
// VotesSent returns the number of blocks for which peer has been sending us // VotesSent returns the number of blocks for which peer has been sending us
// votes. // votes.
func (ps *PeerState) VotesSent() int { func (ps *PeerState) VotesSent() int {
ps.mtx.Lock()
defer ps.mtx.Unlock()
return ps.stats.votes return ps.stats.votes
} }
// RecordVote updates internal statistics for this peer by recording the block part.
// It returns the total number of block parts (1 per block). This essentially means
// the number of blocks for which peer has been sending us block parts.
// RecordBlockPart updates internal statistics for this peer by recording the
// block part. It returns the total number of block parts (1 per block). This
// essentially means the number of blocks for which peer has been sending us
// block parts.
func (ps *PeerState) RecordBlockPart(bp *BlockPartMessage) int { func (ps *PeerState) RecordBlockPart(bp *BlockPartMessage) int {
ps.mtx.Lock()
defer ps.mtx.Unlock()
if ps.stats.lastBlockPartHeight >= bp.Height { if ps.stats.lastBlockPartHeight >= bp.Height {
return ps.stats.blockParts return ps.stats.blockParts
} }
@ -1117,6 +1127,9 @@ func (ps *PeerState) RecordBlockPart(bp *BlockPartMessage) int {
// BlockPartsSent returns the number of blocks for which peer has been sending // BlockPartsSent returns the number of blocks for which peer has been sending
// us block parts. // us block parts.
func (ps *PeerState) BlockPartsSent() int { func (ps *PeerState) BlockPartsSent() int {
ps.mtx.Lock()
defer ps.mtx.Unlock()
return ps.stats.blockParts return ps.stats.blockParts
} }


Loading…
Cancel
Save