Revert to one action for commit-or-next-round

This commit is contained in:
Jae Kwon 2014-10-26 04:16:24 -07:00
parent 0f484b6315
commit 6416185a6f
2 changed files with 18 additions and 20 deletions

View File

@ -319,7 +319,7 @@ func (conR *ConsensusReactor) stepTransitionRoutine() {
case RoundStepPrecommit: case RoundStepPrecommit:
// Wake up when the round is over. // Wake up when the round is over.
time.Sleep(time.Duration((1.0 - elapsedRatio) * float64(roundDuration))) time.Sleep(time.Duration((1.0 - elapsedRatio) * float64(roundDuration)))
conR.doActionCh <- RoundAction{rs.Height, rs.Round, RoundActionNextRound} conR.doActionCh <- RoundAction{rs.Height, rs.Round, RoundActionTryCommit}
case RoundStepCommit: case RoundStepCommit:
panic("Should not happen: RoundStepCommit waits until +2/3 commits.") panic("Should not happen: RoundStepCommit waits until +2/3 commits.")
case RoundStepCommitWait: case RoundStepCommitWait:
@ -372,8 +372,8 @@ ACTION_LOOP:
if height != rs.Height { if height != rs.Height {
continue continue
} }
// If action >= RoundActionCommit, the round doesn't matter. // If action >= RoundActionCommitWait, the round doesn't matter.
if action < RoundActionCommit && round != rs.Round { if action < RoundActionCommitWait && round != rs.Round {
continue continue
} }
@ -412,26 +412,25 @@ ACTION_LOOP:
scheduleNextAction() scheduleNextAction()
continue ACTION_LOOP continue ACTION_LOOP
case RoundActionNextRound: case RoundActionTryCommit:
if rs.Step >= RoundStepCommit { if rs.Step >= RoundStepCommit {
continue ACTION_LOOP continue ACTION_LOOP
} }
conR.conS.SetupRound(rs.Round + 1) if rs.Precommits.HasTwoThirdsMajority() {
scheduleNextAction() // NOTE: Duplicated in RoundActionCommitWait.
continue ACTION_LOOP vote := conR.conS.RunActionCommit(rs.Height, rs.Round)
broadcastNewRoundStep(RoundStepCommit)
case RoundActionCommit: if vote != nil {
if rs.Step >= RoundStepCommit { conR.broadcastVote(rs, vote)
}
// do not schedule next action.
continue ACTION_LOOP
} else {
// Could not commit, move onto next round.
conR.conS.SetupRound(rs.Round + 1)
scheduleNextAction()
continue ACTION_LOOP continue ACTION_LOOP
} }
// NOTE: Duplicated in RoundActionCommitWait.
vote := conR.conS.RunActionCommit(rs.Height, rs.Round)
broadcastNewRoundStep(RoundStepCommit)
if vote != nil {
conR.broadcastVote(rs, vote)
}
// do not schedule next action.
continue ACTION_LOOP
case RoundActionCommitWait: case RoundActionCommitWait:
if rs.Step >= RoundStepCommitWait { if rs.Step >= RoundStepCommitWait {

View File

@ -36,8 +36,7 @@ const (
RoundActionPropose = RoundActionType(0x00) // Goto RoundStepPropose RoundActionPropose = RoundActionType(0x00) // Goto RoundStepPropose
RoundActionPrevote = RoundActionType(0x01) // Goto RoundStepPrevote RoundActionPrevote = RoundActionType(0x01) // Goto RoundStepPrevote
RoundActionPrecommit = RoundActionType(0x02) // Goto RoundStepPrecommit RoundActionPrecommit = RoundActionType(0x02) // Goto RoundStepPrecommit
RoundActionNextRound = RoundActionType(0x04) // Goto next round RoundStepStart RoundActionTryCommit = RoundActionType(0x10) // Goto RoundStepCommit or RoundStepStart next round
RoundActionCommit = RoundActionType(0x10) // Goto RoundStepCommit or RoundStepStart next round
RoundActionCommitWait = RoundActionType(0x11) // Goto RoundStepCommitWait RoundActionCommitWait = RoundActionType(0x11) // Goto RoundStepCommitWait
RoundActionFinalize = RoundActionType(0x12) // Goto RoundStepStart next height RoundActionFinalize = RoundActionType(0x12) // Goto RoundStepStart next height
) )