From 02c22427916ff8243c609a0b0b5bbe934c3dbf35 Mon Sep 17 00:00:00 2001 From: ferhat elmas Date: Fri, 17 Nov 2017 03:16:29 +0100 Subject: [PATCH] build: enable deadcode linter * also fixes warnings generated by linter * fixes #15473 --- accounts/abi/numbers.go | 1 + accounts/usbwallet/ledger.go | 1 + build/ci.go | 9 ++++++++- consensus/clique/clique.go | 1 + consensus/ethash/algorithm.go | 1 + core/asm/compiler.go | 1 + core/chain_makers.go | 2 ++ core/genesis.go | 1 + core/tx_pool.go | 1 + core/types/block.go | 1 + core/types/log.go | 1 + core/types/receipt.go | 1 + core/types/transaction.go | 2 ++ core/vm/logger.go | 1 + core/vm/memory_table.go | 6 ------ crypto/sha3/xor.go | 1 + crypto/sha3/xor_unaligned.go | 1 + eth/config.go | 1 + eth/downloader/downloader.go | 1 + les/bloombits.go | 1 + les/serverpool.go | 1 + les/sync.go | 1 + p2p/discover/node.go | 1 + p2p/discover/udp.go | 1 + p2p/discv5/net.go | 7 ++++--- p2p/discv5/node.go | 1 + p2p/discv5/nodeevent_string.go | 13 +++++++------ p2p/discv5/ntp.go | 1 + p2p/discv5/table.go | 1 + p2p/discv5/udp.go | 2 ++ p2p/message.go | 1 + p2p/peer.go | 1 + p2p/server.go | 1 + swarm/network/kademlia/kademlia.go | 1 + swarm/storage/dbstore.go | 1 + swarm/storage/netstore.go | 1 + whisper/whisperv2/topic.go | 2 ++ 37 files changed, 56 insertions(+), 16 deletions(-) diff --git a/accounts/abi/numbers.go b/accounts/abi/numbers.go index 9ad99f90d2..c8f4872dc0 100644 --- a/accounts/abi/numbers.go +++ b/accounts/abi/numbers.go @@ -50,6 +50,7 @@ func U256(n *big.Int) []byte { } // checks whether the given reflect value is signed. This also works for slices with a number type +// nolint: deadcode func isSigned(v reflect.Value) bool { switch v.Type() { case int_ts, int8_ts, int16_ts, int32_ts, int64_ts, int_t, int8_t, int16_t, int32_t, int64_t: diff --git a/accounts/usbwallet/ledger.go b/accounts/usbwallet/ledger.go index f5def61d23..4bb341e504 100644 --- a/accounts/usbwallet/ledger.go +++ b/accounts/usbwallet/ledger.go @@ -47,6 +47,7 @@ type ledgerParam1 byte // specific opcodes. The same parameter values may be reused between opcodes. type ledgerParam2 byte +// nolint: deadcode const ( ledgerOpRetrieveAddress ledgerOpcode = 0x02 // Returns the public key and Ethereum address for a given BIP 32 path ledgerOpSignTransaction ledgerOpcode = 0x04 // Signs an Ethereum transaction after having the user validate the parameters diff --git a/build/ci.go b/build/ci.go index 0c825ef31e..78dddb95a5 100644 --- a/build/ci.go +++ b/build/ci.go @@ -323,7 +323,14 @@ func doLint(cmdline []string) { build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), "--install") // Run fast linters batched together - configs := []string{"--vendor", "--disable-all", "--enable=vet", "--enable=gofmt", "--enable=misspell"} + configs := []string{"--vendor", "-t", + "--disable-all", + "--exclude=cmd/faucet/website.go", + "--enable=vet", + "--enable=gofmt", + "--enable=misspell", + "--enable=deadcode", + } build.MustRunCommand(filepath.Join(GOBIN, "gometalinter.v1"), append(configs, packages...)...) // Run slow linters one by one diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 6892d83906..c98b11c7a7 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -51,6 +51,7 @@ const ( ) // Clique proof-of-authority protocol constants. +// nolint: deadcode var ( epochLength = uint64(30000) // Default number of blocks after which to checkpoint and reset the pending votes blockPeriod = uint64(15) // Default minimum difference between two consecutive block's timestamps diff --git a/consensus/ethash/algorithm.go b/consensus/ethash/algorithm.go index 76f19252fa..4d3880966e 100644 --- a/consensus/ethash/algorithm.go +++ b/consensus/ethash/algorithm.go @@ -163,6 +163,7 @@ func swap(buffer []byte) { // prepare converts an ethash cache or dataset from a byte stream into the internal // int representation. All ethash methods work with ints to avoid constant byte to // int conversions as well as to handle both little and big endian systems. +// nolint: deadcode func prepare(dest []uint32, src []byte) { for i := 0; i < len(dest); i++ { dest[i] = binary.LittleEndian.Uint32(src[i*4:]) diff --git a/core/asm/compiler.go b/core/asm/compiler.go index b2c85375cc..41b4311331 100644 --- a/core/asm/compiler.go +++ b/core/asm/compiler.go @@ -267,6 +267,7 @@ func (err compileError) Error() string { return fmt.Sprintf("%d syntax error: unexpected %v, expected %v", err.lineno, err.got, err.want) } +// nolint: deadcode var ( errExpBol = errors.New("expected beginning of line") errExpElementOrLabel = errors.New("expected beginning of line") diff --git a/core/chain_makers.go b/core/chain_makers.go index 59af633dfd..35f79f6dab 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -31,6 +31,7 @@ import ( ) // So we can deterministically seed different blockchains +// nolint: deadcode var ( canonicalSeed = 1 forkSeed = 2 @@ -229,6 +230,7 @@ func makeHeader(config *params.ChainConfig, parent *types.Block, state *state.St // newCanonical creates a chain database, and injects a deterministic canonical // chain. Depending on the full flag, if creates either a full block chain or a // header only chain. +// nolint: deadcode func newCanonical(n int, full bool) (ethdb.Database, *BlockChain, error) { // Initialize a fresh chain with only a genesis block gspec := new(Genesis) diff --git a/core/genesis.go b/core/genesis.go index df491ce0f4..d4f38f1b60 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -86,6 +86,7 @@ type GenesisAccount struct { } // field type overrides for gencodec +// nolint: deadcode type genesisSpecMarshaling struct { Nonce math.HexOrDecimal64 Timestamp math.HexOrDecimal64 diff --git a/core/tx_pool.go b/core/tx_pool.go index c3915575b0..f42a622f31 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -35,6 +35,7 @@ import ( "gopkg.in/karalabe/cookiejar.v2/collections/prque" ) +// nolint: deadcode const ( // chainHeadChanSize is the size of channel listening to ChainHeadEvent. chainHeadChanSize = 10 diff --git a/core/types/block.go b/core/types/block.go index 1d00d9f930..c1303eb9b4 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -86,6 +86,7 @@ type Header struct { } // field type overrides for gencodec +// nolint: deadcode type headerMarshaling struct { Difficulty *hexutil.Big Number *hexutil.Big diff --git a/core/types/log.go b/core/types/log.go index be5de38da7..bd80e6f68b 100644 --- a/core/types/log.go +++ b/core/types/log.go @@ -56,6 +56,7 @@ type Log struct { Removed bool `json:"removed"` } +// nolint: deadcode type logMarshaling struct { Data hexutil.Bytes BlockNumber hexutil.Uint64 diff --git a/core/types/receipt.go b/core/types/receipt.go index bc3c996b4f..f21407d14e 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -57,6 +57,7 @@ type Receipt struct { GasUsed *big.Int `json:"gasUsed" gencodec:"required"` } +// nolint: deadcode type receiptMarshaling struct { PostState hexutil.Bytes Status hexutil.Uint diff --git a/core/types/transaction.go b/core/types/transaction.go index a46521236c..70460e87c4 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -32,6 +32,7 @@ import ( //go:generate gencodec -type txdata -field-override txdataMarshaling -out gen_tx_json.go +// nolint: deadcode var ( ErrInvalidSig = errors.New("invalid transaction v, r, s values") errNoSigner = errors.New("missing signing methods") @@ -71,6 +72,7 @@ type txdata struct { Hash *common.Hash `json:"hash" rlp:"-"` } +// nolint: deadcode type txdataMarshaling struct { AccountNonce hexutil.Uint64 Price *hexutil.Big diff --git a/core/vm/logger.go b/core/vm/logger.go index 75309da921..ba54686e9a 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -66,6 +66,7 @@ type StructLog struct { } // overrides for gencodec +// nolint: deadcode type structLogMarshaling struct { Stack []*math.HexOrDecimal256 Gas math.HexOrDecimal64 diff --git a/core/vm/memory_table.go b/core/vm/memory_table.go index bec0235bcc..ab49ebb38b 100644 --- a/core/vm/memory_table.go +++ b/core/vm/memory_table.go @@ -65,12 +65,6 @@ func memoryCall(stack *Stack) *big.Int { return math.BigMax(x, y) } -func memoryCallCode(stack *Stack) *big.Int { - x := calcMemSize(stack.Back(5), stack.Back(6)) - y := calcMemSize(stack.Back(3), stack.Back(4)) - - return math.BigMax(x, y) -} func memoryDelegateCall(stack *Stack) *big.Int { x := calcMemSize(stack.Back(4), stack.Back(5)) y := calcMemSize(stack.Back(2), stack.Back(3)) diff --git a/crypto/sha3/xor.go b/crypto/sha3/xor.go index 46a0d63a6d..df6cd3896e 100644 --- a/crypto/sha3/xor.go +++ b/crypto/sha3/xor.go @@ -13,4 +13,5 @@ var ( copyOutUnaligned = copyOutGeneric ) +// nolint: deadcode const xorImplementationUnaligned = "generic" diff --git a/crypto/sha3/xor_unaligned.go b/crypto/sha3/xor_unaligned.go index 929a486a79..608e994984 100644 --- a/crypto/sha3/xor_unaligned.go +++ b/crypto/sha3/xor_unaligned.go @@ -55,4 +55,5 @@ var ( copyOut = copyOutUnaligned ) +// nolint: deadcode const xorImplementationUnaligned = "unaligned" diff --git a/eth/config.go b/eth/config.go index 7bcfd403ea..f6c610a081 100644 --- a/eth/config.go +++ b/eth/config.go @@ -115,6 +115,7 @@ type Config struct { PowShared bool `toml:"-"` } +// nolint: deadcode type configMarshaling struct { ExtraData hexutil.Bytes } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index b338129e00..193cd3f830 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -69,6 +69,7 @@ var ( fsCriticalTrials = uint32(32) // Number of times to retry in the cricical section before bailing ) +// nolint: deadcode var ( errBusy = errors.New("busy") errUnknownPeer = errors.New("peer is unknown or unhealthy") diff --git a/les/bloombits.go b/les/bloombits.go index de233d7518..9453e25126 100644 --- a/les/bloombits.go +++ b/les/bloombits.go @@ -73,6 +73,7 @@ func (eth *LightEthereum) startBloomHandlers() { } } +// nolint: deadcode const ( // bloomConfirms is the number of confirmation blocks before a bloom section is // considered probably final and its rotated bits are calculated. diff --git a/les/serverpool.go b/les/serverpool.go index dc1ea6bf02..22c5d21467 100644 --- a/les/serverpool.go +++ b/les/serverpool.go @@ -36,6 +36,7 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) +// nolint: deadcode const ( // After a connection has been ended or timed out, there is a waiting period // before it can be selected for connection again. diff --git a/les/sync.go b/les/sync.go index c0e17f97d9..43d613413a 100644 --- a/les/sync.go +++ b/les/sync.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/light" ) +// nolint: deadcode const ( //forceSyncCycle = 10 * time.Second // Time interval to force syncs, even if few peers are available minDesiredPeerCount = 5 // Amount of peers desired to start syncing diff --git a/p2p/discover/node.go b/p2p/discover/node.go index fc928a91af..877e9f8542 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -412,6 +412,7 @@ func logdist(a, b common.Hash) int { } // hashAtDistance returns a random hash such that logdist(a, b) == n +// nolint: deadcode func hashAtDistance(a common.Hash, n int) (b common.Hash) { if n == 0 { return a diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index f9eb99ee36..cc9462b410 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -47,6 +47,7 @@ var ( ) // Timeouts +// nolint: deadcode const ( respTimeout = 500 * time.Millisecond sendTimeout = 500 * time.Millisecond diff --git a/p2p/discv5/net.go b/p2p/discv5/net.go index a39cfcc645..bb545068bd 100644 --- a/p2p/discv5/net.go +++ b/p2p/discv5/net.go @@ -34,6 +34,7 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) +// nolint: deadcode var ( errInvalidEvent = errors.New("invalid in current state") errNoQuery = errors.New("no pending query") @@ -48,6 +49,7 @@ const ( lowPort = 1024 ) +// nolint: deadcode const testTopic = "foo" const ( @@ -825,12 +827,11 @@ type nodeEvent uint //go:generate stringer -type=nodeEvent +// const ( - invalidEvent nodeEvent = iota // zero is reserved - // Packet type events. // These correspond to packet types in the UDP protocol. - pingPacket + pingPacket nodeEvent = iota + 1 pongPacket findnodePacket neighborsPacket diff --git a/p2p/discv5/node.go b/p2p/discv5/node.go index 2db7a508f0..0d0d03e89e 100644 --- a/p2p/discv5/node.go +++ b/p2p/discv5/node.go @@ -413,6 +413,7 @@ func logdist(a, b common.Hash) int { } // hashAtDistance returns a random hash such that logdist(a, b) == n +// nolint: deadcode func hashAtDistance(a common.Hash, n int) (b common.Hash) { if n == 0 { return a diff --git a/p2p/discv5/nodeevent_string.go b/p2p/discv5/nodeevent_string.go index fde9045c52..02b74e3f63 100644 --- a/p2p/discv5/nodeevent_string.go +++ b/p2p/discv5/nodeevent_string.go @@ -1,25 +1,26 @@ -// Code generated by "stringer -type nodeEvent"; DO NOT EDIT +// Code generated by "stringer -type=nodeEvent"; DO NOT EDIT. package discv5 import "fmt" const ( - _nodeEvent_name_0 = "invalidEventpingPacketpongPacketfindnodePacketneighborsPacketfindnodeHashPackettopicRegisterPackettopicQueryPackettopicNodesPacket" + _nodeEvent_name_0 = "pingPacketpongPacketfindnodePacketneighborsPacketfindnodeHashPackettopicRegisterPackettopicQueryPackettopicNodesPacket" _nodeEvent_name_1 = "pongTimeoutpingTimeoutneighboursTimeout" ) var ( - _nodeEvent_index_0 = [...]uint8{0, 12, 22, 32, 46, 61, 79, 98, 114, 130} + _nodeEvent_index_0 = [...]uint8{0, 10, 20, 34, 49, 67, 86, 102, 118} _nodeEvent_index_1 = [...]uint8{0, 11, 22, 39} ) func (i nodeEvent) String() string { switch { - case 0 <= i && i <= 8: + case 1 <= i && i <= 8: + i -= 1 return _nodeEvent_name_0[_nodeEvent_index_0[i]:_nodeEvent_index_0[i+1]] - case 265 <= i && i <= 267: - i -= 265 + case 264 <= i && i <= 266: + i -= 264 return _nodeEvent_name_1[_nodeEvent_index_1[i]:_nodeEvent_index_1[i+1]] default: return fmt.Sprintf("nodeEvent(%d)", i) diff --git a/p2p/discv5/ntp.go b/p2p/discv5/ntp.go index f78d5dc43c..3da4251533 100644 --- a/p2p/discv5/ntp.go +++ b/p2p/discv5/ntp.go @@ -44,6 +44,7 @@ func (s durationSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } // checkClockDrift queries an NTP server for clock drifts and warns the user if // one large enough is detected. +// nolint: deadcode func checkClockDrift() { drift, err := sntpDrift(ntpChecks) if err != nil { diff --git a/p2p/discv5/table.go b/p2p/discv5/table.go index 2cf05009cb..5b4788972c 100644 --- a/p2p/discv5/table.go +++ b/p2p/discv5/table.go @@ -32,6 +32,7 @@ import ( "github.com/ethereum/go-ethereum/common" ) +// nolint: deadcode const ( alpha = 3 // Kademlia concurrency factor bucketSize = 16 // Kademlia bucket size diff --git a/p2p/discv5/udp.go b/p2p/discv5/udp.go index 26087cd8e5..22ffa7aa50 100644 --- a/p2p/discv5/udp.go +++ b/p2p/discv5/udp.go @@ -35,6 +35,7 @@ import ( const Version = 4 // Errors +// nolint: deadcode var ( errPacketTooSmall = errors.New("too small") errBadHash = errors.New("bad hash") @@ -47,6 +48,7 @@ var ( ) // Timeouts +// nolint: deadcode const ( respTimeout = 500 * time.Millisecond sendTimeout = 500 * time.Millisecond diff --git a/p2p/message.go b/p2p/message.go index 5690494bf4..1e9006279f 100644 --- a/p2p/message.go +++ b/p2p/message.go @@ -114,6 +114,7 @@ func SendItems(w MsgWriter, msgcode uint64, elems ...interface{}) error { // netWrapper wraps a MsgReadWriter with locks around // ReadMsg/WriteMsg and applies read/write deadlines. +// nolint: deadcode type netWrapper struct { rmu, wmu sync.Mutex diff --git a/p2p/peer.go b/p2p/peer.go index 1d2b726e8b..1d67b61b85 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -41,6 +41,7 @@ const ( pingInterval = 15 * time.Second ) +// nolint: deadcode const ( // devp2p message codes handshakeMsg = 0x00 diff --git a/p2p/server.go b/p2p/server.go index d1d578401b..750cdf9947 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -35,6 +35,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/netutil" ) +// nolint: deadcode const ( defaultDialTimeout = 15 * time.Second refreshPeersInterval = 30 * time.Second diff --git a/swarm/network/kademlia/kademlia.go b/swarm/network/kademlia/kademlia.go index bf976a3e1d..b2a5a98b05 100644 --- a/swarm/network/kademlia/kademlia.go +++ b/swarm/network/kademlia/kademlia.go @@ -307,6 +307,7 @@ type nodesByDistance struct { target Address } +// nolint: deadcode func sortedByDistanceTo(target Address, slice []Node) bool { var last Address for i, node := range slice { diff --git a/swarm/storage/dbstore.go b/swarm/storage/dbstore.go index 46a5c16ccc..7578697789 100644 --- a/swarm/storage/dbstore.go +++ b/swarm/storage/dbstore.go @@ -38,6 +38,7 @@ import ( "github.com/syndtr/goleveldb/leveldb/iterator" ) +// nolint: deadcode const ( defaultDbCapacity = 5000000 defaultRadius = 0 // not yet used diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index 7b0612edc5..c7cbd8cb0e 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -77,6 +77,7 @@ func NewNetStore(hash SwarmHasher, lstore *LocalStore, cloud CloudStore, params } } +// nolint: deadcode const ( // maximum number of peers that a retrieved message is delivered to requesterCount = 3 diff --git a/whisper/whisperv2/topic.go b/whisper/whisperv2/topic.go index 3e2b47bd3f..5869a7e521 100644 --- a/whisper/whisperv2/topic.go +++ b/whisper/whisperv2/topic.go @@ -104,6 +104,7 @@ func newTopicMatcher(topics ...[]Topic) *topicMatcher { } // newTopicMatcherFromBinary create a topic matcher from a list of binary conditions. +// nolint: deadcode func newTopicMatcherFromBinary(data ...[][]byte) *topicMatcher { topics := make([][]Topic, len(data)) for i, condition := range data { @@ -114,6 +115,7 @@ func newTopicMatcherFromBinary(data ...[][]byte) *topicMatcher { // newTopicMatcherFromStrings creates a topic matcher from a list of textual // conditions. +// nolint: deadcode func newTopicMatcherFromStrings(data ...[]string) *topicMatcher { topics := make([][]Topic, len(data)) for i, condition := range data {