Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Nov 5, 2024
1 parent 14af9c9 commit 183d6d7
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 17 deletions.
16 changes: 8 additions & 8 deletions internal/client/state-db/noncanonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) Insert(
if number < frontBlockNumber || number > frontBlockNumber+uint64(nco.levels.Len()) {

Check failure on line 149 in internal/client/state-db/noncanonical.go

View workflow job for this annotation

GitHub Actions / linting

G115: integer overflow conversion int -> uint64 (gosec)
log.Printf(
"TRACE: Failed to insert block %v, current is %v .. %v)\n",
number, frontBlockNumber, frontBlockNumber+uint64(nco.levels.Len()))
number, frontBlockNumber, frontBlockNumber+uint64(nco.levels.Len())) //nolint:gosec
return CommitSet[Key]{}, ErrInvalidBlockNumber
}
// check for valid parent if inserting on second level or higher
Expand All @@ -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()) {
if nco.levels.Len() == 0 || number == frontBlockNumber+uint64(nco.levels.Len()) { //nolint:gosec
nco.levels.PushBack(newOverlayLevel[BlockHash, Key]())
level = nco.levels.Back()
levelIndex = nco.levels.Len() - 1
} else {
level = nco.levels.At(int(number - frontBlockNumber))
levelIndex = int(number - frontBlockNumber)
level = nco.levels.At(int(number - frontBlockNumber)) //nolint:gosec
levelIndex = int(number - frontBlockNumber) //nolint:gosec
}

if len(level.blocks) >= int(maxBlocksPerLevel) {
Expand Down Expand Up @@ -221,10 +221,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()) {
if levelIndex >= uint(nco.levels.Len()) { //nolint:gosec
return
}
level := nco.levels.At(int(levelIndex))
level := nco.levels.At(int(levelIndex)) //nolint:gosec
for _, overlay := range level.blocks {
parent, ok := nco.parents[overlay.hash]
if !ok {
Expand Down Expand Up @@ -418,7 +418,7 @@ func (nco *nonCanonicalOverlay[BlockHash, Key]) Remove(hash BlockHash) *CommitSe
}
}
}
overlay := level.remove(uint(index))
overlay := level.remove(uint(index)) //nolint:gosec
nco.levels.Set(levelIndex, level)
commit.Meta.Deleted = append(commit.Meta.Deleted, overlay.journalKey)
delete(nco.parents, overlay.hash)
Expand Down Expand Up @@ -639,7 +639,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)
index = uint(i) //nolint:gosec
overlay := level.remove(index)
numPinned := discardDescendants(remainder, values, parents, pinned, pinnedInsertions, overlay.hash)
if _, ok := pinned[overlay.hash]; ok {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/state-db/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ 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)
delete(drqim.deathRows.At(int(block-base)).deleted, k) //nolint:gosec
}
}
// add new keys
Expand Down
3 changes: 3 additions & 0 deletions internal/hash-db/hash_db.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2024 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package hashdb

import "golang.org/x/exp/constraints"
Expand Down
3 changes: 3 additions & 0 deletions internal/memory-db/memory_db.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2024 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package memorydb

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/memory-db/memory_db_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2024 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package memorydb

import (
Expand Down
6 changes: 3 additions & 3 deletions pkg/trie/triedb/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ type (
}
)

func (EmptyCachedNode[H]) Data() []byte { return nil } //nolint:unused
func (no LeafCachedNode[H]) Data() []byte { return no.Value.data() } //nolint:unused
func (no BranchCachedNode[H]) Data() []byte { //nolint:unused
func (EmptyCachedNode[H]) Data() []byte { return nil }
func (no LeafCachedNode[H]) Data() []byte { return no.Value.data() }
func (no BranchCachedNode[H]) Data() []byte {
if no.Value != nil {
return no.Value.data()
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/trie/triedb/cache_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2024 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package triedb

import (
Expand Down
10 changes: 6 additions & 4 deletions pkg/trie/triedb/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func (l *TrieLookup[H, Hasher, QueryItem]) recordAccess(access TrieAccess) {
// / When the provided key leads to a node, then the merkle value (hash) of that node
// / is returned. However, if the key does not lead to a node, then the merkle value
// / of the closest descendant is returned. `None` if no such descendant exists.
func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant(fullKey []byte, nibbleKey nibbles.Nibbles) (MerkleValue[H], error) {
func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant(
fullKey []byte, nibbleKey nibbles.Nibbles,
) (MerkleValue[H], error) {
partial := nibbleKey
hash := l.hash
var keyNibbles uint
Expand Down Expand Up @@ -128,7 +130,7 @@ func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant(fullKey []byte,
// (descendent), but not the other way around.
if !node.PartialKey.StartsWithNibbles(partial) {
l.recordAccess(NonExistingNodeAccess{FullKey: fullKey})
return nil, nil
return nil, nil //nolint:nilnil
}

if partial.Len() != node.PartialKey.Len() {
Expand All @@ -152,14 +154,14 @@ func (l *TrieLookup[H, Hasher, QueryItem]) LookupFirstDescendant(fullKey []byte,
}
return HashMerkleValue[H]{Hash: hash}, nil
}
return nil, nil
return nil, nil //nolint:nilnil
}

// 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
return nil, nil //nolint:nilnil
}

// Partial key starts with the branch slice.
Expand Down
5 changes: 4 additions & 1 deletion pkg/trie/triedb/proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func NewMerkleProof[H hash.Hash, Hasher hash.Hasher[H]](
recorder := triedb.NewRecorder[H]()
trie := triedb.NewTrieDB[H, Hasher](rootHash, db, triedb.WithRecorder[H, Hasher](recorder))
trie.SetVersion(trieVersion)
trie.Get(key)
_, err = trie.Get(key)
if err != nil {
return nil, err
}

recordedNodes := NewIterator(recorder.Drain())

Expand Down

0 comments on commit 183d6d7

Please sign in to comment.