linters: enable stylecheck (#4153)

Refs #3262
This commit is contained in:
Anton Kaliaev
2019-11-16 19:35:39 +04:00
committed by GitHub
parent 36ba1a8494
commit 3e1516b624
137 changed files with 590 additions and 589 deletions

View File

@@ -161,7 +161,7 @@ func TestMempoolRmBadTx(t *testing.T) {
checkTxRespCh <- struct{}{}
}, mempl.TxInfo{})
if err != nil {
t.Errorf("Error after CheckTx: %v", err)
t.Errorf("error after CheckTx: %v", err)
return
}
@@ -182,7 +182,7 @@ func TestMempoolRmBadTx(t *testing.T) {
case <-checkTxRespCh:
// success
case <-ticker:
t.Errorf("Timed out waiting for tx to return")
t.Errorf("timed out waiting for tx to return")
return
}
@@ -192,7 +192,7 @@ func TestMempoolRmBadTx(t *testing.T) {
case <-emptyMempoolCh:
// success
case <-ticker:
t.Errorf("Timed out waiting for tx to be removed")
t.Errorf("timed out waiting for tx to be removed")
return
}
}

View File

@@ -898,8 +898,8 @@ func ReactorMetrics(metrics *Metrics) ReactorOption {
//-----------------------------------------------------------------------------
var (
ErrPeerStateHeightRegression = errors.New("Error peer state height regression")
ErrPeerStateInvalidStartTime = errors.New("Error peer state invalid startTime")
ErrPeerStateHeightRegression = errors.New("error peer state height regression")
ErrPeerStateInvalidStartTime = errors.New("error peer state invalid startTime")
)
// PeerState contains the known state of a peer, including its connection and
@@ -1399,7 +1399,7 @@ func RegisterConsensusMessages(cdc *amino.Codec) {
func decodeMsg(bz []byte) (msg ConsensusMessage, err error) {
if len(bz) > maxMsgSize {
return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize)
return msg, fmt.Errorf("msg exceeds max size (%d > %d)", len(bz), maxMsgSize)
}
err = cdc.UnmarshalBinaryBare(bz, &msg)
return
@@ -1420,20 +1420,20 @@ type NewRoundStepMessage struct {
// ValidateBasic performs basic validation.
func (m *NewRoundStepMessage) ValidateBasic() error {
if m.Height < 0 {
return errors.New("Negative Height")
return errors.New("negative Height")
}
if m.Round < 0 {
return errors.New("Negative Round")
return errors.New("negative Round")
}
if !m.Step.IsValid() {
return errors.New("Invalid Step")
return errors.New("invalid Step")
}
// NOTE: SecondsSinceStartTime may be negative
if (m.Height == 1 && m.LastCommitRound != -1) ||
(m.Height > 1 && m.LastCommitRound < -1) { // TODO: #2737 LastCommitRound should always be >= 0 for heights > 1
return errors.New("Invalid LastCommitRound (for 1st block: -1, for others: >= 0)")
return errors.New("invalid LastCommitRound (for 1st block: -1, for others: >= 0)")
}
return nil
}
@@ -1460,19 +1460,19 @@ type NewValidBlockMessage struct {
// ValidateBasic performs basic validation.
func (m *NewValidBlockMessage) ValidateBasic() error {
if m.Height < 0 {
return errors.New("Negative Height")
return errors.New("negative Height")
}
if m.Round < 0 {
return errors.New("Negative Round")
return errors.New("negative Round")
}
if err := m.BlockPartsHeader.ValidateBasic(); err != nil {
return fmt.Errorf("Wrong BlockPartsHeader: %v", err)
return fmt.Errorf("wrong BlockPartsHeader: %v", err)
}
if m.BlockParts.Size() == 0 {
return errors.New("Empty BlockParts")
}
if m.BlockParts.Size() != m.BlockPartsHeader.Total {
return fmt.Errorf("BlockParts bit array size %d not equal to BlockPartsHeader.Total %d",
return fmt.Errorf("blockParts bit array size %d not equal to BlockPartsHeader.Total %d",
m.BlockParts.Size(),
m.BlockPartsHeader.Total)
}
@@ -1517,13 +1517,13 @@ type ProposalPOLMessage struct {
// ValidateBasic performs basic validation.
func (m *ProposalPOLMessage) ValidateBasic() error {
if m.Height < 0 {
return errors.New("Negative Height")
return errors.New("negative Height")
}
if m.ProposalPOLRound < 0 {
return errors.New("Negative ProposalPOLRound")
return errors.New("negative ProposalPOLRound")
}
if m.ProposalPOL.Size() == 0 {
return errors.New("Empty ProposalPOL bit array")
return errors.New("empty ProposalPOL bit array")
}
if m.ProposalPOL.Size() > types.MaxVotesCount {
return errors.Errorf("ProposalPOL bit array is too big: %d, max: %d", m.ProposalPOL.Size(), types.MaxVotesCount)
@@ -1548,13 +1548,13 @@ type BlockPartMessage struct {
// ValidateBasic performs basic validation.
func (m *BlockPartMessage) ValidateBasic() error {
if m.Height < 0 {
return errors.New("Negative Height")
return errors.New("negative Height")
}
if m.Round < 0 {
return errors.New("Negative Round")
return errors.New("negative Round")
}
if err := m.Part.ValidateBasic(); err != nil {
return fmt.Errorf("Wrong Part: %v", err)
return fmt.Errorf("wrong Part: %v", err)
}
return nil
}
@@ -1594,16 +1594,16 @@ type HasVoteMessage struct {
// ValidateBasic performs basic validation.
func (m *HasVoteMessage) ValidateBasic() error {
if m.Height < 0 {
return errors.New("Negative Height")
return errors.New("negative Height")
}
if m.Round < 0 {
return errors.New("Negative Round")
return errors.New("negative Round")
}
if !types.IsVoteTypeValid(m.Type) {
return errors.New("Invalid Type")
return errors.New("invalid Type")
}
if m.Index < 0 {
return errors.New("Negative Index")
return errors.New("negative Index")
}
return nil
}
@@ -1626,16 +1626,16 @@ type VoteSetMaj23Message struct {
// ValidateBasic performs basic validation.
func (m *VoteSetMaj23Message) ValidateBasic() error {
if m.Height < 0 {
return errors.New("Negative Height")
return errors.New("negative Height")
}
if m.Round < 0 {
return errors.New("Negative Round")
return errors.New("negative Round")
}
if !types.IsVoteTypeValid(m.Type) {
return errors.New("Invalid Type")
return errors.New("invalid Type")
}
if err := m.BlockID.ValidateBasic(); err != nil {
return fmt.Errorf("Wrong BlockID: %v", err)
return fmt.Errorf("wrong BlockID: %v", err)
}
return nil
}
@@ -1659,20 +1659,20 @@ type VoteSetBitsMessage struct {
// ValidateBasic performs basic validation.
func (m *VoteSetBitsMessage) ValidateBasic() error {
if m.Height < 0 {
return errors.New("Negative Height")
return errors.New("negative Height")
}
if m.Round < 0 {
return errors.New("Negative Round")
return errors.New("negative Round")
}
if !types.IsVoteTypeValid(m.Type) {
return errors.New("Invalid Type")
return errors.New("invalid Type")
}
if err := m.BlockID.ValidateBasic(); err != nil {
return fmt.Errorf("Wrong BlockID: %v", err)
return fmt.Errorf("wrong BlockID: %v", err)
}
// NOTE: Votes.Size() can be zero if the node does not have any
if m.Votes.Size() > types.MaxVotesCount {
return fmt.Errorf("Votes bit array is too big: %d, max: %d", m.Votes.Size(), types.MaxVotesCount)
return fmt.Errorf("votes bit array is too big: %d, max: %d", m.Votes.Size(), types.MaxVotesCount)
}
return nil
}

View File

@@ -608,14 +608,14 @@ func waitForBlockWithUpdatedValsAndValidateIt(
func validateBlock(block *types.Block, activeVals map[string]struct{}) error {
if block.LastCommit.Size() != len(activeVals) {
return fmt.Errorf(
"Commit size doesn't match number of active validators. Got %d, expected %d",
"commit size doesn't match number of active validators. Got %d, expected %d",
block.LastCommit.Size(),
len(activeVals))
}
for _, vote := range block.LastCommit.Precommits {
if _, ok := activeVals[string(vote.ValidatorAddress)]; !ok {
return fmt.Errorf("Found vote for unactive validator %X", vote.ValidatorAddress)
return fmt.Errorf("found vote for unactive validator %X", vote.ValidatorAddress)
}
}
return nil
@@ -704,11 +704,11 @@ func TestNewValidBlockMessageValidateBasic(t *testing.T) {
expErr string
}{
{func(msg *NewValidBlockMessage) {}, ""},
{func(msg *NewValidBlockMessage) { msg.Height = -1 }, "Negative Height"},
{func(msg *NewValidBlockMessage) { msg.Round = -1 }, "Negative Round"},
{func(msg *NewValidBlockMessage) { msg.Height = -1 }, "negative Height"},
{func(msg *NewValidBlockMessage) { msg.Round = -1 }, "negative Round"},
{
func(msg *NewValidBlockMessage) { msg.BlockPartsHeader.Total = 2 },
"BlockParts bit array size 1 not equal to BlockPartsHeader.Total 2",
"blockParts bit array size 1 not equal to BlockPartsHeader.Total 2",
},
{
func(msg *NewValidBlockMessage) { msg.BlockPartsHeader.Total = 0; msg.BlockParts = cmn.NewBitArray(0) },
@@ -716,7 +716,7 @@ func TestNewValidBlockMessageValidateBasic(t *testing.T) {
},
{
func(msg *NewValidBlockMessage) { msg.BlockParts = cmn.NewBitArray(types.MaxBlockPartsCount + 1) },
"BlockParts bit array size 1602 not equal to BlockPartsHeader.Total 1",
"blockParts bit array size 1602 not equal to BlockPartsHeader.Total 1",
},
}
@@ -747,9 +747,9 @@ func TestProposalPOLMessageValidateBasic(t *testing.T) {
expErr string
}{
{func(msg *ProposalPOLMessage) {}, ""},
{func(msg *ProposalPOLMessage) { msg.Height = -1 }, "Negative Height"},
{func(msg *ProposalPOLMessage) { msg.ProposalPOLRound = -1 }, "Negative ProposalPOLRound"},
{func(msg *ProposalPOLMessage) { msg.ProposalPOL = cmn.NewBitArray(0) }, "Empty ProposalPOL bit array"},
{func(msg *ProposalPOLMessage) { msg.Height = -1 }, "negative Height"},
{func(msg *ProposalPOLMessage) { msg.ProposalPOLRound = -1 }, "negative ProposalPOLRound"},
{func(msg *ProposalPOLMessage) { msg.ProposalPOL = cmn.NewBitArray(0) }, "empty ProposalPOL bit array"},
{func(msg *ProposalPOLMessage) { msg.ProposalPOL = cmn.NewBitArray(types.MaxVotesCount + 1) },
"ProposalPOL bit array is too big: 10001, max: 10000"},
}
@@ -893,9 +893,9 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) {
expErr string
}{
{func(msg *VoteSetBitsMessage) {}, ""},
{func(msg *VoteSetBitsMessage) { msg.Height = -1 }, "Negative Height"},
{func(msg *VoteSetBitsMessage) { msg.Round = -1 }, "Negative Round"},
{func(msg *VoteSetBitsMessage) { msg.Type = 0x03 }, "Invalid Type"},
{func(msg *VoteSetBitsMessage) { msg.Height = -1 }, "negative Height"},
{func(msg *VoteSetBitsMessage) { msg.Round = -1 }, "negative Round"},
{func(msg *VoteSetBitsMessage) { msg.Type = 0x03 }, "invalid Type"},
{func(msg *VoteSetBitsMessage) {
msg.BlockID = types.BlockID{
Hash: cmn.HexBytes{},
@@ -904,9 +904,9 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) {
Hash: cmn.HexBytes{},
},
}
}, "Wrong BlockID: Wrong PartsHeader: Negative Total"},
}, "wrong BlockID: wrong PartsHeader: negative Total"},
{func(msg *VoteSetBitsMessage) { msg.Votes = cmn.NewBitArray(types.MaxVotesCount + 1) },
"Votes bit array is too big: 10001, max: 10000"},
"votes bit array is too big: 10001, max: 10000"},
}
for i, tc := range testCases {

View File

@@ -59,12 +59,12 @@ func (cs *ConsensusState) readReplayMessage(msg *TimedWALMessage, newStepSub typ
case stepMsg := <-newStepSub.Out():
m2 := stepMsg.Data().(types.EventDataRoundState)
if m.Height != m2.Height || m.Round != m2.Round || m.Step != m2.Step {
return fmt.Errorf("RoundState mismatch. Got %v; Expected %v", m2, m)
return fmt.Errorf("roundState mismatch. Got %v; Expected %v", m2, m)
}
case <-newStepSub.Cancelled():
return fmt.Errorf("Failed to read off newStepSub.Out(). newStepSub was cancelled")
return fmt.Errorf("failed to read off newStepSub.Out(). newStepSub was cancelled")
case <-ticker:
return fmt.Errorf("Failed to read off newStepSub.Out()")
return fmt.Errorf("failed to read off newStepSub.Out()")
}
}
case msgInfo:
@@ -90,7 +90,7 @@ func (cs *ConsensusState) readReplayMessage(msg *TimedWALMessage, newStepSub typ
cs.Logger.Info("Replay: Timeout", "height", m.Height, "round", m.Round, "step", m.Step, "dur", m.Duration)
cs.handleTimeout(m, cs.RoundState)
default:
return fmt.Errorf("Replay: Unknown TimedWALMessage type: %v", reflect.TypeOf(msg.Msg))
return fmt.Errorf("replay: Unknown TimedWALMessage type: %v", reflect.TypeOf(msg.Msg))
}
return nil
}
@@ -119,7 +119,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int64) error {
}
}
if found {
return fmt.Errorf("WAL should not contain #ENDHEIGHT %d", csHeight)
return fmt.Errorf("wal should not contain #ENDHEIGHT %d", csHeight)
}
// Search for last height marker.
@@ -132,7 +132,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int64) error {
return err
}
if !found {
return fmt.Errorf("Cannot replay height %d. WAL does not contain #ENDHEIGHT for %d", csHeight, csHeight-1)
return fmt.Errorf("cannot replay height %d. WAL does not contain #ENDHEIGHT for %d", csHeight, csHeight-1)
}
defer gr.Close() // nolint: errcheck
@@ -175,11 +175,11 @@ func makeHeightSearchFunc(height int64) auto.SearchFunc {
line = strings.TrimRight(line, "\n")
parts := strings.Split(line, " ")
if len(parts) != 2 {
return -1, errors.New("Line did not have 2 parts")
return -1, errors.New("line did not have 2 parts")
}
i, err := strconv.Atoi(parts[1])
if err != nil {
return -1, errors.New("Failed to parse INFO: " + err.Error())
return -1, errors.New("failed to parse INFO: " + err.Error())
}
if height < i {
return 1, nil
@@ -243,12 +243,12 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
// Handshake is done via ABCI Info on the query conn.
res, err := proxyApp.Query().InfoSync(proxy.RequestInfo)
if err != nil {
return fmt.Errorf("Error calling Info: %v", err)
return fmt.Errorf("error calling Info: %v", err)
}
blockHeight := res.LastBlockHeight
if blockHeight < 0 {
return fmt.Errorf("Got a negative last block height (%d) from the app", blockHeight)
return fmt.Errorf("got a negative last block height (%d) from the app", blockHeight)
}
appHash := res.LastBlockAppHash

View File

@@ -932,7 +932,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) {
return nil, nil, err
}
if !found {
return nil, nil, fmt.Errorf("WAL does not contain height %d", height)
return nil, nil, fmt.Errorf("wal does not contain height %d", height)
}
defer gr.Close() // nolint: errcheck

View File

@@ -27,10 +27,10 @@ import (
// Errors
var (
ErrInvalidProposalSignature = errors.New("Error invalid proposal signature")
ErrInvalidProposalPOLRound = errors.New("Error invalid proposal POL round")
ErrAddingVote = errors.New("Error adding vote")
ErrVoteHeightMismatch = errors.New("Error vote height mismatch")
ErrInvalidProposalSignature = errors.New("error invalid proposal signature")
ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round")
ErrAddingVote = errors.New("error adding vote")
ErrVoteHeightMismatch = errors.New("error vote height mismatch")
)
//-----------------------------------------------------------------------------
@@ -969,8 +969,8 @@ func (cs *ConsensusState) defaultDecideProposal(height int64, round int) {
cs.wal.FlushAndSync()
// Make proposal
propBlockId := types.BlockID{Hash: block.Hash(), PartsHeader: blockParts.Header()}
proposal := types.NewProposal(height, round, cs.ValidRound, propBlockId)
propBlockID := types.BlockID{Hash: block.Hash(), PartsHeader: blockParts.Header()}
proposal := types.NewProposal(height, round, cs.ValidRound, propBlockID)
if err := cs.privValidator.SignProposal(cs.state.ChainID, proposal); err == nil {
// send proposal and block parts on internal msg queue

View File

@@ -1594,7 +1594,7 @@ func TestStateOutputsBlockPartsStats(t *testing.T) {
select {
case <-cs.statsMsgQueue:
t.Errorf("Should not output stats message after receiving the known block part!")
t.Errorf("should not output stats message after receiving the known block part!")
case <-time.After(50 * time.Millisecond):
}
@@ -1625,7 +1625,7 @@ func TestStateOutputVoteStats(t *testing.T) {
select {
case <-cs.statsMsgQueue:
t.Errorf("Should not output stats message after receiving the known vote or vote from bigger height")
t.Errorf("should not output stats message after receiving the known vote or vote from bigger height")
case <-time.After(50 * time.Millisecond):
}

View File

@@ -16,8 +16,9 @@ type RoundVoteSet struct {
}
var (
GotVoteFromUnwantedRoundError = errors.New(
"Peer has sent a vote that does not match our round for more than one round")
ErrGotVoteFromUnwantedRound = errors.New(
"peer has sent a vote that does not match our round for more than one round",
)
)
/*
@@ -123,7 +124,7 @@ func (hvs *HeightVoteSet) AddVote(vote *types.Vote, peerID p2p.ID) (added bool,
hvs.peerCatchupRounds[peerID] = append(rndz, vote.Round)
} else {
// punish peer
err = GotVoteFromUnwantedRoundError
err = ErrGotVoteFromUnwantedRound
return
}
}
@@ -158,18 +159,18 @@ func (hvs *HeightVoteSet) POLInfo() (polRound int, polBlockID types.BlockID) {
return -1, types.BlockID{}
}
func (hvs *HeightVoteSet) getVoteSet(round int, type_ types.SignedMsgType) *types.VoteSet {
func (hvs *HeightVoteSet) getVoteSet(round int, voteType types.SignedMsgType) *types.VoteSet {
rvs, ok := hvs.roundVoteSets[round]
if !ok {
return nil
}
switch type_ {
switch voteType {
case types.PrevoteType:
return rvs.Prevotes
case types.PrecommitType:
return rvs.Precommits
default:
panic(fmt.Sprintf("Unexpected vote type %X", type_))
panic(fmt.Sprintf("Unexpected vote type %X", voteType))
}
}
@@ -179,15 +180,15 @@ func (hvs *HeightVoteSet) getVoteSet(round int, type_ types.SignedMsgType) *type
// TODO: implement ability to remove peers too
func (hvs *HeightVoteSet) SetPeerMaj23(
round int,
type_ types.SignedMsgType,
voteType types.SignedMsgType,
peerID p2p.ID,
blockID types.BlockID) error {
hvs.mtx.Lock()
defer hvs.mtx.Unlock()
if !types.IsVoteTypeValid(type_) {
return fmt.Errorf("SetPeerMaj23: Invalid vote type %v", type_)
if !types.IsVoteTypeValid(voteType) {
return fmt.Errorf("setPeerMaj23: Invalid vote type %X", voteType)
}
voteSet := hvs.getVoteSet(round, type_)
voteSet := hvs.getVoteSet(round, voteType)
if voteSet == nil {
return nil // something we don't know about yet
}

View File

@@ -38,8 +38,8 @@ func TestPeerCatchupRounds(t *testing.T) {
vote1001_0 := makeVoteHR(t, 1, 1001, privVals, 0)
added, err = hvs.AddVote(vote1001_0, "peer1")
if err != GotVoteFromUnwantedRoundError {
t.Errorf("Expected GotVoteFromUnwantedRoundError, but got %v", err)
if err != ErrGotVoteFromUnwantedRound {
t.Errorf("expected GotVoteFromUnwantedRoundError, but got %v", err)
}
if added {
t.Error("Expected to *not* add vote from peer, too many catchup rounds.")

View File

@@ -70,19 +70,19 @@ func (prs PeerRoundState) StringIndented(indent string) string {
// These methods are for Protobuf Compatibility
// Size returns the size of the amino encoding, in bytes.
func (ps *PeerRoundState) Size() int {
bs, _ := ps.Marshal()
func (prs *PeerRoundState) Size() int {
bs, _ := prs.Marshal()
return len(bs)
}
// Marshal returns the amino encoding.
func (ps *PeerRoundState) Marshal() ([]byte, error) {
return cdc.MarshalBinaryBare(ps)
func (prs *PeerRoundState) Marshal() ([]byte, error) {
return cdc.MarshalBinaryBare(prs)
}
// MarshalTo calls Marshal and copies to the given buffer.
func (ps *PeerRoundState) MarshalTo(data []byte) (int, error) {
bs, err := ps.Marshal()
func (prs *PeerRoundState) MarshalTo(data []byte) (int, error) {
bs, err := prs.Marshal()
if err != nil {
return -1, err
}
@@ -90,6 +90,6 @@ func (ps *PeerRoundState) MarshalTo(data []byte) (int, error) {
}
// Unmarshal deserializes from amino encoded form.
func (ps *PeerRoundState) Unmarshal(bs []byte) error {
return cdc.UnmarshalBinaryBare(bs, ps)
func (prs *PeerRoundState) Unmarshal(bs []byte) error {
return cdc.UnmarshalBinaryBare(bs, prs)
}

View File

@@ -139,7 +139,7 @@ func (rs *RoundState) NewRoundEvent() types.EventDataNewRound {
func (rs *RoundState) CompleteProposalEvent() types.EventDataCompleteProposal {
// We must construct BlockID from ProposalBlock and ProposalBlockParts
// cs.Proposal is not guaranteed to be set when this function is called
blockId := types.BlockID{
blockID := types.BlockID{
Hash: rs.ProposalBlock.Hash(),
PartsHeader: rs.ProposalBlockParts.Header(),
}
@@ -148,7 +148,7 @@ func (rs *RoundState) CompleteProposalEvent() types.EventDataCompleteProposal {
Height: rs.Height,
Round: rs.Round,
Step: rs.Step.String(),
BlockID: blockId,
BlockID: blockID,
}
}