From 97193cf337ba9cbfee61791b0aedec03ed1ec465 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 2 Sep 2022 18:22:35 +0300 Subject: [PATCH] golangci: add predeclared linter These can be confusing. --- .golangci.yml | 1 + pkg/core/blockchain.go | 14 +++++++------- pkg/core/dao/dao.go | 6 +++--- pkg/neorpc/result/validator_test.go | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d63fe3d3e..4c282cb30 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -47,6 +47,7 @@ linters: - errorlint - gofmt - misspell + - predeclared - whitespace - goimports disable-all: true diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 479f5a83d..1c14b7851 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -693,15 +693,15 @@ func (bc *Blockchain) Run() { } } -func (bc *Blockchain) tryRunGC(old uint32) time.Duration { +func (bc *Blockchain) tryRunGC(oldHeight uint32) time.Duration { var dur time.Duration - new := atomic.LoadUint32(&bc.persistedHeight) - var tgtBlock = int64(new) + newHeight := atomic.LoadUint32(&bc.persistedHeight) + var tgtBlock = int64(newHeight) tgtBlock -= int64(bc.config.MaxTraceableBlocks) if bc.config.P2PStateExchangeExtensions { - syncP := new / uint32(bc.config.StateSyncInterval) + syncP := newHeight / uint32(bc.config.StateSyncInterval) syncP-- syncP *= uint32(bc.config.StateSyncInterval) if tgtBlock > int64(syncP) { @@ -712,9 +712,9 @@ func (bc *Blockchain) tryRunGC(old uint32) time.Duration { tgtBlock /= int64(bc.config.GarbageCollectionPeriod) tgtBlock *= int64(bc.config.GarbageCollectionPeriod) // Count periods. - old /= bc.config.GarbageCollectionPeriod - new /= bc.config.GarbageCollectionPeriod - if tgtBlock > int64(bc.config.GarbageCollectionPeriod) && new != old { + oldHeight /= bc.config.GarbageCollectionPeriod + newHeight /= bc.config.GarbageCollectionPeriod + if tgtBlock > int64(bc.config.GarbageCollectionPeriod) && newHeight != oldHeight { tgtBlock /= int64(bc.config.GarbageCollectionPeriod) tgtBlock *= int64(bc.config.GarbageCollectionPeriod) dur = bc.stateRoot.GC(uint32(tgtBlock), bc.store) diff --git a/pkg/core/dao/dao.go b/pkg/core/dao/dao.go index 5e1f17960..cd8266bef 100644 --- a/pkg/core/dao/dao.go +++ b/pkg/core/dao/dao.go @@ -828,14 +828,14 @@ func (dao *Simple) StoreAsTransaction(tx *transaction.Transaction, index uint32, return nil } -func (dao *Simple) getKeyBuf(len int) []byte { +func (dao *Simple) getKeyBuf(l int) []byte { if dao.private { if dao.keyBuf == nil { dao.keyBuf = make([]byte, 0, 1+4+limits.MaxStorageKeyLen) // Prefix, uint32, key. } - return dao.keyBuf[:len] // Should have enough capacity. + return dao.keyBuf[:l] // Should have enough capacity. } - return make([]byte, len) + return make([]byte, l) } func (dao *Simple) getDataBuf() *io.BufBinWriter { diff --git a/pkg/neorpc/result/validator_test.go b/pkg/neorpc/result/validator_test.go index f7ecd4b68..a45a81523 100644 --- a/pkg/neorpc/result/validator_test.go +++ b/pkg/neorpc/result/validator_test.go @@ -13,8 +13,8 @@ func TestValidatorUnmarshal(t *testing.T) { require.NoError(t, json.Unmarshal(old, v)) require.Equal(t, int64(100500), v.Votes) - new := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":42}`) - require.NoError(t, json.Unmarshal(new, v)) + newV := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":42}`) + require.NoError(t, json.Unmarshal(newV, v)) require.Equal(t, int64(42), v.Votes) bad := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"notanumber"}`)