// handleMessage handles an Envelope sent from a peer on a specific p2p Channel.
// It will handle errors and any possible panics gracefully. A caller can handle
// any error returned by sending a PeerError on the respective channel.
//
// NOTE: We process these messages even when we're block syncing. Messages affect
// either a peer state or the consensus state. Peer state updates can happen in
// parallel, but processing of proposals, block parts, and votes are ordered by
// the p2p channel.
//
// NOTE: We block on consensus state for proposals, block parts, and votes.
handleMessage handles an Envelope sent from a peer on a specific p2p Channel.
It will handle errors and any possible panics gracefully. A caller can handle
any error returned by sending a PeerError on the respective channel.

We process these messages even when we're block syncing. Messages affect
either a peer state or the consensus state. Peer state updates can happen in
parallel, but processing of proposals, block parts, and votes are ordered by
the p2p channel.

We block on consensus state for proposals, block parts, and votes.
// handleMessage handles an Envelope sent from a peer on a specific p2p Channel . // It will handle errors and any possible panics gracefully . A caller can handle // any error returned by sending a PeerError on the respective channel . // // NOTE : We process these messages even when we ' re block syncing . Messages affect // either a peer state or the consensus state . Peer state updates can happen in // parallel but processing of proposals block parts and votes are ordered by // the p2p channel . // // NOTE : We block on consensus state for proposals block parts and votes .
func (r *Reactor) handleMessage(chID p2p.ChannelID, envelope p2p.Envelope) (err error) {
	defer func() {
		if e := recover(); e != nil {
			err = fmt.Errorf("panic in processing message: %v", e)
			r.Logger.Error(
				"recovering from processing message panic",
				"err", err,
				"stack", string(debug.Stack()),
			)
		}
	}()
	protoMsg := new(tmcons.Message)
	if err := protoMsg.Wrap(envelope.Message); err != nil {
		return err
	}
	msgI, err := MsgFromProto(protoMsg)
	if err != nil {
		return err
	}
	r.Logger.Debug("received message", "ch_id", chID, "message", msgI, "peer", envelope.From)
	switch chID {
	case StateChannel:
		err = r.handleStateMessage(envelope, msgI)
	case DataChannel:
		err = r.handleDataMessage(envelope, msgI)
	case VoteChannel:
		err = r.handleVoteMessage(envelope, msgI)
	case VoteSetBitsChannel:
		err = r.handleVoteSetBitsMessage(envelope, msgI)
	default:
		err = fmt.Errorf("unknown channel ID (%d) for envelope (%v)", chID, envelope)
	}
	return err
}
func ( r * Reactor ) handleMessage ( chID p2p . ChannelID , envelope p2p . Envelope ) ( err error ) { defer func ( ) { if e := recover ( ) ; e != nil { err = fmt . Errorf ( " " , e ) r . Logger . Error ( " " , " " , err , " " , string ( debug . Stack ( ) ) , ) } } ( ) protoMsg := new ( tmcons . Message ) if err := protoMsg . Wrap ( envelope . Message ) ; err != nil { return err } msgI , err := MsgFromProto ( protoMsg ) if err != nil { return err } r . Logger . Debug ( " " , " " , chID , " " , msgI , " " , envelope . From ) switch chID { case StateChannel : err = r . handleStateMessage ( envelope , msgI ) case DataChannel : err = r . handleDataMessage ( envelope , msgI ) case VoteChannel : err = r . handleVoteMessage ( envelope , msgI ) case VoteSetBitsChannel : err = r . handleVoteSetBitsMessage ( envelope , msgI ) default : err = fmt . Errorf ( " " , chID , envelope ) } return err }
handleMessage handles an Envelope sent from a peer on a specific p2p Channel.
handleMessage handles an Envelope sent from a peer on a specific p2p Channel .
// We wrap the envelope's message in a Proto wire type so we can convert back // the domain type that individual channel message handlers can work with. We // do this here once to avoid having to do it for each individual message type. // and because a large part of the core business logic depends on these // domain types opposed to simply working with the Proto types.