From 6d168145c9458790d0756d1e9aabda2a6ea09321 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 12 Sep 2022 14:32:51 +0200 Subject: [PATCH] move log back, fix compile err --- consensus/state.go | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 5a4c3c7a3..c147d7347 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -770,14 +770,6 @@ func (cs *State) receiveRoutine(maxSteps int) { // may generate internal events (votes, complete proposals, 2/3 majorities) err := cs.handleMsg(mi) if err != nil { - cs.Logger.Error( - "failed to process message", - "height", cs.Height, - "round", cs.Round, - "peer", peerID, - "msg_type", fmt.Sprintf("%T", msg), - "err", err, - ) // if error is due to misbehaviour, disconect from peer // TODO: can we create some higher order type to collect these errors in? switch err { @@ -812,17 +804,9 @@ func (cs *State) receiveRoutine(maxSteps int) { } // handles proposals, block parts, votes - err := cs.handleMsg(mi) - if err != nil { + if err := cs.handleMsg(mi); err != nil { // TODO: why are we erroring on our own messages? // should we panic ? - cs.Logger.Error( - "failed to process internal message", - "height", cs.Height, - "round", cs.Round, - "msg_type", fmt.Sprintf("%T", msg), - "err", err, - ) } case ti := <-cs.timeoutTicker.Chan(): // tockChan: @@ -842,7 +826,7 @@ func (cs *State) receiveRoutine(maxSteps int) { } // state transitions on complete-proposal, 2/3-any, 2/3-one -func (cs *State) handleMsg(mi msgInfo) error { +func (cs *State) handleMsg(mi msgInfo) (err error) { cs.mtx.Lock() defer cs.mtx.Unlock() @@ -852,11 +836,12 @@ func (cs *State) handleMsg(mi msgInfo) error { case *ProposalMessage: // will not cause transition. // once proposal is set, we can receive block parts - return cs.setProposal(msg.Proposal) + err = cs.setProposal(msg.Proposal) case *BlockPartMessage: // if the proposal is complete, we'll enterPrevote or tryFinalizeCommit - added, err := cs.addProposalBlockPart(msg, peerID) + var added bool + added, err = cs.addProposalBlockPart(msg, peerID) // We unlock here to yield to any routines that need to read the the RoundState. // Previously, this code held the lock from the point at which the final block @@ -888,12 +873,12 @@ func (cs *State) handleMsg(mi msgInfo) error { ) err = nil } - return err case *VoteMessage: + var added bool // attempt to add the vote and dupeout the validator if its a duplicate signature // if the vote gives us a 2/3-any or 2/3-one, we transition - added, err := cs.tryAddVote(msg.Vote, peerID) + added, err = cs.tryAddVote(msg.Vote, peerID) if added { cs.statsMsgQueue <- mi } @@ -912,12 +897,23 @@ func (cs *State) handleMsg(mi msgInfo) error { // TODO: If rs.Height == vote.Height && rs.Round < vote.Round, // the peer is sending us CatchupCommit precommits. // We could make note of this and help filter in broadcastHasVoteMessage(). - return err default: cs.Logger.Error("unknown msg type", "type", fmt.Sprintf("%T", msg)) return nil } + + if err != nil { + cs.Logger.Error( + "failed to process message", + "height", cs.Height, + "round", cs.Round, + "peer", peerID, + "msg_type", fmt.Sprintf("%T", msg), + "err", err, + ) + } + return err } func (cs *State) handleTimeout(ti timeoutInfo, rs cstypes.RoundState) {