diff --git a/internal/client/db/backend.go b/internal/client/db/backend.go index 993ad5da9b..eeff2aa126 100644 --- a/internal/client/db/backend.go +++ b/internal/client/db/backend.go @@ -684,7 +684,7 @@ func (b *Backend[H, Hasher, N, E, Header]) forceDelayedCanonicalize( return nil } -func (b *Backend[H, Hasher, N, E, Header]) tryCommitOperation( +func (b *Backend[H, Hasher, N, E, Header]) tryCommitOperation( //nolint:gocyclo operation *BlockImportOperation[H, Hasher, N, Header, E], ) error { var transaction database.Transaction[hash.H256] @@ -821,7 +821,7 @@ func (b *Backend[H, Hasher, N, E, Header]) tryCommitOperation( for key, update := range operation.dbUpdates.Drain() { if rc := update.RC; rc > 0 { ops += 1 - bytes += uint64(len(key) + len(update.Data)) //nolint:gosec + bytes += uint64(len(key) + len(update.Data)) if rc == 1 { changeset.Inserted = append(changeset.Inserted, statedb.HashDBValue[string]{ Hash: key, @@ -1261,14 +1261,14 @@ func applyIndexOps[E runtime.Extrinsic]( } for index, extrinsic := range body { var dbExtrinsic dbExtrinsic[E] - hash, ok := renewedMap[uint32(index)] //nolint:gosec + hash, ok := renewedMap[uint32(index)] if ok { // Bump ref counter encoded := scale.MustMarshal(extrinsic) transaction.Reference(columns.Transaction, hash) dbExtrinsic = newDbExtrinsic[E](dbExtrinsicIndexed{Hash: hash, Header: encoded}) } else { - i, ok := indexMap[uint32(index)] //nolint:gosec + i, ok := indexMap[uint32(index)] if ok { encoded := scale.MustMarshal(extrinsic) if int(i.Size) <= len(encoded) { @@ -1317,7 +1317,7 @@ func (b *Backend[H, Hasher, N, E, Header]) GetAux(key []byte) ([]byte, error) { return b.storage.db.Get(columns.Aux, key), nil } -func (b *Backend[H, Hasher, N, E, Header]) beginOperation() (*BlockImportOperation[H, Hasher, N, Header, E], error) { +func (b *Backend[H, Hasher, N, E, Header]) beginOperation() *BlockImportOperation[H, Hasher, N, Header, E] { return &BlockImportOperation[H, Hasher, N, Header, E]{ pendingBlock: nil, oldState: b.emptyState(), @@ -1330,13 +1330,13 @@ func (b *Backend[H, Hasher, N, E, Header]) beginOperation() (*BlockImportOperati setHead: nil, commitState: false, indexOps: make([]statemachine.IndexOperation, 0), - }, nil + } } func (b *Backend[H, Hasher, N, E, Header]) BeginOperation() ( api.BlockImportOperation[N, H, Hasher, Header, E], error, ) { - return b.beginOperation() + return b.beginOperation(), nil } func (b *Backend[H, Hasher, N, E, Header]) BeginStateOperation( diff --git a/internal/client/db/backend_test.go b/internal/client/db/backend_test.go index 120584add3..4ac01db62e 100644 --- a/internal/client/db/backend_test.go +++ b/internal/client/db/backend_test.go @@ -140,9 +140,8 @@ func insertBlock(t *testing.T, blockHash = parentHash } - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, blockHash) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, blockHash) require.NoError(t, err) if transactionIndex != nil { err = op.UpdateTransactionIndex(transactionIndex) @@ -181,8 +180,7 @@ func insertHeaderNoHead(t *testing.T, header := generic.NewHeader[uint64, hash.H256, runtime.BlakeTwo256]( number, extrinisicsRoot, hash.H256(""), parentHash, digest, ) - op, err := backend.beginOperation() - require.NoError(t, err) + op := backend.beginOperation() state, err := backend.StateAt(parentHash) if err != nil { @@ -280,8 +278,7 @@ func TestBackend(t *testing.T) { db := NewTestBackend(t, BlocksPruningSome(2), 0) var hash dbHash { - op, err := db.beginOperation() - require.NoError(t, err) + op := db.beginOperation() header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 0, dbHash(""), dbHash(""), dbHash(""), runtime.Digest{}, ) @@ -299,7 +296,7 @@ func TestBackend(t *testing.T) { for _, delta := range deltas { top.Set(string(delta.Key), delta.Value) } - _, err = op.ResetStorage(storage.Storage{ + _, err := op.ResetStorage(storage.Storage{ Top: *top, }, stateVersion) require.NoError(t, err) @@ -326,9 +323,8 @@ func TestBackend(t *testing.T) { } { - op, err := db.beginOperation() - require.NoError(t, err) - err = db.BeginStateOperation(op, hash) + op := db.beginOperation() + err := db.BeginStateOperation(op, hash) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 1, @@ -387,9 +383,8 @@ func TestBackend(t *testing.T) { var hash dbHash { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, dbHash("")) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, dbHash("")) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 0, @@ -421,9 +416,8 @@ func TestBackend(t *testing.T) { var hash1 dbHash { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, hash) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, hash) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 1, @@ -456,9 +450,8 @@ func TestBackend(t *testing.T) { var hash2 dbHash { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, hash1) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, hash1) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 2, @@ -489,9 +482,8 @@ func TestBackend(t *testing.T) { var hash3 dbHash { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, hash2) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, hash2) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 3, @@ -521,9 +513,8 @@ func TestBackend(t *testing.T) { var hash4 dbHash { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, hash3) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, hash3) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 4, @@ -829,9 +820,8 @@ func TestBackend(t *testing.T) { block4 := insertHeader(t, backend, 4, block3, nil, hash.H256("")) { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block0) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block0) require.NoError(t, err) err = op.MarkFinalized(block1, nil) require.NoError(t, err) @@ -842,9 +832,8 @@ func TestBackend(t *testing.T) { } { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block2) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block2) require.NoError(t, err) err = op.MarkFinalized(block3, nil) require.NoError(t, err) @@ -861,9 +850,8 @@ func TestBackend(t *testing.T) { var hash0 dbHash { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, dbHash("")) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, dbHash("")) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 0, @@ -907,9 +895,8 @@ func TestBackend(t *testing.T) { var hash1 dbHash { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, hash0) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, hash0) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 1, @@ -976,9 +963,8 @@ func TestBackend(t *testing.T) { block2 := insertHeader(t, backend, 2, block1, nil, hash.H256("")) { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block0) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block0) require.NoError(t, err) err = op.MarkFinalized(block2, nil) require.NoError(t, err) @@ -1010,9 +996,8 @@ func TestBackend(t *testing.T) { } { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, blocks[4]) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, blocks[4]) require.NoError(t, err) for i := 1; i < 5; i++ { err = op.MarkFinalized(blocks[i], nil) @@ -1592,9 +1577,8 @@ func TestBackend(t *testing.T) { var block3 hash.H256 { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block1) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block1) require.NoError(t, err) trie := triedb.NewEmptyTrieDB[hash.H256, runtime.BlakeTwo256]( trie.NewPrefixedMemoryDB[hash.H256, runtime.BlakeTwo256](), @@ -1619,9 +1603,8 @@ func TestBackend(t *testing.T) { var block4 hash.H256 { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block2) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block2) require.NoError(t, err) trie := triedb.NewEmptyTrieDB[hash.H256, runtime.BlakeTwo256]( trie.NewPrefixedMemoryDB[hash.H256, runtime.BlakeTwo256](), @@ -1646,9 +1629,8 @@ func TestBackend(t *testing.T) { var block3Fork hash.H256 { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block2) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block2) require.NoError(t, err) trie := triedb.NewEmptyTrieDB[hash.H256, runtime.BlakeTwo256]( trie.NewPrefixedMemoryDB[hash.H256, runtime.BlakeTwo256](), @@ -1739,9 +1721,8 @@ func TestBackend(t *testing.T) { var block1 hash.H256 { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, genesis) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, genesis) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 1, @@ -1791,9 +1772,8 @@ func TestBackend(t *testing.T) { // best block by now. var block2 hash.H256 { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block1) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block1) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 2, @@ -1842,9 +1822,8 @@ func TestBackend(t *testing.T) { // block from the POV of the db is still at `0`. var block3 hash.H256 { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block2) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block2) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 3, @@ -1892,9 +1871,8 @@ func TestBackend(t *testing.T) { // Now it should kick in. var block4 hash.H256 { - op, err := backend.beginOperation() - require.NoError(t, err) - err = backend.BeginStateOperation(op, block3) + op := backend.beginOperation() + err := backend.BeginStateOperation(op, block3) require.NoError(t, err) header := generic.NewHeader[uint64, dbHash, runtime.BlakeTwo256]( 4, @@ -2007,8 +1985,7 @@ func TestBackend(t *testing.T) { require.NoError(t, err) // Finalize all blocks. This will trigger pruning. - op, err := backend.beginOperation() - require.NoError(t, err) + op := backend.beginOperation() err = backend.BeginStateOperation(op, blocks[4]) require.NoError(t, err) for i := 1; i < 5; i++ { @@ -2119,8 +2096,7 @@ func TestBackend(t *testing.T) { err = backend.PinBlock(blocks[4]) require.NoError(t, err) // Mark block 5 as finalized. - op, err = backend.beginOperation() - require.NoError(t, err) + op = backend.beginOperation() err = backend.BeginStateOperation(op, blocks[5]) require.NoError(t, err) err = op.MarkFinalized(blocks[5], buildJustification(uint64(5))) @@ -2180,8 +2156,7 @@ func TestBackend(t *testing.T) { // Finalize block 6 so block 5 gets pruned. Since it is pinned both justifications should be // in memory. - op, err = backend.beginOperation() - require.NoError(t, err) + op = backend.beginOperation() err = backend.BeginStateOperation(op, blocks[6]) require.NoError(t, err) err = op.MarkFinalized(blocks[6], nil) diff --git a/internal/client/state-db/noncanonical.go b/internal/client/state-db/noncanonical.go index 11d859c0a2..b2989cd03c 100644 --- a/internal/client/state-db/noncanonical.go +++ b/internal/client/state-db/noncanonical.go @@ -146,10 +146,10 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) Insert( }) nco.lastCanonicalized = &lastCanonicalized } else if nco.lastCanonicalized != nil { - if number < frontBlockNumber || number > frontBlockNumber+uint64(nco.levels.Len()) { //nolint:gosec + if number < frontBlockNumber || number > frontBlockNumber+uint64(nco.levels.Len()) { log.Printf( "TRACE: Failed to insert block %v, current is %v .. %v)", - number, frontBlockNumber, frontBlockNumber+uint64(nco.levels.Len())) //nolint:gosec + number, frontBlockNumber, frontBlockNumber+uint64(nco.levels.Len())) return CommitSet[Key]{}, ErrInvalidBlockNumber } // check for valid parent if inserting on second level or higher @@ -163,13 +163,13 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) Insert( } var level overlayLevel[BlockHash, Key] = newOverlayLevel[BlockHash, Key]() var levelIndex int - if nco.levels.Len() == 0 || number == frontBlockNumber+uint64(nco.levels.Len()) { //nolint:gosec + if nco.levels.Len() == 0 || number == frontBlockNumber+uint64(nco.levels.Len()) { nco.levels.PushBack(newOverlayLevel[BlockHash, Key]()) level = nco.levels.Back() levelIndex = nco.levels.Len() - 1 } else { - level = nco.levels.At(int(number - frontBlockNumber)) //nolint:gosec - levelIndex = int(number - frontBlockNumber) //nolint:gosec + level = nco.levels.At(int(number - frontBlockNumber)) + levelIndex = int(number - frontBlockNumber) } if len(level.blocks) >= int(maxBlocksPerLevel) { @@ -219,10 +219,10 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) Insert( func (nco *nonCanonicalOverlay[BlockHash, Key]) discardJournals( levelIndex uint, discardedJournals *[][]byte, hash BlockHash) { - if levelIndex >= uint(nco.levels.Len()) { //nolint:gosec + if levelIndex >= uint(nco.levels.Len()) { return } - level := nco.levels.At(int(levelIndex)) //nolint:gosec + level := nco.levels.At(int(levelIndex)) for _, overlay := range level.blocks { parent, ok := nco.parents[overlay.hash] if !ok { @@ -416,7 +416,7 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) Remove(hash BlockHash) *CommitSe } } } - overlay := level.remove(uint(index)) //nolint:gosec + overlay := level.remove(uint(index)) nco.levels.Set(levelIndex, level) commit.Meta.Deleted = append(commit.Meta.Deleted, overlay.journalKey) delete(nco.parents, overlay.hash) @@ -494,7 +494,7 @@ func (ol *overlayLevel[BlockHash, Key]) push(overlay blockOverlay[BlockHash, Key } func (ol *overlayLevel[BlockHash, Key]) availableIndex() uint64 { - return uint64(bits.TrailingZeros64(^ol.usedIndices)) //nolint:gosec + return uint64(bits.TrailingZeros64(^ol.usedIndices)) } func (ol *overlayLevel[BlockHash, Key]) remove(index uint) blockOverlay[BlockHash, Key] { @@ -637,7 +637,7 @@ func discardDescendants[BlockHash Hash, Key Hash]( panic("there is a parent entry for each entry in levels; qed") } if h == hash { - index = uint(i) //nolint:gosec + index = uint(i) overlay := level.remove(index) numPinned := discardDescendants(remainder, values, parents, pinned, pinnedInsertions, overlay.hash) if _, ok := pinned[overlay.hash]; ok { diff --git a/internal/client/state-db/pruning.go b/internal/client/state-db/pruning.go index d8ed02dafd..7ca8274a2b 100644 --- a/internal/client/state-db/pruning.go +++ b/internal/client/state-db/pruning.go @@ -208,11 +208,11 @@ func (drqim *inMemDeathRowQueue[BlockHash, Key]) Import( block, ok := drqim.deathIndex[k] if ok { delete(drqim.deathIndex, k) - delete(drqim.deathRows.At(int(block-base)).deleted, k) //nolint:gosec + delete(drqim.deathRows.At(int(block-base)).deleted, k) } } // add new keys - importedBlock := base + uint64(drqim.deathRows.Len()) //nolint:gosec + importedBlock := base + uint64(drqim.deathRows.Len()) deletedMap := make(map[Key]any) for _, k := range deleted { drqim.deathIndex[k] = importedBlock @@ -237,7 +237,7 @@ func (drqim *inMemDeathRowQueue[BlockHash, Key]) PopFront(base uint64) (*deathRo // Check if the block at the given `index` of the queue exist // it is the caller's responsibility to ensure `index` won't be out of bounds func (drqim *inMemDeathRowQueue[BlockHash, Key]) HaveBlock(hash BlockHash, index uint) haveBlock { - if drqim.deathRows.At(int(index)).hash == hash { //nolint:gosec + if drqim.deathRows.At(int(index)).hash == hash { return haveBlockYes } return haveBlockNo @@ -245,7 +245,7 @@ func (drqim *inMemDeathRowQueue[BlockHash, Key]) HaveBlock(hash BlockHash, index // Return the number of block in the pruning window func (drqim *inMemDeathRowQueue[BlockHash, Key]) Len(base uint64) uint64 { - return uint64(drqim.deathRows.Len()) //nolint:gosec + return uint64(drqim.deathRows.Len()) } // Get the hash of the next pruning block diff --git a/internal/client/state-db/statedb.go b/internal/client/state-db/statedb.go index bdef6b91ba..79306d8767 100644 --- a/internal/client/state-db/statedb.go +++ b/internal/client/state-db/statedb.go @@ -672,7 +672,7 @@ func fetchStoredPruningMode(db MetaDB) (PruningMode, error) { return nil, err } if val == nil { - return nil, nil //nolint: nilnil + return nil, nil } mode := NewPruningModeFromID(val) if mode != nil { diff --git a/internal/cost-lru/cost_lru.go b/internal/cost-lru/cost_lru.go index ac3d05a7aa..54dd00ba6f 100644 --- a/internal/cost-lru/cost_lru.go +++ b/internal/cost-lru/cost_lru.go @@ -25,7 +25,7 @@ func New[K comparable, V any]( ) (*LRU[K, V], error) { var capacity = uint32(math.MaxUint32) / 8 if (maxCost / 8) < uint(capacity) { - capacity = uint32(maxCost / 8) //nolint:gosec + capacity = uint32(maxCost / 8) } lru, err := freelru.New[K, V](capacity, hash) if err != nil { diff --git a/internal/primitives/state-machine/trie_backend_essence.go b/internal/primitives/state-machine/trie_backend_essence.go index defeb0f9b8..2a2414725b 100644 --- a/internal/primitives/state-machine/trie_backend_essence.go +++ b/internal/primitives/state-machine/trie_backend_essence.go @@ -444,7 +444,7 @@ func (tbe *trieBackendEssence[H, Hasher]) ChildClosestMerkleValue( return nil, err } if root == nil { - return nil, nil //nolint:nilnil + return nil, nil } childRoot = *root diff --git a/internal/primitives/trie/cache/shared_cache.go b/internal/primitives/trie/cache/shared_cache.go index ce0f50b279..bb99ee29db 100644 --- a/internal/primitives/trie/cache/shared_cache.go +++ b/internal/primitives/trie/cache/shared_cache.go @@ -29,7 +29,7 @@ type hasher[K comparable] struct { } func (h hasher[K]) Hash(key K) uint32 { - return uint32(h.Hasher.Hash(key)) //nolint:gosec + return uint32(h.Hasher.Hash(key)) } // Constructor for [sharedNodeCache] with fixed size in number of bytes. @@ -40,7 +40,7 @@ func newSharedNodeCache[H runtime.Hash](sizeBytes uint) *sharedNodeCache[H] { var err error snc.lru, err = costlru.New(sizeBytes, h.Hash, func(hash H, node triedb.CachedNode[H]) uint32 { - return uint32(node.ByteSize()) //nolint:gosec + return uint32(node.ByteSize()) }) if err != nil { panic(err) @@ -63,7 +63,7 @@ func (snc *sharedNodeCache[H]) Update(list []updateItem[H]) { addCount := uint(0) snc.itemsEvicted = 0 - maxItemsEvicted := uint(snc.lru.Len()*100) / sharedNodeCacheMaxReplacePercent //nolint:gosec + maxItemsEvicted := uint(snc.lru.Len()*100) / sharedNodeCacheMaxReplacePercent for _, ui := range list { if ui.nodeCached.FromSharedCache { _, ok := snc.lru.Get(ui.Hash) @@ -143,14 +143,14 @@ func newSharedValueCache[H runtime.Hash](size uint) *sharedValueCache[H] { h := hasher[ValueCacheKeyComparable[H]]{maphash.NewHasher[ValueCacheKeyComparable[H]]()} svc.lru, err = costlru.New(size, h.Hash, func(key ValueCacheKeyComparable[H], value triedb.CachedValue[H]) uint32 { - keyCost := uint32(len(key.StorageKey)) //nolint:gosec + keyCost := uint32(len(key.StorageKey)) switch value := value.(type) { case triedb.NonExistingCachedValue[H]: return keyCost + 1 case triedb.ExistingHashCachedValue[H]: - return keyCost + uint32(value.Hash.Length()) //nolint:gosec + return keyCost + uint32(value.Hash.Length()) case triedb.ExistingCachedValue[H]: - return keyCost + uint32(value.Hash.Length()+len(value.Data)) //nolint:gosec + return keyCost + uint32(value.Hash.Length()+len(value.Data)) default: panic("unreachable") } @@ -198,7 +198,7 @@ func (svc *sharedValueCache[H]) Update(added []sharedValueCacheAdded[H], accesse // we don't evict the whole shared cache nor we keep spinning our wheels // evicting items which we've added ourselves in previous iterations of this loop. svc.itemsEvicted = 0 - maxItemsEvicted := uint(svc.lru.Len()) * 100 / sharedValueCacheMaxReplacePercent //nolint:gosec + maxItemsEvicted := uint(svc.lru.Len()) * 100 / sharedValueCacheMaxReplacePercent for _, svca := range added { added, _ := svc.lru.Add(svca.ValueCacheKey.ValueCacheKeyComparable(), svca.CachedValue) @@ -260,7 +260,7 @@ func NewSharedTrieCache[H runtime.Hash](size uint) *SharedTrieCache[H] { func (stc *SharedTrieCache[H]) LocalTrieCache() LocalTrieCache[H] { h := hasher[H]{maphash.NewHasher[H]()} nodeCache, err := costlru.New(localNodeCacheMaxSize, h.Hash, func(hash H, node nodeCached[H]) uint32 { - return uint32(node.ByteSize()) //nolint:gosec + return uint32(node.ByteSize()) }) if err != nil { panic(err) @@ -270,14 +270,14 @@ func (stc *SharedTrieCache[H]) LocalTrieCache() LocalTrieCache[H] { localValueCacheMaxSize, hasher[ValueCacheKeyComparable[H]]{maphash.NewHasher[ValueCacheKeyComparable[H]]()}.Hash, func(key ValueCacheKeyComparable[H], value triedb.CachedValue[H]) uint32 { - keyCost := uint32(len(key.StorageKey)) //nolint:gosec + keyCost := uint32(len(key.StorageKey)) switch value := value.(type) { case triedb.NonExistingCachedValue[H]: return keyCost + 1 case triedb.ExistingHashCachedValue[H]: - return keyCost + uint32(value.Hash.Length()) //nolint:gosec + return keyCost + uint32(value.Hash.Length()) case triedb.ExistingCachedValue[H]: - return keyCost + uint32(value.Hash.Length()+len(value.Data)) //nolint:gosec + return keyCost + uint32(value.Hash.Length()+len(value.Data)) default: panic("unreachable") } diff --git a/lib/blocktree/blocktree_test.go b/lib/blocktree/blocktree_test.go index 32a3ffa469..5a5af6697f 100644 --- a/lib/blocktree/blocktree_test.go +++ b/lib/blocktree/blocktree_test.go @@ -46,10 +46,10 @@ func Test_BlockTree_GetBlock(t *testing.T) { bt, hashes := createFlatTree(t, 2) n := bt.getNode(hashes[2]) - if n == nil { //nolint:staticcheck + if n == nil { t.Fatal("node is nil") } - if !bytes.Equal(hashes[2][:], (*n).hash[:]) { //nolint:staticcheck + if !bytes.Equal(hashes[2][:], (*n).hash[:]) { t.Fatalf("Fail: got %x expected %x", n.hash, hashes[2]) } diff --git a/pkg/trie/triedb/cache.go b/pkg/trie/triedb/cache.go index ee4e24f208..36b02dc26b 100644 --- a/pkg/trie/triedb/cache.go +++ b/pkg/trie/triedb/cache.go @@ -242,7 +242,7 @@ func (no ValueCachedNode[H]) Encoded() []byte { return no.Value } func (no EmptyCachedNode[H]) ByteSize() uint { return (uint)(unsafe.Sizeof(no)) } func (no LeafCachedNode[H]) ByteSize() uint { - return (uint)(unsafe.Sizeof(no)) + uint(len(no.PartialKey.Inner())+len(no.Value.data())) //nolint:gosec + return (uint)(unsafe.Sizeof(no)) + uint(len(no.PartialKey.Inner())+len(no.Value.data())) } func (no BranchCachedNode[H]) ByteSize() uint { selfSize := (uint)(unsafe.Sizeof(no)) diff --git a/pkg/trie/triedb/lookup.go b/pkg/trie/triedb/lookup.go index f6577e2048..82c5dca1cc 100644 --- a/pkg/trie/triedb/lookup.go +++ b/pkg/trie/triedb/lookup.go @@ -130,7 +130,7 @@ func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant( // (descendent), but not the other way around. if !node.PartialKey.StartsWithNibbles(partial) { l.recordAccess(NonExistingNodeAccess{FullKey: fullKey}) - return nil, nil //nolint:nilnil + return nil, nil } if partial.Len() != node.PartialKey.Len() { @@ -154,14 +154,14 @@ func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant( } return HashMerkleValue[H]{Hash: hash}, nil } - return nil, nil //nolint:nilnil + return nil, nil } // Partial key is longer or equal than the branch slice. // Ensure partial key starts with the branch slice. if !partial.StartsWithNibbleSlice(node.PartialKey) { l.recordAccess(NonExistingNodeAccess{FullKey: fullKey}) - return nil, nil //nolint:nilnil + return nil, nil } // Partial key starts with the branch slice. @@ -183,11 +183,11 @@ func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant( nextNode = child } else { l.recordAccess(NonExistingNodeAccess{fullKey}) - return nil, nil //nolint:nilnil + return nil, nil } case EmptyCachedNode[H]: l.recordAccess(NonExistingNodeAccess{FullKey: fullKey}) - return nil, nil //nolint:nilnil + return nil, nil default: panic("unreachable") }