From 8f48c49543428ef628097654c2da7b53fd94d64d Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Thu, 20 Feb 2020 13:43:40 +0100 Subject: [PATCH] Fix some golangci-lint warnings (#4448) --- .golangci.yml | 2 +- abci/tests/test_app/main.go | 3 ++- consensus/state.go | 1 + crypto/secp256k1/secp256k1.go | 4 +--- libs/autofile/group.go | 6 +++--- lite/helpers.go | 4 ++-- node/node.go | 2 +- p2p/switch.go | 4 ---- p2p/test_util.go | 2 +- rpc/core/routes.go | 1 + types/priv_validator.go | 10 +++++----- types/protobuf.go | 1 + 12 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ce0925357..dc934f43d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,7 +23,7 @@ linters: - interfacer - lll - misspell - - maligned + # - maligned - nakedret - prealloc - scopelint diff --git a/abci/tests/test_app/main.go b/abci/tests/test_app/main.go index ae47ac6f9..ca298d7e2 100644 --- a/abci/tests/test_app/main.go +++ b/abci/tests/test_app/main.go @@ -53,7 +53,8 @@ func testCounter() { } fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType) - cmd := exec.Command("bash", "-c", fmt.Sprintf("abci-cli %s", abciApp)) + subCommand := fmt.Sprintf("abci-cli %s", abciApp) + cmd := exec.Command("bash", "-c", subCommand) cmd.Stdout = os.Stdout if err := cmd.Start(); err != nil { log.Fatalf("starting %q err: %v", abciApp, err) diff --git a/consensus/state.go b/consensus/state.go index d543c9c84..cd25aa32f 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1644,6 +1644,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { // If the vote height is off, we'll just ignore it, // But if it's a conflicting sig, add it to the cs.evpool. // If it's otherwise invalid, punish peer. + // nolint: gocritic if err == ErrVoteHeightMismatch { return added, err } else if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { diff --git a/crypto/secp256k1/secp256k1.go b/crypto/secp256k1/secp256k1.go index fc64a0b0f..26dcead59 100644 --- a/crypto/secp256k1/secp256k1.go +++ b/crypto/secp256k1/secp256k1.go @@ -8,12 +8,10 @@ import ( "io" "math/big" - "golang.org/x/crypto/ripemd160" - secp256k1 "github.com/btcsuite/btcd/btcec" + "golang.org/x/crypto/ripemd160" // nolint: staticcheck // necessary for Bitcoin address format amino "github.com/tendermint/go-amino" - "github.com/tendermint/tendermint/crypto" ) diff --git a/libs/autofile/group.go b/libs/autofile/group.go index ca9f57003..5d5822ebc 100644 --- a/libs/autofile/group.go +++ b/libs/autofile/group.go @@ -77,7 +77,7 @@ type Group struct { // OpenGroup creates a new Group with head at headPath. It returns an error if // it fails to open head file. -func OpenGroup(headPath string, groupOptions ...func(*Group)) (g *Group, err error) { +func OpenGroup(headPath string, groupOptions ...func(*Group)) (*Group, error) { dir, err := filepath.Abs(filepath.Dir(headPath)) if err != nil { return nil, err @@ -87,7 +87,7 @@ func OpenGroup(headPath string, groupOptions ...func(*Group)) (g *Group, err err return nil, err } - g = &Group{ + g := &Group{ ID: "group:" + head.ID, Head: head, headBuf: bufio.NewWriterSize(head, 4096*10), @@ -109,7 +109,7 @@ func OpenGroup(headPath string, groupOptions ...func(*Group)) (g *Group, err err gInfo := g.readGroupInfo() g.minIndex = gInfo.MinIndex g.maxIndex = gInfo.MaxIndex - return + return g, nil } // GroupCheckDuration allows you to overwrite default groupCheckDuration. diff --git a/lite/helpers.go b/lite/helpers.go index 18a64aa25..29dd50b5b 100644 --- a/lite/helpers.go +++ b/lite/helpers.go @@ -42,7 +42,7 @@ func (pkz privKeys) Extend(n int) privKeys { } // GenSecpPrivKeys produces an array of secp256k1 private keys to generate commits. -func GenSecpPrivKeys(n int) privKeys { +func genSecpPrivKeys(n int) privKeys { res := make(privKeys, n) for i := range res { res[i] = secp256k1.GenPrivKey() @@ -52,7 +52,7 @@ func GenSecpPrivKeys(n int) privKeys { // ExtendSecp adds n more secp256k1 keys (to remove, just take a slice). func (pkz privKeys) ExtendSecp(n int) privKeys { - extra := GenSecpPrivKeys(n) + extra := genSecpPrivKeys(n) return append(pkz, extra...) } diff --git a/node/node.go b/node/node.go index 104e572fb..485709120 100644 --- a/node/node.go +++ b/node/node.go @@ -6,7 +6,7 @@ import ( "fmt" "net" "net/http" - _ "net/http/pprof" + _ "net/http/pprof" // nolint: gosec // securely exposed on separate, optional port "os" "strings" "time" diff --git a/p2p/switch.go b/p2p/switch.go index bc675cdb8..3f9325808 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -584,10 +584,6 @@ func (sw *Switch) AddUnconditionalPeerIDs(ids []string) error { return nil } -func (sw *Switch) isPeerPersistentFn() func(*NetAddress) bool { - return sw.IsPeerPersistent -} - func (sw *Switch) IsPeerPersistent(na *NetAddress) bool { for _, pa := range sw.persistentPeersAddrs { if pa.Equals(na) { diff --git a/p2p/test_util.go b/p2p/test_util.go index f592f5f2f..045dc4c7e 100644 --- a/p2p/test_util.go +++ b/p2p/test_util.go @@ -34,7 +34,7 @@ func AddPeerToSwitchPeerSet(sw *Switch, peer Peer) { sw.peers.Add(peer) } -func CreateRandomPeer(outbound bool) *peer { +func CreateRandomPeer(outbound bool) Peer { addr, netAddr := CreateRoutableAddr() p := &peer{ peerConn: peerConn{ diff --git a/rpc/core/routes.go b/rpc/core/routes.go index 42a57456a..aa0403f87 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -6,6 +6,7 @@ import ( // TODO: better system than "unsafe" prefix // NOTE: Amino is registered in rpc/core/types/codec.go. + var Routes = map[string]*rpc.RPCFunc{ // subscribe/unsubscribe are reserved for websocket events. "subscribe": rpc.NewWSRPCFunc(Subscribe, "query"), diff --git a/types/priv_validator.go b/types/priv_validator.go index 45d0a67b5..bd35973ca 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -107,23 +107,23 @@ func (pv *MockPV) DisableChecks() { // as MockPV has no safety checks at all. } -type erroringMockPV struct { +type ErroringMockPV struct { *MockPV } var ErroringMockPVErr = errors.New("erroringMockPV always returns an error") // Implements PrivValidator. -func (pv *erroringMockPV) SignVote(chainID string, vote *Vote) error { +func (pv *ErroringMockPV) SignVote(chainID string, vote *Vote) error { return ErroringMockPVErr } // Implements PrivValidator. -func (pv *erroringMockPV) SignProposal(chainID string, proposal *Proposal) error { +func (pv *ErroringMockPV) SignProposal(chainID string, proposal *Proposal) error { return ErroringMockPVErr } // NewErroringMockPV returns a MockPV that fails on each signing request. Again, for testing only. -func NewErroringMockPV() *erroringMockPV { - return &erroringMockPV{&MockPV{ed25519.GenPrivKey(), false, false}} +func NewErroringMockPV() *ErroringMockPV { + return &ErroringMockPV{&MockPV{ed25519.GenPrivKey(), false, false}} } diff --git a/types/protobuf.go b/types/protobuf.go index c1063ac94..52815593f 100644 --- a/types/protobuf.go +++ b/types/protobuf.go @@ -27,6 +27,7 @@ const ( ) // TODO: Make non-global by allowing for registration of more pubkey types + var ABCIPubKeyTypesToAminoNames = map[string]string{ ABCIPubKeyTypeEd25519: ed25519.PubKeyAminoName, ABCIPubKeyTypeSr25519: sr25519.PubKeyAminoName,