diff --git a/.changelog/unreleased/improvements/3156-make-addvote-only-take-one-ps-mtx.md b/.changelog/unreleased/improvements/3156-make-addvote-only-take-one-ps-mtx.md new file mode 100644 index 0000000000..215295c2cf --- /dev/null +++ b/.changelog/unreleased/improvements/3156-make-addvote-only-take-one-ps-mtx.md @@ -0,0 +1,2 @@ +- `[consensus]` Make Vote messages only take one peerstate mutex + ([\#3156](https://github.com/cometbft/cometbft/issues/3156)) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f6a8644ab..3e648c749d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ It also includes a few other bug fixes and performance improvements. - `[indexer]` Fixed ineffective select break statements; they now point to their enclosing for loop label to exit ([\#3544](https://github.com/cometbft/cometbft/issues/3544)) +- [#91](https://github.com/osmosis-labs/cometbft/pull/91) perf(consensus): Minor improvement by making add vote only do one peer set mutex call, not 3 (#3156) ## v0.38.10 diff --git a/consensus/reactor.go b/consensus/reactor.go index 9e86e70d2e..8bb7de92b1 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -1365,6 +1365,16 @@ func (ps *PeerState) SetHasVote(vote *types.Vote) { ps.setHasVote(vote.Height, vote.Round, vote.Type, vote.ValidatorIndex) } +// SetHasVote sets the given vote as known by the peer. +func (ps *PeerState) SetHasVoteFromPeer(vote *types.Vote, csHeight int64, valSize, lastCommitSize int) { + ps.mtx.Lock() + defer ps.mtx.Unlock() + + ps.ensureVoteBitArrays(csHeight, valSize) + ps.ensureVoteBitArrays(csHeight-1, lastCommitSize) + ps.setHasVote(vote.Height, vote.Round, vote.Type, vote.ValidatorIndex) +} + func (ps *PeerState) setHasVote(height int64, round int32, voteType cmtproto.SignedMsgType, index int32) { ps.logger.Debug("setHasVote", "peerH/R",