Skip to content

Commit da204d3

Browse files
authoredNov 28, 2022
consensus: correctly save reference to previous height precommits (#9760)
This change reduces the number of Precommit messages sent to peers by 50%. During the `ApplyNewRoundStepMessage`, we update the known state of the peer sending us the message. We set the value of `ps.PRS.Precommits` to nil in this method if the peer is entering a new height or round. https://github.com/tendermint/tendermint/blob/34ca3fb4741cdb205a4714d345218a0d5e9fefd0/consensus/reactor.go#L1368 We then assign `ps.PRS.LastCommit = ps.PRS.Precommits` if the peer is entering a new height only - this does not happen during just a round change. This therefore results in `ps.PRS.LastCommit` having the value `nil`. When the `LastCommit` bit field is seen as `nil` in the reactor, an empty bit field is initialized. https://github.com/tendermint/tendermint/blob/34ca3fb4741cdb205a4714d345218a0d5e9fefd0/consensus/reactor.go#L1273 The code responsible for gossiping votes from the previous height uses this `LastCommit` value and, seeing an empty `LastCommit` will resend every `Precommit` from the previous height since it lost the information it previously had detailing which precommits from the previous height the peer had. This can be seen in the code responsible for gossiping precommits from the previous height: https://github.com/tendermint/tendermint/blob/34ca3fb4741cdb205a4714d345218a0d5e9fefd0/consensus/reactor.go#L773 Where this code grabs the, previously `nil`, `LastCommit` bit field: https://github.com/tendermint/tendermint/blob/34ca3fb4741cdb205a4714d345218a0d5e9fefd0/consensus/reactor.go#L1204-L1212 --- #### PR checklist - [ ] Tests written/updated, or no tests needed - [ ] `CHANGELOG_PENDING.md` updated, or no changelog entry needed - [ ] Updated relevant documentation (`docs/`) and code comments, or no documentation updates needed
1 parent 9d01a68 commit da204d3

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
 

‎CHANGELOG_PENDING.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
- [p2p/pex] \#6509 Improve addrBook.hash performance (@cuonglm)
3535
- [crypto/merkle] \#6443 & \#6513 Improve HashAlternatives performance (@cuonglm, @marbar3778)
3636
- [rpc] \#9650 Enable caching of RPC responses (@JayT106)
37+
- [consensus] \#9760 Save peer LastCommit correctly to achieve 50% reduction in gossiped precommits. (@williambanfield)
3738

3839
### BUG FIXES
3940

‎consensus/reactor.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,7 @@ func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage) {
13511351
psRound := ps.PRS.Round
13521352
psCatchupCommitRound := ps.PRS.CatchupCommitRound
13531353
psCatchupCommit := ps.PRS.CatchupCommit
1354+
lastPrecommits := ps.PRS.Precommits
13541355

13551356
startTime := tmtime.Now().Add(-1 * time.Duration(msg.SecondsSinceStartTime) * time.Second)
13561357
ps.PRS.Height = msg.Height
@@ -1378,7 +1379,7 @@ func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage) {
13781379
// Shift Precommits to LastCommit.
13791380
if psHeight+1 == msg.Height && psRound == msg.LastCommitRound {
13801381
ps.PRS.LastCommitRound = msg.LastCommitRound
1381-
ps.PRS.LastCommit = ps.PRS.Precommits
1382+
ps.PRS.LastCommit = lastPrecommits
13821383
} else {
13831384
ps.PRS.LastCommitRound = msg.LastCommitRound
13841385
ps.PRS.LastCommit = nil

0 commit comments

Comments
 (0)