Send prevotes before precommits in cs syncer
Send prevotes before precommits to prevent a peer from entering
precommit without polka and sending nil precommit.
@@ -93,7 +93,14 @@ func (p *peer) doSync() (module.ProtocolInfo, Message) {
if p.Height < e.Height() || (p.Height == e.Height() && e.Step() >= stepCommit) {
if p.BlockPartsMask == nil {
- vl := e.GetCommitPrecommits(p.Height)
+ var vl *voteList
+ if p.Height == e.Height() {
+ // send prevotes to prevent the peer from entering precommit
+ // without polka and sending nil precommit
+ vl = e.GetVotes(e.Round(), p.PrevotesMask, p.PrecommitsMask)
+ } else {
+ vl = e.GetCommitPrecommits(p.Height)
+ }
if vl == nil {
return 0, nil
}
@@ -135,20 +142,19 @@ func (p *peer) doSync() (module.ProtocolInfo, Message) {
return 0, nil
}
- if p.Round < e.Round() && e.Step() >= stepPrecommitWait {
- vl := e.GetPrecommits(e.Round())
+ if p.Round < e.Round() && e.Step() >= stepPrevoteWait {
+ vl := e.GetVotes(e.Round(), p.PrevotesMask, p.PrecommitsMask)
msg := newVoteListMessage()
msg.VoteList = vl
p.peerRoundState = nil
- p.log.Tracef("PC for round %v\n", e.Round())
+ p.log.Tracef("Votes for round %v\n", e.Round())
return ProtoVoteList, msg
} else if p.Round < e.Round() {
- // TODO: check peer step
- vl := e.GetPrecommits(e.Round() - 1)
+ vl := e.GetVotes(e.Round() - 1, p.PrevotesMask, p.PrecommitsMask)
msg := newVoteListMessage()
msg.VoteList = vl
p.peerRoundState = nil
- p.log.Tracef("PC for round %v (prev round)\n", e.Round())
+ p.log.Tracef("Votes for prev round %v\n", e.Round()-1)
return ProtoVoteList, msg
} else if p.Round == e.Round() {
rs := e.GetRoundState()
