Skip to content

Commit

Permalink
lint: golint issue fixes (cometbft#4258)
Browse files Browse the repository at this point in the history
* lint: golint issue fixes

- on my local machine golint is a lot stricter than the bot so slowly going through and fixing things.

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>

* more fixes from golint

* remove isPeerPersistentFn

* add changelog entry
  • Loading branch information
tac0turtle authored Dec 17, 2019
1 parent f077727 commit 9bd0f9e
Show file tree
Hide file tree
Showing 56 changed files with 246 additions and 246 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ program](https://hackerone.com/tendermint).
- [libs/common] \#4240 Move async functions out of `libs/common` to `async` pkg
- [libs/common] \#4240 Move bit functions out of `libs/common` to `bits` pkg
- [libs/common] \#4240 Move cmap functions out of `libs/common` to `cmap` pkg
- [libs/common] \#4258 Remove `Rand` from all `rand` pkg functions
- Blockchain Protocol
Expand Down
4 changes: 2 additions & 2 deletions abci/client/socket_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/server"
"github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/libs/service"
)

Expand Down Expand Up @@ -97,7 +97,7 @@ func TestHangingSyncCalls(t *testing.T) {
func setupClientServer(t *testing.T, app types.Application) (
service.Service, abcicli.Client) {
// some port between 20k and 30k
port := 20000 + rand.RandInt32()%10000
port := 20000 + tmrand.Int32()%10000
addr := fmt.Sprintf("localhost:%d", port)

s, err := server.NewServer(addr, "socket", app)
Expand Down
6 changes: 3 additions & 3 deletions abci/example/kvstore/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package kvstore

import (
"github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
)

// RandVal creates one random validator, with a key derived
// from the input value
func RandVal(i int) types.ValidatorUpdate {
pubkey := rand.RandBytes(32)
power := rand.RandUint16() + 1
pubkey := tmrand.Bytes(32)
power := tmrand.Uint16() + 1
v := types.Ed25519ValidatorUpdate(pubkey, int64(power))
return v
}
Expand Down
6 changes: 3 additions & 3 deletions abci/tests/server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (

abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
)

func InitChain(client abcicli.Client) error {
total := 10
vals := make([]types.ValidatorUpdate, total)
for i := 0; i < total; i++ {
pubkey := rand.RandBytes(33)
power := rand.RandInt()
pubkey := tmrand.Bytes(33)
power := tmrand.Int()
vals[i] = types.Ed25519ValidatorUpdate(pubkey, int64(power))
}
_, err := client.InitChainSync(types.RequestInitChain{
Expand Down
6 changes: 3 additions & 3 deletions blockchain/v0/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
)
Expand Down Expand Up @@ -65,8 +65,8 @@ func (ps testPeers) stop() {
func makePeers(numPeers int, minHeight, maxHeight int64) testPeers {
peers := make(testPeers, numPeers)
for i := 0; i < numPeers; i++ {
peerID := p2p.ID(rand.RandStr(12))
height := minHeight + rand.RandInt63n(maxHeight-minHeight)
peerID := p2p.ID(tmrand.Str(12))
height := minHeight + tmrand.Int63n(maxHeight-minHeight)
peers[peerID] = testPeer{peerID, height, make(chan inputData, 10)}
}
return peers
Expand Down
18 changes: 9 additions & 9 deletions blockchain/v1/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
)

func TestPeerMonitor(t *testing.T) {
peer := NewBpPeer(
p2p.ID(rand.RandStr(12)), 10,
p2p.ID(tmrand.Str(12)), 10,
func(err error, _ p2p.ID) {},
nil)
peer.SetLogger(log.TestingLogger())
Expand All @@ -35,7 +35,7 @@ func TestPeerResetBlockResponseTimer(t *testing.T) {
params := &BpPeerParams{timeout: 2 * time.Millisecond}

peer := NewBpPeer(
p2p.ID(rand.RandStr(12)), 10,
p2p.ID(tmrand.Str(12)), 10,
func(err error, _ p2p.ID) {
peerTestMtx.Lock()
defer peerTestMtx.Unlock()
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestPeerRequestSent(t *testing.T) {
params := &BpPeerParams{timeout: 2 * time.Millisecond}

peer := NewBpPeer(
p2p.ID(rand.RandStr(12)), 10,
p2p.ID(tmrand.Str(12)), 10,
func(err error, _ p2p.ID) {},
params)

Expand All @@ -94,7 +94,7 @@ func TestPeerRequestSent(t *testing.T) {

func TestPeerGetAndRemoveBlock(t *testing.T) {
peer := NewBpPeer(
p2p.ID(rand.RandStr(12)), 100,
p2p.ID(tmrand.Str(12)), 100,
func(err error, _ p2p.ID) {},
nil)

Expand Down Expand Up @@ -142,7 +142,7 @@ func TestPeerGetAndRemoveBlock(t *testing.T) {

func TestPeerAddBlock(t *testing.T) {
peer := NewBpPeer(
p2p.ID(rand.RandStr(12)), 100,
p2p.ID(tmrand.Str(12)), 100,
func(err error, _ p2p.ID) {},
nil)

Expand Down Expand Up @@ -189,7 +189,7 @@ func TestPeerOnErrFuncCalledDueToExpiration(t *testing.T) {
)

peer := NewBpPeer(
p2p.ID(rand.RandStr(12)), 10,
p2p.ID(tmrand.Str(12)), 10,
func(err error, _ p2p.ID) {
peerTestMtx.Lock()
defer peerTestMtx.Unlock()
Expand All @@ -215,7 +215,7 @@ func TestPeerCheckRate(t *testing.T) {
minRecvRate: int64(100), // 100 bytes/sec exponential moving average
}
peer := NewBpPeer(
p2p.ID(rand.RandStr(12)), 10,
p2p.ID(tmrand.Str(12)), 10,
func(err error, _ p2p.ID) {},
params)
peer.SetLogger(log.TestingLogger())
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestPeerCleanup(t *testing.T) {
params := &BpPeerParams{timeout: 2 * time.Millisecond}

peer := NewBpPeer(
p2p.ID(rand.RandStr(12)), 10,
p2p.ID(tmrand.Str(12)), 10,
func(err error, _ p2p.ID) {},
params)
peer.SetLogger(log.TestingLogger())
Expand Down
14 changes: 7 additions & 7 deletions blockchain/v1/reactor_fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/libs/log"
tmmath "github.com/tendermint/tendermint/libs/math"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
)
Expand Down Expand Up @@ -736,7 +736,7 @@ func makeCorrectTransitionSequence(startingHeight int64, numBlocks int64, numPee
continue
}
if randomPeerHeights {
peerHeights[i] = int64(tmmath.MaxInt(rand.RandIntn(int(numBlocks)), int(startingHeight)+1))
peerHeights[i] = int64(tmmath.MaxInt(tmrand.Intn(int(numBlocks)), int(startingHeight)+1))
} else {
peerHeights[i] = numBlocks
}
Expand Down Expand Up @@ -826,19 +826,19 @@ const (

func makeCorrectTransitionSequenceWithRandomParameters() testFields {
// Generate a starting height for fast sync.
startingHeight := int64(rand.RandIntn(maxStartingHeightTest) + 1)
startingHeight := int64(tmrand.Intn(maxStartingHeightTest) + 1)

// Generate the number of requests per peer.
maxRequestsPerPeer := rand.RandIntn(maxRequestsPerPeerTest) + 1
maxRequestsPerPeer := tmrand.Intn(maxRequestsPerPeerTest) + 1

// Generate the maximum number of total pending requests, >= maxRequestsPerPeer.
maxPendingRequests := rand.RandIntn(maxTotalPendingRequestsTest-maxRequestsPerPeer) + maxRequestsPerPeer
maxPendingRequests := tmrand.Intn(maxTotalPendingRequestsTest-maxRequestsPerPeer) + maxRequestsPerPeer

// Generate the number of blocks to be synced.
numBlocks := int64(rand.RandIntn(maxNumBlocksInChainTest)) + startingHeight
numBlocks := int64(tmrand.Intn(maxNumBlocksInChainTest)) + startingHeight

// Generate a number of peers.
numPeers := rand.RandIntn(maxNumPeersTest) + 1
numPeers := tmrand.Intn(maxNumPeersTest) + 1

return makeCorrectTransitionSequence(startingHeight, numBlocks, numPeers, true, maxRequestsPerPeer, maxPendingRequests)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tendermint/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
cfg "github.com/tendermint/tendermint/config"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -56,7 +56,7 @@ func initFilesWithConfig(config *cfg.Config) error {
logger.Info("Found genesis file", "path", genFile)
} else {
genDoc := types.GenesisDoc{
ChainID: fmt.Sprintf("test-chain-%v", rand.RandStr(6)),
ChainID: fmt.Sprintf("test-chain-%v", tmrand.Str(6)),
GenesisTime: tmtime.Now(),
ConsensusParams: types.DefaultConsensusParams(),
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/tendermint/commands/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -168,7 +168,7 @@ func testnetFiles(cmd *cobra.Command, args []string) error {

// Generate genesis doc from generated validators
genDoc := &types.GenesisDoc{
ChainID: "chain-" + rand.RandStr(6),
ChainID: "chain-" + tmrand.Str(6),
ConsensusParams: types.DefaultConsensusParams(),
GenesisTime: tmtime.Now(),
Validators: genVals,
Expand Down Expand Up @@ -262,5 +262,5 @@ func moniker(i int) string {
}

func randomMoniker() string {
return bytes.HexBytes(rand.RandBytes(8)).String()
return bytes.HexBytes(tmrand.Bytes(8)).String()
}
6 changes: 3 additions & 3 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/mock"
"github.com/tendermint/tendermint/privval"
Expand Down Expand Up @@ -912,11 +912,11 @@ func (app *badApp) Commit() abci.ResponseCommit {
app.height++
if app.onlyLastHashIsWrong {
if app.height == app.numBlocks {
return abci.ResponseCommit{Data: rand.RandBytes(8)}
return abci.ResponseCommit{Data: tmrand.Bytes(8)}
}
return abci.ResponseCommit{Data: []byte{app.height}}
} else if app.allHashesAreWrong {
return abci.ResponseCommit{Data: rand.RandBytes(8)}
return abci.ResponseCommit{Data: tmrand.Bytes(8)}
}

panic("either allHashesAreWrong or onlyLastHashIsWrong must be set")
Expand Down
4 changes: 2 additions & 2 deletions consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
cstypes "github.com/tendermint/tendermint/consensus/types"
"github.com/tendermint/tendermint/libs/log"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
p2pmock "github.com/tendermint/tendermint/p2p/mock"
"github.com/tendermint/tendermint/types"
)
Expand Down Expand Up @@ -1563,7 +1563,7 @@ func TestStateOutputsBlockPartsStats(t *testing.T) {
peer := p2pmock.NewPeer(nil)

// 1) new block part
parts := types.NewPartSetFromData(rand.RandBytes(100), 10)
parts := types.NewPartSetFromData(tmrand.Bytes(100), 10)
msg := &BlockPartMessage{
Height: 1,
Round: 0,
Expand Down
26 changes: 13 additions & 13 deletions consensus/types/round_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
amino "github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
Expand All @@ -19,38 +19,38 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) {
vset, _ := types.RandValidatorSet(nval, 1)
commitSigs := make([]types.CommitSig, nval)
blockID := types.BlockID{
Hash: rand.RandBytes(tmhash.Size),
Hash: tmrand.Bytes(tmhash.Size),
PartsHeader: types.PartSetHeader{
Hash: rand.RandBytes(tmhash.Size),
Hash: tmrand.Bytes(tmhash.Size),
Total: 1000,
},
}
sig := make([]byte, ed25519.SignatureSize)
for i := 0; i < nval; i++ {
commitSigs[i] = (&types.Vote{
ValidatorAddress: types.Address(rand.RandBytes(20)),
ValidatorAddress: types.Address(tmrand.Bytes(20)),
Timestamp: tmtime.Now(),
BlockID: blockID,
Signature: sig,
}).CommitSig()
}
txs := make([]types.Tx, ntxs)
for i := 0; i < ntxs; i++ {
txs[i] = rand.RandBytes(100)
txs[i] = tmrand.Bytes(100)
}
// Random block
block := &types.Block{
Header: types.Header{
ChainID: rand.RandStr(12),
ChainID: tmrand.Str(12),
Time: tmtime.Now(),
LastBlockID: blockID,
LastCommitHash: rand.RandBytes(20),
DataHash: rand.RandBytes(20),
ValidatorsHash: rand.RandBytes(20),
ConsensusHash: rand.RandBytes(20),
AppHash: rand.RandBytes(20),
LastResultsHash: rand.RandBytes(20),
EvidenceHash: rand.RandBytes(20),
LastCommitHash: tmrand.Bytes(20),
DataHash: tmrand.Bytes(20),
ValidatorsHash: tmrand.Bytes(20),
ConsensusHash: tmrand.Bytes(20),
AppHash: tmrand.Bytes(20),
LastResultsHash: tmrand.Bytes(20),
EvidenceHash: tmrand.Bytes(20),
},
Data: types.Data{
Txs: txs,
Expand Down
4 changes: 2 additions & 2 deletions consensus/wal_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/tendermint/tendermint/abci/example/kvstore"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/rand"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/mock"
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy"
Expand Down Expand Up @@ -120,7 +120,7 @@ func WALWithNBlocks(t *testing.T, numBlocks int) (data []byte, err error) {
func randPort() int {
// returns between base and base + spread
base, spread := 20000, 20000
return base + rand.RandIntn(spread)
return base + tmrand.Intn(spread)
}

func makeAddrs() (string, string, string) {
Expand Down
Loading

0 comments on commit 9bd0f9e

Please sign in to comment.