Browse Source

lint: various fixes

## Description

various linitng fixes
pull/4855/head
Marko 5 years ago
committed by GitHub
parent
commit
9149ee7d8b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 36 additions and 44 deletions
  1. +1
    -1
      .github/workflows/lint.yaml
  2. +1
    -1
      blockchain/v1/reactor_fsm.go
  3. +8
    -8
      consensus/state.go
  4. +1
    -2
      lite/proxy/proxy.go
  5. +3
    -4
      lite2/provider/http/http_test.go
  6. +1
    -1
      mempool/clist_mempool.go
  7. +3
    -4
      node/node.go
  8. +2
    -3
      p2p/node_info_test.go
  9. +3
    -4
      p2p/pex/pex_reactor.go
  10. +2
    -2
      rpc/client/rpc_test.go
  11. +2
    -2
      rpc/jsonrpc/client/ws_client.go
  12. +1
    -2
      state/state_test.go
  13. +2
    -3
      store/store.go
  14. +6
    -7
      store/store_test.go

+ 1
- 1
.github/workflows/lint.yaml View File

@ -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 }}

+ 1
- 1
blockchain/v1/reactor_fsm.go View File

@ -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)


+ 8
- 8
consensus/state.go View File

@ -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) {


+ 1
- 2
lite/proxy/proxy.go View File

@ -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()
}


+ 3
- 4
lite2/provider/http/http_test.go View File

@ -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}")
}


+ 1
- 1
mempool/clist_mempool.go View File

@ -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)


+ 3
- 4
node/node.go View File

@ -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")


+ 2
- 3
p2p/node_info_test.go View File

@ -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


+ 3
- 4
p2p/pex/pex_reactor.go View File

@ -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 {


+ 2
- 2
rpc/client/rpc_test.go View File

@ -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)


+ 2
- 2
rpc/jsonrpc/client/ws_client.go View File

@ -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)


+ 1
- 2
state/state_test.go View File

@ -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)


+ 2
- 3
store/store.go View File

@ -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


+ 6
- 7
store/store_test.go View File

@ -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
}


Loading…
Cancel
Save