diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index b5e2c89ac..37f702ef6 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -9,6 +9,6 @@ jobs: - uses: golangci/golangci-lint-action@master with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.26 + version: v1.27 args: --timeout 10m github-token: ${{ secrets.github_token }} diff --git a/blockchain/v1/reactor_fsm.go b/blockchain/v1/reactor_fsm.go index 0f65f9d66..84944d0a6 100644 --- a/blockchain/v1/reactor_fsm.go +++ b/blockchain/v1/reactor_fsm.go @@ -105,7 +105,7 @@ func (msg *bcReactorMessage) String() string { case stateTimeoutEv: dataStr = fmt.Sprintf("state=%v", msg.data.stateName) default: - dataStr = fmt.Sprintf("cannot interpret message data") + dataStr = "cannot interpret message data" } return fmt.Sprintf("%v: %v", msg.event, dataStr) diff --git a/consensus/state.go b/consensus/state.go index 906dd96fb..7aadc56da 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -205,7 +205,7 @@ func StateMetrics(metrics *Metrics) StateOption { // String returns a string. func (cs *State) String() string { // better not to access shared variables - return fmt.Sprintf("ConsensusState") //(H:%v R:%v S:%v", cs.Height, cs.Round, cs.Step) + return "ConsensusState" } // GetState returns a copy of the chain state. @@ -1415,16 +1415,16 @@ func (cs *State) finalizeCommit(height int64) { block, blockParts := cs.ProposalBlock, cs.ProposalBlockParts if !ok { - panic(fmt.Sprintf("Cannot finalizeCommit, commit does not have two thirds majority")) + panic("Cannot finalizeCommit, commit does not have two thirds majority") } if !blockParts.HasHeader(blockID.PartsHeader) { - panic(fmt.Sprintf("Expected ProposalBlockParts header to be commit header")) + panic("Expected ProposalBlockParts header to be commit header") } if !block.HashesTo(blockID.Hash) { - panic(fmt.Sprintf("Cannot finalizeCommit, ProposalBlock does not hash to commit hash")) + panic("Cannot finalizeCommit, ProposalBlock does not hash to commit hash") } if err := cs.blockExec.ValidateBlock(cs.state, block); err != nil { - panic(fmt.Sprintf("+2/3 committed an invalid block: %v", err)) + panic(fmt.Errorf("+2/3 committed an invalid block: %w", err)) } cs.Logger.Info("Finalizing commit of block with N txs", @@ -1968,12 +1968,12 @@ func (cs *State) voteTime() time.Time { minVoteTime := now // TODO: We should remove next line in case we don't vote for v in case cs.ProposalBlock == nil, // even if cs.LockedBlock != nil. See https://docs.tendermint.com/master/spec/. - timeIotaMs := time.Duration(cs.state.ConsensusParams.Block.TimeIotaMs) * time.Millisecond + timeIota := time.Duration(cs.state.ConsensusParams.Block.TimeIotaMs) * time.Millisecond if cs.LockedBlock != nil { // See the BFT time spec https://docs.tendermint.com/master/spec/consensus/bft-time.html - minVoteTime = cs.LockedBlock.Time.Add(timeIotaMs) + minVoteTime = cs.LockedBlock.Time.Add(timeIota) } else if cs.ProposalBlock != nil { - minVoteTime = cs.ProposalBlock.Time.Add(timeIotaMs) + minVoteTime = cs.ProposalBlock.Time.Add(timeIota) } if now.After(minVoteTime) { diff --git a/lite/proxy/proxy.go b/lite/proxy/proxy.go index b72f863ed..57c079289 100644 --- a/lite/proxy/proxy.go +++ b/lite/proxy/proxy.go @@ -8,7 +8,6 @@ import ( "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/rpc/client" rpcclient "github.com/tendermint/tendermint/rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server" @@ -88,7 +87,7 @@ func RPCRoutes(c rpcclient.Client) map[string]*rpcserver.RPCFunc { } } -func makeStatusFunc(c client.StatusClient) func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { +func makeStatusFunc(c rpcclient.StatusClient) func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { return func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { return c.Status() } diff --git a/lite2/provider/http/http_test.go b/lite2/provider/http/http_test.go index 33ab63a37..9d7bbe273 100644 --- a/lite2/provider/http/http_test.go +++ b/lite2/provider/http/http_test.go @@ -10,7 +10,6 @@ import ( "github.com/tendermint/tendermint/abci/example/kvstore" "github.com/tendermint/tendermint/lite2/provider" - "github.com/tendermint/tendermint/lite2/provider/http" litehttp "github.com/tendermint/tendermint/lite2/provider/http" rpcclient "github.com/tendermint/tendermint/rpc/client" rpchttp "github.com/tendermint/tendermint/rpc/client/http" @@ -19,15 +18,15 @@ import ( ) func TestNewProvider(t *testing.T) { - c, err := http.New("chain-test", "192.168.0.1:26657") + c, err := litehttp.New("chain-test", "192.168.0.1:26657") require.NoError(t, err) require.Equal(t, fmt.Sprintf("%s", c), "http{http://192.168.0.1:26657}") - c, err = http.New("chain-test", "http://153.200.0.1:26657") + c, err = litehttp.New("chain-test", "http://153.200.0.1:26657") require.NoError(t, err) require.Equal(t, fmt.Sprintf("%s", c), "http{http://153.200.0.1:26657}") - c, err = http.New("chain-test", "153.200.0.1") + c, err = litehttp.New("chain-test", "153.200.0.1") require.NoError(t, err) require.Equal(t, fmt.Sprintf("%s", c), "http{http://153.200.0.1}") } diff --git a/mempool/clist_mempool.go b/mempool/clist_mempool.go index f55d62329..d73105165 100644 --- a/mempool/clist_mempool.go +++ b/mempool/clist_mempool.go @@ -707,7 +707,7 @@ func (cache *mapTxCache) Push(tx types.Tx) bool { if cache.list.Len() >= cache.size { popped := cache.list.Front() - poppedTxHash := popped.Value.([sha256.Size]byte) + poppedTxHash := popped.Value.([sha256.Size]byte) //nolint:staticcheck // SA5011: possible nil pointer dereference delete(cache.cacheMap, poppedTxHash) if popped != nil { cache.list.Remove(popped) diff --git a/node/node.go b/node/node.go index cc63222e6..540362529 100644 --- a/node/node.go +++ b/node/node.go @@ -23,7 +23,6 @@ import ( bcv1 "github.com/tendermint/tendermint/blockchain/v1" bcv2 "github.com/tendermint/tendermint/blockchain/v2" cfg "github.com/tendermint/tendermint/config" - "github.com/tendermint/tendermint/consensus" cs "github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/evidence" @@ -392,7 +391,7 @@ func createConsensusReactor(config *cfg.Config, csMetrics *cs.Metrics, waitSync bool, eventBus *types.EventBus, - consensusLogger log.Logger) (*consensus.Reactor, *consensus.State) { + consensusLogger log.Logger) (*cs.Reactor, *cs.State) { consensusState := cs.NewState( config.Consensus, @@ -491,7 +490,7 @@ func createSwitch(config *cfg.Config, mempoolReactor *mempl.Reactor, bcReactor p2p.Reactor, stateSyncReactor *statesync.Reactor, - consensusReactor *consensus.Reactor, + consensusReactor *cs.Reactor, evidenceReactor *evidence.Reactor, nodeInfo p2p.NodeInfo, nodeKey *p2p.NodeKey, @@ -566,7 +565,7 @@ func createPEXReactorAndAddToSwitch(addrBook pex.AddrBook, config *cfg.Config, } // startStateSync starts an asynchronous state sync process, then switches to fast sync mode. -func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *consensus.Reactor, +func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reactor, stateProvider statesync.StateProvider, config *cfg.StateSyncConfig, fastSync bool, stateDB dbm.DB, blockStore *store.BlockStore) error { ssR.Logger.Info("Starting state sync") diff --git a/p2p/node_info_test.go b/p2p/node_info_test.go index 8896efe1d..c34e71230 100644 --- a/p2p/node_info_test.go +++ b/p2p/node_info_test.go @@ -1,7 +1,6 @@ package p2p import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -24,8 +23,8 @@ func TestNodeInfoValidate(t *testing.T) { dupChannels = append(dupChannels, testCh) nonASCII := "¢§µ" - emptyTab := fmt.Sprintf("\t") - emptySpace := fmt.Sprintf(" ") + emptyTab := "\t" + emptySpace := " " testCases := []struct { testName string diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index c8d97a702..26f714772 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -11,7 +11,6 @@ import ( "github.com/tendermint/tendermint/libs/cmap" tmmath "github.com/tendermint/tendermint/libs/math" - "github.com/tendermint/tendermint/libs/rand" tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/p2p" @@ -409,7 +408,7 @@ func (r *Reactor) SetEnsurePeersPeriod(d time.Duration) { // Ensures that sufficient peers are connected. (continuous) func (r *Reactor) ensurePeersRoutine() { var ( - seed = rand.NewRand() + seed = tmrand.NewRand() jitter = seed.Int63n(r.ensurePeersPeriod.Nanoseconds()) ) @@ -545,8 +544,8 @@ func (r *Reactor) dialPeer(addr *p2p.NetAddress) error { // exponential backoff if it's not our first attempt to dial given address if attempts > 0 { - jitterSeconds := time.Duration(tmrand.Float64() * float64(time.Second)) // 1s == (1e9 ns) - backoffDuration := jitterSeconds + ((1 << uint(attempts)) * time.Second) + jitter := time.Duration(tmrand.Float64() * float64(time.Second)) // 1s == (1e9 ns) + backoffDuration := jitter + ((1 << uint(attempts)) * time.Second) backoffDuration = r.maxBackoffDurationForPeer(addr, backoffDuration) sinceLastDialed := time.Since(lastDialed) if sinceLastDialed < backoffDuration { diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index db025bdb5..1614b0b70 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -520,14 +520,14 @@ func TestTxSearch(t *testing.T) { require.Len(t, result.Txs, 0) // check sorting - result, err = c.TxSearch(fmt.Sprintf("tx.height >= 1"), false, 1, 30, "asc") + result, err = c.TxSearch("tx.height >= 1", false, 1, 30, "asc") require.Nil(t, err) for k := 0; k < len(result.Txs)-1; k++ { require.LessOrEqual(t, result.Txs[k].Height, result.Txs[k+1].Height) require.LessOrEqual(t, result.Txs[k].Index, result.Txs[k+1].Index) } - result, err = c.TxSearch(fmt.Sprintf("tx.height >= 1"), false, 1, 30, "desc") + result, err = c.TxSearch("tx.height >= 1", false, 1, 30, "desc") require.Nil(t, err) for k := 0; k < len(result.Txs)-1; k++ { require.GreaterOrEqual(t, result.Txs[k].Height, result.Txs[k+1].Height) diff --git a/rpc/jsonrpc/client/ws_client.go b/rpc/jsonrpc/client/ws_client.go index b1e449a7a..2158d2f70 100644 --- a/rpc/jsonrpc/client/ws_client.go +++ b/rpc/jsonrpc/client/ws_client.go @@ -294,8 +294,8 @@ func (c *WSClient) reconnect() error { }() for { - jitterSeconds := time.Duration(tmrand.Float64() * float64(time.Second)) // 1s == (1e9 ns) - backoffDuration := jitterSeconds + ((1 << uint(attempt)) * time.Second) + jitter := time.Duration(tmrand.Float64() * float64(time.Second)) // 1s == (1e9 ns) + backoffDuration := jitter + ((1 << uint(attempt)) * time.Second) c.Logger.Info("reconnecting", "attempt", attempt+1, "backoff_duration", backoffDuration) time.Sleep(backoffDuration) diff --git a/state/state_test.go b/state/state_test.go index a506b1d27..f8f65b58e 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -17,7 +17,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/libs/rand" tmrand "github.com/tendermint/tendermint/libs/rand" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" @@ -346,7 +345,7 @@ func genValSetWithPowers(powers []int64) *types.ValidatorSet { for i := 0; i < size; i++ { totalVotePower += powers[i] val := types.NewValidator(ed25519.GenPrivKey().PubKey(), powers[i]) - val.ProposerPriority = rand.Int64() + val.ProposerPriority = tmrand.Int64() vals[i] = val } valSet := types.NewValidatorSet(vals) diff --git a/store/store.go b/store/store.go index e599b69b0..ef5692c67 100644 --- a/store/store.go +++ b/store/store.go @@ -5,7 +5,6 @@ import ( "strconv" "sync" - db "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db" "github.com/tendermint/tendermint/types" @@ -211,7 +210,7 @@ func (bs *BlockStore) PruneBlocks(height int64) (uint64, error) { pruned := uint64(0) batch := bs.db.NewBatch() defer batch.Close() - flush := func(batch db.Batch, base int64) error { + flush := func(batch dbm.Batch, base int64) error { // We can't trust batches to be atomic, so update base first to make sure noone // tries to access missing blocks. bs.mtx.Lock() @@ -277,7 +276,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s panic(fmt.Sprintf("BlockStore can only save contiguous blocks. Wanted %v, got %v", w, g)) } if !blockParts.IsComplete() { - panic(fmt.Sprintf("BlockStore can only save complete block part sets")) + panic("BlockStore can only save complete block part sets") } // Save block meta diff --git a/store/store_test.go b/store/store_test.go index c311b0439..5da5daeda 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -11,7 +11,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - db "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db" cfg "github.com/tendermint/tendermint/config" @@ -63,7 +62,7 @@ func makeStateAndBlockStore(logger log.Logger) (sm.State, *BlockStore, cleanupFu } func TestLoadBlockStoreStateJSON(t *testing.T) { - db := db.NewMemDB() + db := dbm.NewMemDB() bsj := &BlockStoreStateJSON{Base: 100, Height: 1000} bsj.Save(db) @@ -72,7 +71,7 @@ func TestLoadBlockStoreStateJSON(t *testing.T) { } func TestLoadBlockStoreStateJSON_Empty(t *testing.T) { - db := db.NewMemDB() + db := dbm.NewMemDB() bsj := &BlockStoreStateJSON{} bsj.Save(db) @@ -82,7 +81,7 @@ func TestLoadBlockStoreStateJSON_Empty(t *testing.T) { } func TestLoadBlockStoreStateJSON_NoBase(t *testing.T) { - db := db.NewMemDB() + db := dbm.NewMemDB() bsj := &BlockStoreStateJSON{Height: 1000} bsj.Save(db) @@ -92,7 +91,7 @@ func TestLoadBlockStoreStateJSON_NoBase(t *testing.T) { } func TestNewBlockStore(t *testing.T) { - db := db.NewMemDB() + db := dbm.NewMemDB() err := db.Set(blockStoreKey, []byte(`{"base": "100", "height": "10000"}`)) require.NoError(t, err) bs := NewBlockStore(db) @@ -126,8 +125,8 @@ func TestNewBlockStore(t *testing.T) { assert.Equal(t, bs.Height(), int64(0), "expecting nil bytes to be unmarshaled alright") } -func freshBlockStore() (*BlockStore, db.DB) { - db := db.NewMemDB() +func freshBlockStore() (*BlockStore, dbm.DB) { + db := dbm.NewMemDB() return NewBlockStore(db), db }