Skip to content

Commit 5860f6b

Browse files
mdj3333cn
authored andcommitted
linter
1 parent 5d37552 commit 5860f6b

File tree

25 files changed

+77
-16
lines changed

25 files changed

+77
-16
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ vet:
103103
@go vet `go list -f {{.Dir}} ./... | grep -v "common/crypto/sha3"`
104104

105105
ineffassign:
106-
@golangci-lint run --no-config --issues-exit-code=1 --deadline=2m --disable-all --enable=ineffassign -n ./...
106+
@golangci-lint run --no-config --issues-exit-code=1 --deadline=2m --disable-all --enable=ineffassign ./...
107107

108108
test: ## Run unittests
109109
@go clean -testcache

blockchain/blockstore.go

+3
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ func (bs *BlockStore) SaveBlock(storeBatch dbm.Batch, blockdetail *types.BlockDe
572572
return lastSequence, nil
573573
}
574574

575+
//BlockdetailToBlockBody get block detail
575576
func (bs *BlockStore) BlockdetailToBlockBody(blockdetail *types.BlockDetail) *types.BlockBody {
576577
cfg := bs.client.GetConfig()
577578
height := blockdetail.Block.Height
@@ -1687,6 +1688,7 @@ func (bs *BlockStore) getRecvChunkHash(chunkNum int64) ([]byte, error) {
16871688
return chunk.ChunkHash, err
16881689
}
16891690

1691+
//GetMaxSerialChunkNum get max serial chunk num
16901692
func (bs *BlockStore) GetMaxSerialChunkNum() int64 {
16911693
value, err := bs.db.Get(MaxSerialChunkNum)
16921694
if err != nil {
@@ -1700,6 +1702,7 @@ func (bs *BlockStore) GetMaxSerialChunkNum() int64 {
17001702
return chunkNum.Data
17011703
}
17021704

1705+
//SetMaxSerialChunkNum set max serial chunk num
17031706
func (bs *BlockStore) SetMaxSerialChunkNum(chunkNum int64) error {
17041707
data := &types.Int64{
17051708
Data: chunkNum,

blockchain/blockstore_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ func TestGetBodyFromP2Pstore(t *testing.T) {
431431
Height: 1,
432432
}
433433
body, err := blockStore.multiGetBody(blockheader, "", calcHeightHashKey(1, blcokHash), nil)
434+
assert.NotNil(t, body)
434435
assert.Equal(t, err, types.ErrHashNotExist)
435436
bcConfig := cfg.GetModuleConfig().BlockChain
436437
bcConfig.EnableFetchP2pstore = true

blockchain/blocksyn.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type BestPeerInfo struct {
8888
//记录最新区块上链的时间,长时间没有更新需要做对应的超时处理
8989
//主要是处理联盟链区块高度相差一个区块
9090
//整个网络长时间不出块时需要主动去获取最新的区块
91+
//BlockOnChain struct
9192
type BlockOnChain struct {
9293
sync.RWMutex
9394
Height int64
@@ -103,7 +104,7 @@ func (chain *BlockChain) initOnChainTimeout() {
103104
chain.blockOnChain.OnChainTime = types.Now().Unix()
104105
}
105106

106-
//onChainTimeout 最新区块长时间没有更新并超过设置的超时时间
107+
//OnChainTimeout 最新区块长时间没有更新并超过设置的超时时间
107108
func (chain *BlockChain) OnChainTimeout(height int64) bool {
108109
chain.blockOnChain.Lock()
109110
defer chain.blockOnChain.Unlock()

blockchain/blocktable_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ func testBlockTable(cfg *types.Chain33Config, t *testing.T, blockchain *blockcha
144144
assert.Equal(t, count, 0)
145145

146146
//获取平行链title对应的区块高度,向后翻
147-
count = 0
148147
req.Direction = 1
149148
paraTxs, err = blockchain.LoadParaTxByTitle(&req)
150149
require.NoError(t, err)

blockchain/chain.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,11 @@ func (chain *BlockChain) InitIndexAndBestView() {
499499
for ; height <= curheight; height++ {
500500
header, err := chain.blockStore.GetBlockHeaderByHeight(height)
501501
if header == nil {
502+
chainlog.Error("InitIndexAndBestView GetBlockHeaderByHeight", "height", height, "err", err)
502503
//开始升级localdb到2.0.0版本时需要兼容旧的存储方式
503504
header, err = chain.blockStore.getBlockHeaderByHeightOld(height)
504505
if header == nil {
505-
chainlog.Error("InitIndexAndBestView GetBlockHeaderByHeight", "height", height, "err", err)
506+
chainlog.Error("InitIndexAndBestView getBlockHeaderByHeightOld", "height", height, "err", err)
506507
panic("InitIndexAndBestView fail!")
507508
}
508509
}

blockchain/chain_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ func TestOnChainTimeout(t *testing.T) {
11951195
//2秒后超时
11961196
time.Sleep(2 * time.Second)
11971197
lastheight := blockchain.GetBlockHeight()
1198-
isTimeOut = blockchain.OnChainTimeout(lastheight)
1198+
blockchain.OnChainTimeout(lastheight)
11991199
println("curheight:", curheight)
12001200
println("lastheight:", lastheight)
12011201
if lastheight == curheight {

blockchain/chunkshard.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
var (
19+
//ErrNoBlockToChunk ErrNoBlockToChunk
1920
ErrNoBlockToChunk = errors.New("ErrNoBlockToChunk")
2021
ErrNoChunkInfoToDownLoad = errors.New("ErrNoChunkInfoToDownLoad")
2122
ErrNoChunkNumSerial = errors.New("ErrNoChunkNumSerial")

blockchain/export_block_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func testImportBlockProc(t *testing.T) {
9898
err = blockchain.ImportBlock(title, dbPath)
9999
require.NoError(t, err)
100100
curHeader, err := blockchain.ProcGetLastHeaderMsg()
101+
require.NoError(t, err)
101102
assert.Equal(t, curHeader.Height, endBlock.GetHeight())
102103
assert.Equal(t, curHeader.GetHash(), endBlock.GetHash())
103104
file := title + ".db"

blockchain/push.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func (push *Push) runTask(input *pushNotify) {
447447
push.updateLastSeq(input.subscribe.Name)
448448

449449
go func(in *pushNotify) {
450-
var lastesBlockSeq int64 = -1
450+
var lastesBlockSeq int64
451451
var continueFailCount int32
452452
var err error
453453

blockchain/push_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func Test_addSubscriber_Success(t *testing.T) {
223223
key := calcPushKey(subscribe.Name)
224224
subInfo, err := chain.push.store.GetKey(key)
225225
assert.NotEqual(t, err, nil)
226-
//assert.Equal(t, subInfo, nil)
226+
assert.NotEqual(t, subInfo, nil)
227227

228228
err = chain.push.addSubscriber(subscribe)
229229
assert.Equal(t, err, nil)
@@ -678,7 +678,7 @@ func Test_RecoverPush(t *testing.T) {
678678
createBlocks(t, mock33, chain, 10)
679679
time.Sleep(3 * time.Second)
680680
assert.Equal(t, atomic.LoadInt32(&pushNotifyInfo.status), notRunning)
681-
lastSeq, _ = chain.ProcGetLastPushSeq(subscribe.Name)
681+
chain.ProcGetLastPushSeq(subscribe.Name)
682682

683683
//chain33的push服务重启后,不会将其添加到task中,
684684
chainAnother := &BlockChain{

golinter.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function filterLinter() {
1818
--enable=goimports \
1919
--enable=misspell \
2020
--enable=golint \
21-
--exclude=underscores
21+
--exclude=underscores \
22+
--exclude-use-default=false
2223
)
2324
# --enable=staticcheck \
2425
# --enable=gocyclo \

metrics/metrics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var (
2323
log = chain33log.New("module", "chain33 metrics")
2424
)
2525

26-
//根据配置文件相关参数启动m
26+
//StartMetrics 根据配置文件相关参数启动m
2727
func StartMetrics(cfg *types.Chain33Config) {
2828
metrics := cfg.GetModuleConfig().Metrics
2929
if !metrics.EnableMetrics {

rpc/rpc_real_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func TestExprieCreateNoBalanceTransaction(t *testing.T) {
166166
assert.Nil(t, err)
167167
var tx types.Transaction
168168
err = types.Decode(txByteData, &tx)
169+
assert.Nil(t, err)
169170
txgroup, err := tx.GetTxGroup()
170171
assert.Nil(t, err)
171172
assert.True(t, txgroup.GetTxs()[0].GetExpire() > 0)
@@ -184,6 +185,7 @@ func TestExprieSignRawTx(t *testing.T) {
184185
}
185186
var res string
186187
err := jrpcClient.Call("Chain33.CreateTransaction", req, &res)
188+
assert.Nil(t, err)
187189

188190
txNone := &types.Transaction{Execer: []byte(cfg.ExecName(types.NoneX)), Payload: []byte("no-fee-transaction")}
189191
txNone.To = address.ExecAddress(string(txNone.Execer))
@@ -202,6 +204,7 @@ func TestExprieSignRawTx(t *testing.T) {
202204
assert.Nil(t, err)
203205
var tx types.Transaction
204206
err = types.Decode(txByteData, &tx)
207+
assert.Nil(t, err)
205208
req3 := &types.ReqSignRawTx{
206209
TxHex: common.ToHex(types.Encode(&tx)),
207210
Privkey: common.ToHex(gen),
@@ -215,6 +218,7 @@ func TestExprieSignRawTx(t *testing.T) {
215218
assert.Nil(t, err)
216219
var tx2 types.Transaction
217220
err = types.Decode(txByteData, &tx2)
221+
assert.Nil(t, err)
218222
txgroup2, err := tx2.GetTxGroup()
219223
assert.Nil(t, err)
220224
assert.True(t, txgroup2.GetTxs()[0].GetExpire() > 0)

system/consensus/base.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ func (bc *BaseClient) CmpBestBlock(newBlock *types.Block, cmpHash []byte) bool {
648648
return false
649649
}
650650

651-
//RequestBlockByHash 通过区块hash获取区块信息
651+
//ReqBlockByHash 通过区块hash获取区块信息
652652
func (bc *BaseClient) ReqBlockByHash(hash []byte) (*types.Block, error) {
653653
if bc.client == nil {
654654
panic("bc not bind message queue.")

system/consensus/solo/solo_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func BenchmarkSendTx(b *testing.B) {
8686
subcfg := cfg.GetSubConfig()
8787
cfg.GetModuleConfig().Exec.DisableAddrIndex = true
8888
solocfg, err := types.ModifySubConfig(subcfg.Consensus["solo"], "waitTxMs", 100)
89+
assert.Nil(b, err)
8990
solocfg, err = types.ModifySubConfig(solocfg, "benchMode", true)
9091
assert.Nil(b, err)
9192
subcfg.Consensus["solo"] = solocfg
@@ -113,6 +114,7 @@ func BenchmarkSoloNewBlock(b *testing.B) {
113114
cfg.GetModuleConfig().Mempool.DisableExecCheck = true
114115
subcfg := cfg.GetSubConfig()
115116
solocfg, err := types.ModifySubConfig(subcfg.Consensus["solo"], "waitTxMs", 100)
117+
assert.Nil(b, err)
116118
solocfg, err = types.ModifySubConfig(solocfg, "benchMode", true)
117119
assert.Nil(b, err)
118120
subcfg.Consensus["solo"] = solocfg

0 commit comments

Comments
 (0)