golangci: add predeclared linter

These can be confusing.
This commit is contained in:
Roman Khimov 2022-09-02 18:22:35 +03:00
parent 63f212f4b3
commit 97193cf337
4 changed files with 13 additions and 12 deletions

View file

@ -47,6 +47,7 @@ linters:
- errorlint
- gofmt
- misspell
- predeclared
- whitespace
- goimports
disable-all: true

View file

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

View file

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

View file

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