Skip to content

Commit

Permalink
fix(consensus): refcator strong termination for change-proposer phase (
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad authored Dec 14, 2024
1 parent ade44b8 commit 3e82c65
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
6 changes: 0 additions & 6 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,6 @@ func (cs *consensus) AddVote(vte *vote.Vote) {
cs.logger.Info("new vote added", "vote", vte)

cs.currentState.onAddVote(vte)

if vte.Type() == vote.VoteTypeCPDecided {
if vte.Round() > cs.round {
cs.changeProposer.cpDecide(vte.Round(), vte.CPValue())
}
}
}
}

Expand Down
21 changes: 7 additions & 14 deletions consensus/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,26 +313,19 @@ func (cp *changeProposer) checkJust(vte *vote.Vote) error {
func (cp *changeProposer) cpStrongTermination() {
cpDecided := cp.log.CPDecidedVoteSet(cp.round)
if cpDecided.HasAnyVoteFor(cp.cpRound, vote.CPValueNo) {
cp.cpDecide(cp.round, vote.CPValueNo)
} else if cpDecided.HasAnyVoteFor(cp.cpRound, vote.CPValueYes) {
cp.cpDecide(cp.round, vote.CPValueYes)
}
}

func (cp *changeProposer) cpDecide(round int16, cpValue vote.CPValue) {
if cpValue == vote.CPValueYes {
cp.round = round + 1
cp.cpDecided = 1
cp.enterNewState(cp.proposeState)
} else if cpValue == vote.CPValueNo {
cp.round = round
cp.cpDecided = 0

roundProposal := cp.log.RoundProposal(cp.round)
if roundProposal == nil {
cp.queryProposal()
}

cp.enterNewState(cp.prepareState)
} else if cpDecided.HasAnyVoteFor(cp.cpRound, vote.CPValueYes) {
cp.round++
cp.cpDecided = 1
cp.enterNewState(cp.proposeState)

// Check if there is any decided vote for the next round.
cp.cpStrongTermination()
}
}
2 changes: 0 additions & 2 deletions consensus/cp_decide.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (s *cpDecideState) decide() {
QCert: cert,
}
s.signAddCPDecidedVote(hash.UndefHash, s.cpRound, vote.CPValueYes, just)
s.cpDecide(s.round, vote.CPValueYes)
} else if cpMainVotes.HasQuorumVotesFor(s.cpRound, vote.CPValueNo) {
// decided for no and proceeds to the next round
s.logger.Info("binary agreement decided", "value", 0, "round", s.cpRound)
Expand All @@ -37,7 +36,6 @@ func (s *cpDecideState) decide() {
QCert: cert,
}
s.signAddCPDecidedVote(*s.cpWeakValidity, s.cpRound, vote.CPValueNo, just)
s.cpDecide(s.round, vote.CPValueNo)
} else {
// conflicting votes
s.logger.Debug("conflicting main votes", "round", s.cpRound)
Expand Down

0 comments on commit 3e82c65

Please sign in to comment.