From fc0a4bae4e94d7d084818720fa829407adf06b04 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 5 Jul 2015 15:35:26 -0700 Subject: [PATCH] Do not reset Proposal* when EnterNewRound(0) --- consensus/reactor.go | 15 +++++++++++++-- consensus/state.go | 19 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index a6ea168b..24081d39 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -458,35 +458,43 @@ OUTER_LOOP: sleeping = 0 } + log.Debug("gossipVotesRoutine", "rsHeight", rs.Height, "rsRound", rs.Round, + "prsHeight", prs.Height, "prsRound", prs.Round, "prsStep", prs.Step) + // If height matches, then send LastCommit, Prevotes, Precommits. if rs.Height == prs.Height { // If there are lastCommits to send... if prs.Step == RoundStepNewHeight { if ps.PickSendVote(rs.LastCommit) { + log.Debug("Picked rs.LastCommit to send") continue OUTER_LOOP } } // If there are prevotes to send... if rs.Round == prs.Round && prs.Step <= RoundStepPrevote { if ps.PickSendVote(rs.Votes.Prevotes(rs.Round)) { + log.Debug("Picked rs.Prevotes(rs.Round) to send") continue OUTER_LOOP } } // If there are precommits to send... if rs.Round == prs.Round && prs.Step <= RoundStepPrecommit { if ps.PickSendVote(rs.Votes.Precommits(rs.Round)) { + log.Debug("Picked rs.Precommits(rs.Round) to send") continue OUTER_LOOP } } // If there are prevotes to send for the last round... if rs.Round == prs.Round+1 && prs.Step <= RoundStepPrevote { if ps.PickSendVote(rs.Votes.Prevotes(prs.Round)) { + log.Debug("Picked rs.Prevotes(prs.Round) to send") continue OUTER_LOOP } } // If there are precommits to send for the last round... if rs.Round == prs.Round+1 && prs.Step <= RoundStepPrecommit { if ps.PickSendVote(rs.Votes.Precommits(prs.Round)) { + log.Debug("Picked rs.Precommits(prs.Round) to send") continue OUTER_LOOP } } @@ -494,6 +502,7 @@ OUTER_LOOP: if 0 <= prs.ProposalPOLRound { if polPrevotes := rs.Votes.Prevotes(prs.ProposalPOLRound); polPrevotes != nil { if ps.PickSendVote(polPrevotes) { + log.Debug("Picked rs.Prevotes(prs.ProposalPOLRound) to send") continue OUTER_LOOP } } @@ -502,20 +511,22 @@ OUTER_LOOP: // Special catchup logic. // If peer is lagging by height 1, send LastCommit. - if prs.Height != 0 && prs.Height == rs.Height-1 { + if prs.Height != 0 && rs.Height == prs.Height+1 { if ps.PickSendVote(rs.LastCommit) { + log.Debug("Picked rs.LastCommit to send") continue OUTER_LOOP } } // Catchup logic // If peer is lagging by more than 1, send Validation. - if prs.Height != 0 && prs.Height <= rs.Height-2 { + if prs.Height != 0 && rs.Height <= prs.Height+2 { // Load the block validation for prs.Height, // which contains precommit signatures for prs.Height. validation := conR.blockStore.LoadBlockValidation(prs.Height) log.Debug("Loaded BlockValidation for catch-up", "height", prs.Height, "validation", validation) if ps.PickSendVote(validation) { + log.Debug("Picked Catchup validation to send") continue OUTER_LOOP } } diff --git a/consensus/state.go b/consensus/state.go index d1c19845..37803a22 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -491,6 +491,7 @@ func (cs *ConsensusState) EnterNewRound(height int, round int) { if now := time.Now(); cs.StartTime.After(now) { log.Warn("Need to set a buffer and log.Warn() here for sanity.", "startTime", cs.StartTime, "now", now) } + log.Debug(Fmt("EnterNewRound(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) // Increment validators if necessary validators := cs.Validators @@ -503,9 +504,15 @@ func (cs *ConsensusState) EnterNewRound(height int, round int) { cs.Round = round cs.Step = RoundStepNewRound cs.Validators = validators - cs.Proposal = nil - cs.ProposalBlock = nil - cs.ProposalBlockParts = nil + if round == 0 { + // We've already reset these upon new height, + // and meanwhile we might have received a proposal + // for round 0. + } else { + cs.Proposal = nil + cs.ProposalBlock = nil + cs.ProposalBlockParts = nil + } cs.Votes.SetRound(round + 1) // also track next round (round+1) to allow round-skipping // Immediately go to EnterPropose. @@ -520,6 +527,7 @@ func (cs *ConsensusState) EnterPropose(height int, round int) { log.Debug(Fmt("EnterPropose(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } + log.Debug(Fmt("EnterPropose(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) defer func() { // Done EnterPropose: @@ -652,6 +660,7 @@ func (cs *ConsensusState) EnterPrevote(height int, round int) { log.Debug(Fmt("EnterPrevote(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } + log.Debug(Fmt("EnterPrevote(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) // Sign and broadcast vote as necessary cs.doPrevote(height, round) @@ -706,6 +715,7 @@ func (cs *ConsensusState) EnterPrevoteWait(height int, round int) { if !cs.Votes.Prevotes(round).HasTwoThirdsAny() { panic(Fmt("EnterPrevoteWait(%v/%v), but Prevotes does not have any +2/3 votes", height, round)) } + log.Debug(Fmt("EnterPrevoteWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) // Done EnterPrevoteWait: cs.Round = round @@ -732,6 +742,7 @@ func (cs *ConsensusState) EnterPrecommit(height int, round int) { log.Debug(Fmt("EnterPrecommit(%v/%v): Invalid args. Current step: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) return } + log.Debug(Fmt("EnterPrecommit(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) defer func() { // Done EnterPrecommit: @@ -823,6 +834,7 @@ func (cs *ConsensusState) EnterPrecommitWait(height int, round int) { if !cs.Votes.Precommits(round).HasTwoThirdsAny() { panic(Fmt("EnterPrecommitWait(%v/%v), but Precommits does not have any +2/3 votes", height, round)) } + log.Debug(Fmt("EnterPrecommitWait(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) // Done EnterPrecommitWait: cs.Round = round @@ -848,6 +860,7 @@ func (cs *ConsensusState) EnterCommit(height int) { log.Debug(Fmt("EnterCommit(%v): Invalid args. Current step: %v/%v/%v", height, cs.Height, cs.Round, cs.Step)) return } + log.Debug(Fmt("EnterCommit(%v). Current: %v/%v/%v", height, cs.Height, cs.Round, cs.Step)) defer func() { // Done Entercommit: