Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ded3100

Browse files
authoredOct 9, 2021
lint: fix collection of stale errors (#7090)
Few things that had been annoying.
1 parent befd669 commit ded3100

File tree

18 files changed

+33
-36
lines changed

18 files changed

+33
-36
lines changed
 

‎.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: golangci/golangci-lint-action@v2.5.2
2424
with:
2525
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
26-
version: v1.38
26+
version: v1.42.1
2727
args: --timeout 10m
2828
github-token: ${{ secrets.github_token }}
2929
if: env.GIT_DIFF

‎.golangci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ linters:
1313
# - gochecknoinits
1414
# - gocognit
1515
- goconst
16-
- gocritic
16+
# - gocritic
1717
# - gocyclo
1818
# - godox
1919
- gofmt
2020
- goimports
21-
- golint
21+
- revive
2222
- gosec
2323
- gosimple
2424
- govet

‎internal/consensus/msgs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (m *NewRoundStepMessage) ValidateHeight(initialHeight int64) error {
7777
m.LastCommitRound, initialHeight)
7878
}
7979
if m.Height > initialHeight && m.LastCommitRound < 0 {
80-
return fmt.Errorf("LastCommitRound can only be negative for initial height %v", // nolint
80+
return fmt.Errorf("LastCommitRound can only be negative for initial height %v",
8181
initialHeight)
8282
}
8383
return nil

‎internal/libs/protoio/io_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func iotest(writer protoio.WriteCloser, reader protoio.ReadCloser) error {
7171
return err
7272
}
7373
if n != len(bz)+visize {
74-
return fmt.Errorf("WriteMsg() wrote %v bytes, expected %v", n, len(bz)+visize) // nolint
74+
return fmt.Errorf("WriteMsg() wrote %v bytes, expected %v", n, len(bz)+visize)
7575
}
7676
lens[i] = n
7777
}

‎internal/mempool/ids.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ import (
77
"github.com/tendermint/tendermint/types"
88
)
99

10-
// nolint: golint
11-
// TODO: Rename type.
12-
type MempoolIDs struct {
10+
type IDs struct {
1311
mtx tmsync.RWMutex
1412
peerMap map[types.NodeID]uint16
1513
nextID uint16 // assumes that a node will never have over 65536 active peers
1614
activeIDs map[uint16]struct{} // used to check if a given peerID key is used
1715
}
1816

19-
func NewMempoolIDs() *MempoolIDs {
20-
return &MempoolIDs{
17+
func NewMempoolIDs() *IDs {
18+
return &IDs{
2119
peerMap: make(map[types.NodeID]uint16),
2220

2321
// reserve UnknownPeerID for mempoolReactor.BroadcastTx
@@ -28,7 +26,7 @@ func NewMempoolIDs() *MempoolIDs {
2826

2927
// ReserveForPeer searches for the next unused ID and assigns it to the provided
3028
// peer.
31-
func (ids *MempoolIDs) ReserveForPeer(peerID types.NodeID) {
29+
func (ids *IDs) ReserveForPeer(peerID types.NodeID) {
3230
ids.mtx.Lock()
3331
defer ids.mtx.Unlock()
3432

@@ -38,7 +36,7 @@ func (ids *MempoolIDs) ReserveForPeer(peerID types.NodeID) {
3836
}
3937

4038
// Reclaim returns the ID reserved for the peer back to unused pool.
41-
func (ids *MempoolIDs) Reclaim(peerID types.NodeID) {
39+
func (ids *IDs) Reclaim(peerID types.NodeID) {
4240
ids.mtx.Lock()
4341
defer ids.mtx.Unlock()
4442

@@ -50,7 +48,7 @@ func (ids *MempoolIDs) Reclaim(peerID types.NodeID) {
5048
}
5149

5250
// GetForPeer returns an ID reserved for the peer.
53-
func (ids *MempoolIDs) GetForPeer(peerID types.NodeID) uint16 {
51+
func (ids *IDs) GetForPeer(peerID types.NodeID) uint16 {
5452
ids.mtx.RLock()
5553
defer ids.mtx.RUnlock()
5654

@@ -59,7 +57,7 @@ func (ids *MempoolIDs) GetForPeer(peerID types.NodeID) uint16 {
5957

6058
// nextPeerID returns the next unused peer ID to use. We assume that the mutex
6159
// is already held.
62-
func (ids *MempoolIDs) nextPeerID() uint16 {
60+
func (ids *IDs) nextPeerID() uint16 {
6361
if len(ids.activeIDs) == MaxActiveIDs {
6462
panic(fmt.Sprintf("node has maximum %d active IDs and wanted to get one more", MaxActiveIDs))
6563
}

‎internal/mempool/v0/reactor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Reactor struct {
3939

4040
cfg *config.MempoolConfig
4141
mempool *CListMempool
42-
ids *mempool.MempoolIDs
42+
ids *mempool.IDs
4343

4444
// XXX: Currently, this is the only way to get information about a peer. Ideally,
4545
// we rely on message-oriented communication to get necessary peer data.

‎internal/mempool/v1/reactor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Reactor struct {
3939

4040
cfg *config.MempoolConfig
4141
mempool *TxMempool
42-
ids *mempool.MempoolIDs
42+
ids *mempool.IDs
4343

4444
// XXX: Currently, this is the only way to get information about a peer. Ideally,
4545
// we rely on message-oriented communication to get necessary peer data.

‎internal/p2p/peermanager.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (o *PeerManagerOptions) Validate() error {
180180

181181
if o.MaxPeers > 0 {
182182
if o.MaxConnected == 0 || o.MaxConnected+o.MaxConnectedUpgrade > o.MaxPeers {
183-
return fmt.Errorf("MaxConnected %v and MaxConnectedUpgrade %v can't exceed MaxPeers %v", // nolint
183+
return fmt.Errorf("MaxConnected %v and MaxConnectedUpgrade %v can't exceed MaxPeers %v",
184184
o.MaxConnected, o.MaxConnectedUpgrade, o.MaxPeers)
185185
}
186186
}
@@ -190,7 +190,7 @@ func (o *PeerManagerOptions) Validate() error {
190190
return errors.New("can't set MaxRetryTime without MinRetryTime")
191191
}
192192
if o.MinRetryTime > o.MaxRetryTime {
193-
return fmt.Errorf("MinRetryTime %v is greater than MaxRetryTime %v", // nolint
193+
return fmt.Errorf("MinRetryTime %v is greater than MaxRetryTime %v",
194194
o.MinRetryTime, o.MaxRetryTime)
195195
}
196196
}
@@ -200,7 +200,7 @@ func (o *PeerManagerOptions) Validate() error {
200200
return errors.New("can't set MaxRetryTimePersistent without MinRetryTime")
201201
}
202202
if o.MinRetryTime > o.MaxRetryTimePersistent {
203-
return fmt.Errorf("MinRetryTime %v is greater than MaxRetryTimePersistent %v", // nolint
203+
return fmt.Errorf("MinRetryTime %v is greater than MaxRetryTimePersistent %v",
204204
o.MinRetryTime, o.MaxRetryTimePersistent)
205205
}
206206
}

‎internal/state/state.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ func (state *State) ToProto() (*tmstate.State, error) {
195195
return sm, nil
196196
}
197197

198-
// StateFromProto takes a state proto message & returns the local state type
199-
func StateFromProto(pb *tmstate.State) (*State, error) { //nolint:golint
198+
// FromProto takes a state proto message & returns the local state type
199+
func FromProto(pb *tmstate.State) (*State, error) {
200200
if pb == nil {
201201
return nil, errors.New("nil State")
202202
}

‎internal/state/state_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ func TestStateProto(t *testing.T) {
10791079
assert.NoError(t, err, tt.testName)
10801080
}
10811081

1082-
smt, err := sm.StateFromProto(pbs)
1082+
smt, err := sm.FromProto(pbs)
10831083
if tt.expPass2 {
10841084
require.NoError(t, err, tt.testName)
10851085
require.Equal(t, tt.state, smt, tt.testName)

‎internal/state/store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (store dbStore) loadState(key []byte) (state State, err error) {
130130
%v\n`, err))
131131
}
132132

133-
sm, err := StateFromProto(sp)
133+
sm, err := FromProto(sp)
134134
if err != nil {
135135
return state, err
136136
}

‎internal/state/validation_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func TestValidateBlockEvidence(t *testing.T) {
270270
A block with too much evidence fails
271271
*/
272272
evidence := make([]types.Evidence, 0)
273-
var currentBytes int64 = 0
273+
var currentBytes int64
274274
// more bytes than the maximum allowed for evidence
275275
for currentBytes <= maxBytesEvidence {
276276
newEv := types.NewMockDuplicateVoteEvidenceWithValidator(height, time.Now(),
@@ -290,7 +290,7 @@ func TestValidateBlockEvidence(t *testing.T) {
290290
A good block with several pieces of good evidence passes
291291
*/
292292
evidence := make([]types.Evidence, 0)
293-
var currentBytes int64 = 0
293+
var currentBytes int64
294294
// precisely the amount of allowed evidence
295295
for {
296296
newEv := types.NewMockDuplicateVoteEvidenceWithValidator(height, defaultEvidenceTime,

‎internal/statesync/reactor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ func (r *Reactor) handleLightBlockMessage(envelope p2p.Envelope) error {
734734
}
735735

736736
case *ssproto.LightBlockResponse:
737-
var height int64 = 0
737+
var height int64
738738
if msg.LightBlock != nil {
739739
height = msg.LightBlock.SignedHeader.Header.Height
740740
}

‎internal/store/store.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (bs *BlockStore) pruneRange(
345345
var (
346346
err error
347347
pruned uint64
348-
totalPruned uint64 = 0
348+
totalPruned uint64
349349
)
350350

351351
batch := bs.db.NewBatch()
@@ -392,7 +392,7 @@ func (bs *BlockStore) batchDelete(
392392
start, end []byte,
393393
preDeletionHook func(key, value []byte, batch dbm.Batch) error,
394394
) (uint64, []byte, error) {
395-
var pruned uint64 = 0
395+
var pruned uint64
396396
iter, err := bs.db.Iterator(start, end)
397397
if err != nil {
398398
return pruned, start, err

‎libs/json/helpers_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func (c CustomValue) MarshalJSON() ([]byte, error) {
6161
}
6262

6363
func (c CustomValue) UnmarshalJSON(bz []byte) error {
64-
c.Value = "custom"
6564
return nil
6665
}
6766

‎node/node_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func TestCreateProposalBlock(t *testing.T) {
249249

250250
// fill the evidence pool with more evidence
251251
// than can fit in a block
252-
var currentBytes int64 = 0
252+
var currentBytes int64
253253
for currentBytes <= maxEvidenceBytes {
254254
ev := types.NewMockDuplicateVoteEvidenceWithValidator(height, time.Now(), privVals[0], "test-chain")
255255
currentBytes += int64(len(ev.Bytes()))

‎types/validation.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ func verifyCommitBatch(
162162
var (
163163
val *Validator
164164
valIdx int32
165-
seenVals = make(map[int32]int, len(commit.Signatures))
166-
batchSigIdxs = make([]int, 0, len(commit.Signatures))
167-
talliedVotingPower int64 = 0
165+
talliedVotingPower int64
166+
seenVals = make(map[int32]int, len(commit.Signatures))
167+
batchSigIdxs = make([]int, 0, len(commit.Signatures))
168168
)
169169
// attempt to create a batch verifier
170170
bv, ok := batch.CreateBatchVerifier(vals.GetProposer().PubKey)
@@ -275,9 +275,9 @@ func verifyCommitSingle(
275275
var (
276276
val *Validator
277277
valIdx int32
278-
seenVals = make(map[int32]int, len(commit.Signatures))
279-
talliedVotingPower int64 = 0
278+
talliedVotingPower int64
280279
voteSignBytes []byte
280+
seenVals = make(map[int32]int, len(commit.Signatures))
281281
)
282282
for idx, commitSig := range commit.Signatures {
283283
if ignoreSig(commitSig) {

‎types/validator_set_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func TestAveragingInIncrementProposerPriority(t *testing.T) {
508508
{Address: []byte("c"), ProposerPriority: 1}}},
509509
// this should average twice but the average should be 0 after the first iteration
510510
// (voting power is 0 -> no changes)
511-
11, 1 / 3},
511+
11, 0},
512512
2: {ValidatorSet{
513513
Validators: []*Validator{
514514
{Address: []byte("a"), ProposerPriority: 100},

0 commit comments

Comments
 (0)
Please sign in to comment.