// handleVoteSetBitsMessage handles envelopes sent from peers on the
// VoteSetBitsChannel. If we fail to find the peer state for the envelope sender,
// we perform a no-op and return. This can happen when we process the envelope
// after the peer is removed.
handleVoteSetBitsMessage handles envelopes sent from peers on the
VoteSetBitsChannel. If we fail to find the peer state for the envelope sender,
we perform a no-op and return. This can happen when we process the envelope
after the peer is removed.
// handleVoteSetBitsMessage handles envelopes sent from peers on the // VoteSetBitsChannel . If we fail to find the peer state for the envelope sender // we perform a no - op and return . This can happen when we process the envelope // after the peer is removed .
func (r *Reactor) handleVoteSetBitsMessage(envelope p2p.Envelope, msgI Message) error {
	logger := r.Logger.With("peer", envelope.From, "ch_id", "VoteSetBitsChannel")
	ps, ok := r.GetPeerState(envelope.From)
	if !ok || ps == nil {
		r.Logger.Debug("failed to find peer state")
		return nil
	}
	if r.WaitSync() {
		logger.Info("ignoring message received during sync", "msg", msgI)
		return nil
	}
	switch msg := envelope.Message.(type) {
	case *tmcons.VoteSetBits:
		r.state.mtx.RLock()
		height, votes := r.state.Height, r.state.Votes
		r.state.mtx.RUnlock()
		vsbMsg := msgI.(*VoteSetBitsMessage)
		if height == msg.Height {
			var ourVotes *bits.BitArray
			switch msg.Type {
			case tmproto.PrevoteType:
				ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(vsbMsg.BlockID)
			case tmproto.PrecommitType:
				ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(vsbMsg.BlockID)
			default:
				panic("bad VoteSetBitsMessage field type; forgot to add a check in ValidateBasic?")
			}
			ps.ApplyVoteSetBitsMessage(vsbMsg, ourVotes)
		} else {
			ps.ApplyVoteSetBitsMessage(vsbMsg, nil)
		}
	default:
		return fmt.Errorf("received unknown message on VoteSetBitsChannel: %T", msg)
	}
	return nil
}
func ( r * Reactor ) handleVoteSetBitsMessage ( envelope p2p . Envelope , msgI Message ) error { logger := r . Logger . With ( " " , envelope . From , " " , " " ) ps , ok := r . GetPeerState ( envelope . From ) if ! ok || ps == nil { r . Logger . Debug ( " " ) return nil } if r . WaitSync ( ) { logger . Info ( " " , " " , msgI ) return nil } switch msg := envelope . Message . ( type ) { case * tmcons . VoteSetBits : r . state . mtx . RLock ( ) height , votes := r . state . Height , r . state . Votes r . state . mtx . RUnlock ( ) vsbMsg := msgI . ( * VoteSetBitsMessage ) if height == msg . Height { var ourVotes * bits . BitArray switch msg . Type { case tmproto . PrevoteType : ourVotes = votes . Prevotes ( msg . Round ) . BitArrayByBlockID ( vsbMsg . BlockID ) case tmproto . PrecommitType : ourVotes = votes . Precommits ( msg . Round ) . BitArrayByBlockID ( vsbMsg . BlockID ) default : panic ( " " ) } ps . ApplyVoteSetBitsMessage ( vsbMsg , ourVotes ) } else { ps . ApplyVoteSetBitsMessage ( vsbMsg , nil ) } default : return fmt . Errorf ( " " , msg ) } return nil }
handleVoteSetBitsMessage handles envelopes sent from peers on the
VoteSetBitsChannel.
handleVoteSetBitsMessage handles envelopes sent from peers on the VoteSetBitsChannel .