Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(consensus): Make late votes outside of last block commits not get to peerMsgQueue #3157

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [`consensus`] Check for late votes in the reactor, preventing them from entering the
single-threaded consensus logic. This change is a performance optimization that reduces the number
of redundant votes that are processed by the consensus logic.
([\#3157](https://github.com/cometbft/cometbft/issues/3157)
14 changes: 12 additions & 2 deletions internal/consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,19 @@ func (conR *Reactor) Receive(e p2p.Envelope) {
case *VoteMessage:
cs := conR.conS
cs.mtx.RLock()
height, valSize, lastCommitSize := cs.Height, cs.Validators.Size(), cs.LastCommit.Size()
csHeight, csRound, valSize, lastCommitSize := cs.Height, cs.Round, cs.Validators.Size(), cs.LastCommit.Size()
cs.mtx.RUnlock()
ps.SetHasVoteFromPeer(msg.Vote, height, valSize, lastCommitSize)
ps.SetHasVoteFromPeer(msg.Vote, csHeight, valSize, lastCommitSize)

// if vote is late, and is not a precommit for the last block, mark it late and return.
isLate := msg.Vote.Height < csHeight || (msg.Vote.Height == csHeight && msg.Vote.Round < csRound)
if isLate {
notLastBlockPrecommit := msg.Vote.Type != types.PrecommitType || msg.Vote.Height != csHeight-1
if notLastBlockPrecommit {
cs.metrics.MarkLateVote(msg.Vote.Type)
cason marked this conversation as resolved.
Show resolved Hide resolved
return
}
}

cs.peerMsgQueue <- msgInfo{msg, e.Src.ID(), time.Time{}}

Expand Down
Loading