Skip to content

Commit

Permalink
fix(consensus): move to new round on decided vote (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f authored May 30, 2024
1 parent e4a2536 commit b80d905
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion consensus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func DefaultConfig() *Config {
return &Config{
ChangeProposerTimeout: 8 * time.Second,
ChangeProposerDelta: 4 * time.Second,
MinimumAvailabilityScore: 0.9,
MinimumAvailabilityScore: 0.6666666,
}
}

Expand Down
2 changes: 2 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ func (cs *consensus) AddVote(v *vote.Vote) {

return
}

cs.strongTerminationOnDecidedVote(v)
}

added, err := cs.log.AddVote(v)
Expand Down
24 changes: 24 additions & 0 deletions consensus/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,30 @@ func (cp *changeProposer) checkJust(v *vote.Vote) error {
}
}

func (cs *consensus) strongTerminationOnDecidedVote(v *vote.Vote) {
// TODO: merge me with strongTermination
if v.Type() != vote.VoteTypeCPDecided {
return
}

if v.Round() > cs.round {
cs.logger.Info("move to new round on decided vote", "vote", v)
if v.CPValue() == vote.CPValueOne {
cs.round = v.Round() + 1
cs.cpDecided = 1
cs.enterNewState(cs.proposeState)
} else if v.CPValue() == vote.CPValueZero {
roundProposal := cs.log.RoundProposal(cs.round)
if roundProposal == nil {
cs.queryProposal()
}
cs.round = v.Round()
cs.cpDecided = 0
cs.enterNewState(cs.prepareState)
}
}
}

func (cp *changeProposer) strongTermination() {
cpDecided := cp.log.CPDecidedVoteVoteSet(cp.round)
if cpDecided.HasAnyVoteFor(cp.cpRound, vote.CPValueZero) {
Expand Down

0 comments on commit b80d905

Please sign in to comment.