From c3a8f202ab61a451b318acf8df5dea9c52bc097f Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 15 Dec 2015 14:44:58 -0500 Subject: [PATCH] consensus: fix negative timeout; log levels --- consensus/reactor.go | 5 ++--- consensus/state.go | 11 ++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index 29a9be86d..b0bdce934 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -283,15 +283,14 @@ func (conR *ConsensusReactor) broadcastHasVoteMessage(vote *types.Vote, index in } func makeRoundStepMessages(rs *RoundState) (nrsMsg *NewRoundStepMessage, csMsg *CommitStepMessage) { - step := RoundStepType(rs.Step) nrsMsg = &NewRoundStepMessage{ Height: rs.Height, Round: rs.Round, - Step: step, + Step: rs.Step, SecondsSinceStartTime: int(time.Now().Sub(rs.StartTime).Seconds()), LastCommitRound: rs.LastCommit.Round(), } - if step == RoundStepCommit { + if rs.Step == RoundStepCommit { csMsg = &CommitStepMessage{ Height: rs.Height, BlockPartsHeader: rs.ProposalBlockParts.Header(), diff --git a/consensus/state.go b/consensus/state.go index bb9bf586b..8dc671821 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -316,6 +316,7 @@ func (cs *ConsensusState) AddProposalBlockPart(height, round int, part *types.Pa return nil } +// May block on send if queue is full. func (cs *ConsensusState) SetProposalAndBlock(proposal *types.Proposal, block *types.Block, parts *types.PartSet, peerKey string) error { cs.SetProposal(proposal, peerKey) for i := 0; i < parts.Total(); i++ { @@ -341,6 +342,9 @@ func (cs *ConsensusState) updateRoundStep(round int, step RoundStepType) { func (cs *ConsensusState) scheduleRound0(height int) { //log.Info("scheduleRound0", "now", time.Now(), "startTime", cs.StartTime) sleepDuration := cs.StartTime.Sub(time.Now()) + if sleepDuration < time.Duration(0) { + sleepDuration = time.Duration(0) + } cs.scheduleTimeout(sleepDuration, height, 0, RoundStepNewHeight) } @@ -749,7 +753,7 @@ func (cs *ConsensusState) decideProposal(height, round int) { part := blockParts.GetPart(i) cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""}) } - log.Notice("Signed and sent proposal", "height", height, "round", round, "proposal", proposal) + log.Info("Signed and sent proposal", "height", height, "round", round, "proposal", proposal) log.Debug(Fmt("Signed and sent proposal block: %v", block)) } else { log.Warn("enterPropose: Error signing proposal", "height", height, "round", round, "error", err) @@ -1130,7 +1134,8 @@ func (cs *ConsensusState) finalizeCommit(height int) { PanicConsensus(Fmt("+2/3 committed an invalid block: %v", err)) } - log.Info(Fmt("Finalizing commit of block: %v", cs.ProposalBlock)) + log.Notice("Finalizing commit of block", "height", cs.ProposalBlock.Height, "hash", cs.ProposalBlock.Hash()) + log.Info(Fmt("%v", cs.ProposalBlock)) // We have the block, so stage/save/commit-vote. cs.saveBlock(cs.ProposalBlock, cs.ProposalBlockParts, cs.Votes.Precommits(cs.CommitRound)) @@ -1402,7 +1407,7 @@ func (cs *ConsensusState) signAddVote(type_ byte, hash []byte, header types.Part // TODO: store our index in the cs so we don't have to do this every time valIndex, _ := cs.Validators.GetByAddress(cs.privValidator.Address) cs.sendInternalMessage(msgInfo{&VoteMessage{valIndex, vote}, ""}) - log.Notice("Signed and pushed vote", "height", cs.Height, "round", cs.Round, "vote", vote, "error", err) + log.Info("Signed and pushed vote", "height", cs.Height, "round", cs.Round, "vote", vote, "error", err) return vote } else { log.Warn("Error signing vote", "height", cs.Height, "round", cs.Round, "vote", vote, "error", err)