golangci: add predeclared linter
These can be confusing.
This commit is contained in:
parent
63f212f4b3
commit
97193cf337
4 changed files with 13 additions and 12 deletions
|
@ -47,6 +47,7 @@ linters:
|
||||||
- errorlint
|
- errorlint
|
||||||
- gofmt
|
- gofmt
|
||||||
- misspell
|
- misspell
|
||||||
|
- predeclared
|
||||||
- whitespace
|
- whitespace
|
||||||
- goimports
|
- goimports
|
||||||
disable-all: true
|
disable-all: true
|
||||||
|
|
|
@ -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
|
var dur time.Duration
|
||||||
|
|
||||||
new := atomic.LoadUint32(&bc.persistedHeight)
|
newHeight := atomic.LoadUint32(&bc.persistedHeight)
|
||||||
var tgtBlock = int64(new)
|
var tgtBlock = int64(newHeight)
|
||||||
|
|
||||||
tgtBlock -= int64(bc.config.MaxTraceableBlocks)
|
tgtBlock -= int64(bc.config.MaxTraceableBlocks)
|
||||||
if bc.config.P2PStateExchangeExtensions {
|
if bc.config.P2PStateExchangeExtensions {
|
||||||
syncP := new / uint32(bc.config.StateSyncInterval)
|
syncP := newHeight / uint32(bc.config.StateSyncInterval)
|
||||||
syncP--
|
syncP--
|
||||||
syncP *= uint32(bc.config.StateSyncInterval)
|
syncP *= uint32(bc.config.StateSyncInterval)
|
||||||
if tgtBlock > int64(syncP) {
|
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)
|
||||||
tgtBlock *= int64(bc.config.GarbageCollectionPeriod)
|
tgtBlock *= int64(bc.config.GarbageCollectionPeriod)
|
||||||
// Count periods.
|
// Count periods.
|
||||||
old /= bc.config.GarbageCollectionPeriod
|
oldHeight /= bc.config.GarbageCollectionPeriod
|
||||||
new /= bc.config.GarbageCollectionPeriod
|
newHeight /= bc.config.GarbageCollectionPeriod
|
||||||
if tgtBlock > int64(bc.config.GarbageCollectionPeriod) && new != old {
|
if tgtBlock > int64(bc.config.GarbageCollectionPeriod) && newHeight != oldHeight {
|
||||||
tgtBlock /= int64(bc.config.GarbageCollectionPeriod)
|
tgtBlock /= int64(bc.config.GarbageCollectionPeriod)
|
||||||
tgtBlock *= int64(bc.config.GarbageCollectionPeriod)
|
tgtBlock *= int64(bc.config.GarbageCollectionPeriod)
|
||||||
dur = bc.stateRoot.GC(uint32(tgtBlock), bc.store)
|
dur = bc.stateRoot.GC(uint32(tgtBlock), bc.store)
|
||||||
|
|
|
@ -828,14 +828,14 @@ func (dao *Simple) StoreAsTransaction(tx *transaction.Transaction, index uint32,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dao *Simple) getKeyBuf(len int) []byte {
|
func (dao *Simple) getKeyBuf(l int) []byte {
|
||||||
if dao.private {
|
if dao.private {
|
||||||
if dao.keyBuf == nil {
|
if dao.keyBuf == nil {
|
||||||
dao.keyBuf = make([]byte, 0, 1+4+limits.MaxStorageKeyLen) // Prefix, uint32, key.
|
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 {
|
func (dao *Simple) getDataBuf() *io.BufBinWriter {
|
||||||
|
|
|
@ -13,8 +13,8 @@ func TestValidatorUnmarshal(t *testing.T) {
|
||||||
require.NoError(t, json.Unmarshal(old, v))
|
require.NoError(t, json.Unmarshal(old, v))
|
||||||
require.Equal(t, int64(100500), v.Votes)
|
require.Equal(t, int64(100500), v.Votes)
|
||||||
|
|
||||||
new := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":42}`)
|
newV := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":42}`)
|
||||||
require.NoError(t, json.Unmarshal(new, v))
|
require.NoError(t, json.Unmarshal(newV, v))
|
||||||
require.Equal(t, int64(42), v.Votes)
|
require.Equal(t, int64(42), v.Votes)
|
||||||
|
|
||||||
bad := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"notanumber"}`)
|
bad := []byte(`{"publickey":"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62","votes":"notanumber"}`)
|
||||||
|
|
Loading…
Reference in a new issue