dev: fix: more errcheck lint issues

This commit is contained in:
marcello33 2023-06-15 15:31:07 +02:00
parent 6223765aab
commit 82f33b22f5
26 changed files with 54 additions and 30 deletions

View file

@ -49,7 +49,7 @@ linters:
- tparallel - tparallel
- unconvert - unconvert
- unparam - unparam
- wsl # - wsl
- asasalint - asasalint
#- errorlint causes stack overflow. TODO: recheck after each golangci update #- errorlint causes stack overflow. TODO: recheck after each golangci update

View file

@ -91,11 +91,11 @@ func TestCalcDifficulty(t *testing.T) {
func randSlice(min, max uint32) []byte { func randSlice(min, max uint32) []byte {
var b = make([]byte, 4) var b = make([]byte, 4)
crand.Read(b) _ , _ = crand.Read(b)
a := binary.LittleEndian.Uint32(b) a := binary.LittleEndian.Uint32(b)
size := min + a%(max-min) size := min + a%(max-min)
out := make([]byte, size) out := make([]byte, size)
crand.Read(out) _ , _ = crand.Read(out)
return out return out
} }

View file

@ -82,6 +82,7 @@ func (f *chainFreezer) Close() error {
// //
// This functionality is deliberately broken off from block importing to avoid // This functionality is deliberately broken off from block importing to avoid
// incurring additional data shuffling delays on block propagation. // incurring additional data shuffling delays on block propagation.
// nolint:gocognit
func (f *chainFreezer) freeze(db ethdb.KeyValueStore) { func (f *chainFreezer) freeze(db ethdb.KeyValueStore) {
var ( var (
backoff bool backoff bool
@ -250,6 +251,7 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore) {
} }
} }
// nolint:gocognit
func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hashes []common.Hash, err error) { func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hashes []common.Hash, err error) {
hashes = make([]common.Hash, 0, limit-number) hashes = make([]common.Hash, 0, limit-number)

View file

@ -197,6 +197,7 @@ func resolveChainFreezerDir(ancient string) string {
// value data store with a freezer moving immutable chain segments into cold // value data store with a freezer moving immutable chain segments into cold
// storage. The passed ancient indicates the path of root ancient directory // storage. The passed ancient indicates the path of root ancient directory
// where the chain freezer can be opened. // where the chain freezer can be opened.
// nolint:gocognit
func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace string, readonly bool) (ethdb.Database, error) { func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace string, readonly bool) (ethdb.Database, error) {
// Create the idle freezer instance // Create the idle freezer instance
frdb, err := newChainFreezer(resolveChainFreezerDir(ancient), namespace, readonly) frdb, err := newChainFreezer(resolveChainFreezerDir(ancient), namespace, readonly)

View file

@ -409,6 +409,7 @@ type convertLegacyFn = func([]byte) ([]byte, error)
// MigrateTable processes the entries in a given table in sequence // MigrateTable processes the entries in a given table in sequence
// converting them to a new format if they're of an old format. // converting them to a new format if they're of an old format.
// nolint:gocognit
func (f *Freezer) MigrateTable(kind string, convert convertLegacyFn) error { func (f *Freezer) MigrateTable(kind string, convert convertLegacyFn) error {
if f.readonly { if f.readonly {
return errReadOnly return errReadOnly

View file

@ -555,13 +555,13 @@ func (t *freezerTable) Close() error {
defer t.lock.Unlock() defer t.lock.Unlock()
var errs []error var errs []error
doClose := func(f *os.File, sync bool, close bool) { doClose := func(f *os.File, sync bool, closed bool) {
if sync && !t.readonly { if sync && !t.readonly {
if err := f.Sync(); err != nil { if err := f.Sync(); err != nil {
errs = append(errs, err) errs = append(errs, err)
} }
} }
if close { if closed {
if err := f.Close(); err != nil { if err := f.Close(); err != nil {
errs = append(errs, err) errs = append(errs, err)
} }

View file

@ -89,7 +89,7 @@ func TestNodeIteratorCoverage(t *testing.T) {
// isTrieNode is a helper function which reports if the provided // isTrieNode is a helper function which reports if the provided
// database entry belongs to a trie node or not. // database entry belongs to a trie node or not.
func isTrieNode(scheme string, key, val []byte) (bool, common.Hash) { func isTrieNode(scheme string, key, _ []byte) (bool, common.Hash) {
if scheme == rawdb.HashScheme { if scheme == rawdb.HashScheme {
if len(key) == common.HashLength { if len(key) == common.HashLength {
return true, common.BytesToHash(key) return true, common.BytesToHash(key)

View file

@ -235,6 +235,7 @@ func prune(snaptree *snapshot.Tree, root common.Hash, maindb ethdb.Database, sta
// Prune deletes all historical state nodes except the nodes belong to the // Prune deletes all historical state nodes except the nodes belong to the
// specified state version. If user doesn't specify the state version, use // specified state version. If user doesn't specify the state version, use
// the bottom-most snapshot diff layer as the target. // the bottom-most snapshot diff layer as the target.
// nolint:nestif
func (p *Pruner) Prune(root common.Hash) error { func (p *Pruner) Prune(root common.Hash) error {
// If the state bloom filter is already committed previously, // If the state bloom filter is already committed previously,
// reuse it for pruning instead of generating a new one. It's // reuse it for pruning instead of generating a new one. It's

View file

@ -244,6 +244,7 @@ func runReport(stats *generateStats, stop chan bool) {
// generateTrieRoot generates the trie hash based on the snapshot iterator. // generateTrieRoot generates the trie hash based on the snapshot iterator.
// It can be used for generating account trie, storage trie or even the // It can be used for generating account trie, storage trie or even the
// whole state which connects the accounts and the corresponding storages. // whole state which connects the accounts and the corresponding storages.
// nolint:gocognit
func generateTrieRoot(db ethdb.KeyValueWriter, scheme string, it Iterator, account common.Hash, generatorFn trieGeneratorFn, leafCallback leafCallbackFn, stats *generateStats, report bool) (common.Hash, error) { func generateTrieRoot(db ethdb.KeyValueWriter, scheme string, it Iterator, account common.Hash, generatorFn trieGeneratorFn, leafCallback leafCallbackFn, stats *generateStats, report bool) (common.Hash, error) {
var ( var (
in = make(chan trieKV) // chan to pass leaves in = make(chan trieKV) // chan to pass leaves

View file

@ -159,6 +159,7 @@ func (result *proofResult) forEach(callback func(key []byte, val []byte) error)
// //
// The proof result will be returned if the range proving is finished, otherwise // The proof result will be returned if the range proving is finished, otherwise
// the error will be returned to abort the entire procedure. // the error will be returned to abort the entire procedure.
// nolint:gocognit
func (dl *diskLayer) proveRange(ctx *generatorContext, trieId *trie.ID, prefix []byte, kind string, origin []byte, max int, valueConvertFn func([]byte) ([]byte, error)) (*proofResult, error) { func (dl *diskLayer) proveRange(ctx *generatorContext, trieId *trie.ID, prefix []byte, kind string, origin []byte, max int, valueConvertFn func([]byte) ([]byte, error)) (*proofResult, error) {
var ( var (
keys [][]byte keys [][]byte
@ -307,6 +308,7 @@ type onStateCallback func(key []byte, val []byte, write bool, delete bool) error
// generateRange generates the state segment with particular prefix. Generation can // generateRange generates the state segment with particular prefix. Generation can
// either verify the correctness of existing state through range-proof and skip // either verify the correctness of existing state through range-proof and skip
// generation, or iterate trie to regenerate state on demand. // generation, or iterate trie to regenerate state on demand.
// nolint:gocognit
func (dl *diskLayer) generateRange(ctx *generatorContext, trieId *trie.ID, prefix []byte, kind string, origin []byte, max int, onState onStateCallback, valueConvertFn func([]byte) ([]byte, error)) (bool, []byte, error) { func (dl *diskLayer) generateRange(ctx *generatorContext, trieId *trie.ID, prefix []byte, kind string, origin []byte, max int, onState onStateCallback, valueConvertFn func([]byte) ([]byte, error)) (bool, []byte, error) {
// Use range prover to check the validity of the flat state in the range // Use range prover to check the validity of the flat state in the range
result, err := dl.proveRange(ctx, trieId, prefix, kind, origin, max, valueConvertFn) result, err := dl.proveRange(ctx, trieId, prefix, kind, origin, max, valueConvertFn)
@ -573,6 +575,7 @@ func generateStorages(ctx *generatorContext, dl *diskLayer, stateRoot common.Has
// generateAccounts generates the missing snapshot accounts as well as their // generateAccounts generates the missing snapshot accounts as well as their
// storage slots in the main trie. It's supposed to restart the generation // storage slots in the main trie. It's supposed to restart the generation
// from the given origin position. // from the given origin position.
// nolint:nestif,gocognit
func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) error { func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) error {
onAccount := func(key []byte, val []byte, write bool, delete bool) error { onAccount := func(key []byte, val []byte, write bool, delete bool) error {
// Make sure to clear all dangling storages before this account // Make sure to clear all dangling storages before this account
@ -636,7 +639,7 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
// If the iterated account is the contract, create a further loop to // If the iterated account is the contract, create a further loop to
// verify or regenerate the contract storage. // verify or regenerate the contract storage.
if acc.Root == types.EmptyRootHash { if acc.Root == types.EmptyRootHash {
ctx.removeStorageAt(account) _ = ctx.removeStorageAt(account)
} else { } else {
var storeMarker []byte var storeMarker []byte
if accMarker != nil && bytes.Equal(account[:], accMarker) && len(dl.genMarker) > common.HashLength { if accMarker != nil && bytes.Equal(account[:], accMarker) && len(dl.genMarker) > common.HashLength {

View file

@ -200,7 +200,7 @@ func (t *testHelper) makeStorageTrie(stateRoot, owner common.Hash, keys []string
root, nodes := stTrie.Commit(false) root, nodes := stTrie.Commit(false)
if nodes != nil { if nodes != nil {
t.nodes.Merge(nodes) _ = t.nodes.Merge(nodes)
} }
return root.Bytes() return root.Bytes()
} }
@ -208,10 +208,10 @@ func (t *testHelper) makeStorageTrie(stateRoot, owner common.Hash, keys []string
func (t *testHelper) Commit() common.Hash { func (t *testHelper) Commit() common.Hash {
root, nodes := t.accTrie.Commit(true) root, nodes := t.accTrie.Commit(true)
if nodes != nil { if nodes != nil {
t.nodes.Merge(nodes) _ = t.nodes.Merge(nodes)
} }
t.triedb.Update(t.nodes) _ = t.triedb.Update(t.nodes)
t.triedb.Commit(root, false) _ = t.triedb.Commit(root, false)
return root return root
} }
@ -400,8 +400,8 @@ func TestGenerateCorruptAccountTrie(t *testing.T) {
root := helper.Commit() // Root: 0xa04693ea110a31037fb5ee814308a6f1d76bdab0b11676bdf4541d2de55ba978 root := helper.Commit() // Root: 0xa04693ea110a31037fb5ee814308a6f1d76bdab0b11676bdf4541d2de55ba978
// Delete an account trie leaf and ensure the generator chokes // Delete an account trie leaf and ensure the generator chokes
helper.triedb.Commit(root, false) _ = helper.triedb.Commit(root, false)
helper.diskdb.Delete(common.HexToHash("0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7").Bytes()) _ = helper.diskdb.Delete(common.HexToHash("0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7").Bytes())
snap := generateSnapshot(helper.diskdb, helper.triedb, 16, root) snap := generateSnapshot(helper.diskdb, helper.triedb, 16, root)
select { select {
@ -436,7 +436,7 @@ func TestGenerateMissingStorageTrie(t *testing.T) {
root := helper.Commit() root := helper.Commit()
// Delete a storage trie root and ensure the generator chokes // Delete a storage trie root and ensure the generator chokes
helper.diskdb.Delete(stRoot) _ = helper.diskdb.Delete(stRoot)
snap := generateSnapshot(helper.diskdb, helper.triedb, 16, root) snap := generateSnapshot(helper.diskdb, helper.triedb, 16, root)
select { select {
@ -470,7 +470,7 @@ func TestGenerateCorruptStorageTrie(t *testing.T) {
root := helper.Commit() root := helper.Commit()
// Delete a storage trie leaf and ensure the generator chokes // Delete a storage trie leaf and ensure the generator chokes
helper.diskdb.Delete(common.HexToHash("0x18a0f4d79cff4459642dd7604f303886ad9d77c30cf3d7d7cedb3a693ab6d371").Bytes()) _ = helper.diskdb.Delete(common.HexToHash("0x18a0f4d79cff4459642dd7604f303886ad9d77c30cf3d7d7cedb3a693ab6d371").Bytes())
snap := generateSnapshot(helper.diskdb, helper.triedb, 16, root) snap := generateSnapshot(helper.diskdb, helper.triedb, 16, root)
select { select {

View file

@ -48,7 +48,7 @@ func TestAccountIteratorBasics(t *testing.T) {
if rand.Intn(2) == 0 { if rand.Intn(2) == 0 {
accStorage := make(map[common.Hash][]byte) accStorage := make(map[common.Hash][]byte)
value := make([]byte, 32) value := make([]byte, 32)
crand.Read(value) _ , _ = crand.Read(value)
accStorage[randomHash()] = value accStorage[randomHash()] = value
storage[h] = accStorage storage[h] = accStorage
} }
@ -80,7 +80,7 @@ func TestStorageIteratorBasics(t *testing.T) {
var nilstorage int var nilstorage int
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
crand.Read(value) _ , _ = crand.Read(value)
if rand.Intn(2) == 0 { if rand.Intn(2) == 0 {
accStorage[randomHash()] = common.CopyBytes(value) accStorage[randomHash()] = common.CopyBytes(value)
} else { } else {

View file

@ -281,6 +281,7 @@ type journalCallback = func(parent common.Hash, root common.Hash, destructs map[
// the most recent layer. // the most recent layer.
// This method returns error either if there was some error reading from disk, // This method returns error either if there was some error reading from disk,
// OR if the callback returns an error when invoked. // OR if the callback returns an error when invoked.
// nolint:gocognit
func iterateJournal(db ethdb.KeyValueReader, callback journalCallback) error { func iterateJournal(db ethdb.KeyValueReader, callback journalCallback) error {
journal := rawdb.ReadSnapshotJournal(db) journal := rawdb.ReadSnapshotJournal(db)
if len(journal) == 0 { if len(journal) == 0 {

View file

@ -31,6 +31,7 @@ func NewStateSync(root common.Hash, database ethdb.KeyValueReader, onLeaf func(k
// Register the storage slot callback if the external callback is specified. // Register the storage slot callback if the external callback is specified.
var onSlot func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error var onSlot func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error
if onLeaf != nil { if onLeaf != nil {
// nolint:unparam
onSlot = func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error { onSlot = func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error {
return onLeaf(keys, leaf) return onLeaf(keys, leaf)
} }

View file

@ -173,6 +173,7 @@ type stateElement struct {
syncPath trie.SyncPath syncPath trie.SyncPath
} }
// nolint:nestif
func testIterativeStateSync(t *testing.T, count int, commit bool, bypath bool) { func testIterativeStateSync(t *testing.T, count int, commit bool, bypath bool) {
// Create a random state to copy // Create a random state to copy
_, srcDb, srcRoot, srcAccounts := makeTestState() _, srcDb, srcRoot, srcAccounts := makeTestState()
@ -298,6 +299,7 @@ func testIterativeStateSync(t *testing.T, count int, commit bool, bypath bool) {
// Tests that the trie scheduler can correctly reconstruct the state even if only // Tests that the trie scheduler can correctly reconstruct the state even if only
// partial results are returned, and the others sent only later. // partial results are returned, and the others sent only later.
// nolint:prealloc
func TestIterativeDelayedStateSync(t *testing.T) { func TestIterativeDelayedStateSync(t *testing.T) {
// Create a random state to copy // Create a random state to copy
_, srcDb, srcRoot, srcAccounts := makeTestState() _, srcDb, srcRoot, srcAccounts := makeTestState()

View file

@ -99,6 +99,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
} }
// UnmarshalJSON unmarshals from JSON. // UnmarshalJSON unmarshals from JSON.
// nolint:gocognit
func (tx *Transaction) UnmarshalJSON(input []byte) error { func (tx *Transaction) UnmarshalJSON(input []byte) error {
var dec txJSON var dec txJSON
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {

View file

@ -314,7 +314,7 @@ func opBenchmark(bench *testing.B, op executionFunc, args ...string) {
for _, arg := range intArgs { for _, arg := range intArgs {
stack.push(arg) stack.push(arg)
} }
op(&pc, evmInterpreter, scope) _ , _ = op(&pc, evmInterpreter, scope)
stack.pop() stack.pop()
} }
bench.StopTimer() bench.StopTimer()
@ -610,14 +610,14 @@ func TestOpTstore(t *testing.T) {
stack.push(new(uint256.Int).SetBytes(value)) stack.push(new(uint256.Int).SetBytes(value))
// push the location to the stack // push the location to the stack
stack.push(new(uint256.Int)) stack.push(new(uint256.Int))
opTstore(&pc, evmInterpreter, &scopeContext) _ , _ = opTstore(&pc, evmInterpreter, &scopeContext)
// there should be no elements on the stack after TSTORE // there should be no elements on the stack after TSTORE
if stack.len() != 0 { if stack.len() != 0 {
t.Fatal("stack wrong size") t.Fatal("stack wrong size")
} }
// push the location to the stack // push the location to the stack
stack.push(new(uint256.Int)) stack.push(new(uint256.Int))
opTload(&pc, evmInterpreter, &scopeContext) _ , _ = opTload(&pc, evmInterpreter, &scopeContext)
// there should be one element on the stack after TLOAD // there should be one element on the stack after TLOAD
if stack.len() != 1 { if stack.len() != 1 {
t.Fatal("stack wrong size") t.Fatal("stack wrong size")

View file

@ -89,7 +89,7 @@ func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, err error) {
if err != nil { if err != nil {
errMsg = err.Error() errMsg = err.Error()
} }
l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), errMsg}) _ = l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), errMsg})
} }
func (l *JSONLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) { func (l *JSONLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {

View file

@ -191,6 +191,7 @@ func init() {
// Setup initializes profiling and logging based on the CLI flags. // Setup initializes profiling and logging based on the CLI flags.
// It should be called as early as possible in the program. // It should be called as early as possible in the program.
// nolint:nestif
func Setup(ctx *cli.Context) error { func Setup(ctx *cli.Context) error {
var ( var (
logfmt log.Format logfmt log.Format

View file

@ -471,8 +471,9 @@ func (mr mapResolver) LookupTXT(ctx context.Context, name string) ([]string, err
return nil, errors.New("not found") return nil, errors.New("not found")
} }
// nolint:prealloc
func parseNodes(rec []string) []*enode.Node { func parseNodes(rec []string) []*enode.Node {
ns := make([]*enode.Node, len(rec)) var ns []*enode.Node
for _, r := range rec { for _, r := range rec {
var n enode.Node var n enode.Node

View file

@ -770,6 +770,7 @@ func (c *cleaner) Delete(key []byte) error {
// Update inserts the dirty nodes in provided nodeset into database and // Update inserts the dirty nodes in provided nodeset into database and
// link the account trie with multiple storage tries if necessary. // link the account trie with multiple storage tries if necessary.
// nolint:prealloc
func (db *Database) Update(nodes *MergedNodeSet) error { func (db *Database) Update(nodes *MergedNodeSet) error {
db.lock.Lock() db.lock.Lock()
defer db.lock.Unlock() defer db.lock.Unlock()

View file

@ -154,11 +154,13 @@ func (set *NodeSet) Size() (int, int) {
// Hashes returns the hashes of all updated nodes. TODO(rjl493456442) how can // Hashes returns the hashes of all updated nodes. TODO(rjl493456442) how can
// we get rid of it? // we get rid of it?
// nolint:makezero
func (set *NodeSet) Hashes() []common.Hash { func (set *NodeSet) Hashes() []common.Hash {
var ret []common.Hash ret := make([]common.Hash, len(set.nodes))
for _, node := range set.nodes { for _, node := range set.nodes {
ret = append(ret, node.hash) ret = append(ret, node.hash)
} }
return ret return ret
} }

View file

@ -422,6 +422,7 @@ func (s *Sync) scheduleCodeRequest(req *codeRequest) {
// children retrieves all the missing children of a state trie entry for future // children retrieves all the missing children of a state trie entry for future
// retrieval scheduling. // retrieval scheduling.
// nolint:gocognit
func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) { func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
// Gather all the children of the node, irrelevant whether known or not // Gather all the children of the node, irrelevant whether known or not
type childNode struct { type childNode struct {

View file

@ -124,6 +124,7 @@ func TestIterativeSyncBatched(t *testing.T) { testIterativeSync(t, 100,
func TestIterativeSyncIndividualByPath(t *testing.T) { testIterativeSync(t, 1, true) } func TestIterativeSyncIndividualByPath(t *testing.T) { testIterativeSync(t, 1, true) }
func TestIterativeSyncBatchedByPath(t *testing.T) { testIterativeSync(t, 100, true) } func TestIterativeSyncBatchedByPath(t *testing.T) { testIterativeSync(t, 100, true) }
// nolint:prealloc
func testIterativeSync(t *testing.T, count int, bypath bool) { func testIterativeSync(t *testing.T, count int, bypath bool) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()
@ -195,6 +196,7 @@ func testIterativeSync(t *testing.T, count int, bypath bool) {
// Tests that the trie scheduler can correctly reconstruct the state even if only // Tests that the trie scheduler can correctly reconstruct the state even if only
// partial results are returned, and the others sent only later. // partial results are returned, and the others sent only later.
// nolint:prealloc
func TestIterativeDelayedSync(t *testing.T) { func TestIterativeDelayedSync(t *testing.T) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()
@ -384,12 +386,12 @@ func TestIterativeRandomDelayedSync(t *testing.T) {
} }
} }
} }
// Cross check that the two tries are in sync // Cross-check that the two tries are in sync
checkTrieContents(t, triedb, srcTrie.Hash().Bytes(), srcData) checkTrieContents(t, triedb, srcTrie.Hash().Bytes(), srcData)
} }
// Tests that a trie sync will not request nodes multiple times, even if they // Tests that a trie sync will not request nodes multiple times, even if they have such references.
// have such references. // nolint:prealloc
func TestDuplicateAvoidanceSync(t *testing.T) { func TestDuplicateAvoidanceSync(t *testing.T) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()
@ -456,8 +458,8 @@ func TestDuplicateAvoidanceSync(t *testing.T) {
checkTrieContents(t, triedb, srcTrie.Hash().Bytes(), srcData) checkTrieContents(t, triedb, srcTrie.Hash().Bytes(), srcData)
} }
// Tests that at any point in time during a sync, only complete sub-tries are in // Tests that at any point in time during a sync, only complete sub-tries are in the database.
// the database. // nolint:prealloc
func TestIncompleteSync(t *testing.T) { func TestIncompleteSync(t *testing.T) {
t.Parallel() t.Parallel()
// Create a random trie to copy // Create a random trie to copy
@ -543,8 +545,8 @@ func TestIncompleteSync(t *testing.T) {
} }
} }
// Tests that trie nodes get scheduled lexicographically when having the same // Tests that trie nodes get scheduled lexicographically when having the same depth.
// depth. // nolint:prealloc
func TestSyncOrdering(t *testing.T) { func TestSyncOrdering(t *testing.T) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()

View file

@ -179,6 +179,7 @@ func testAccessList(t *testing.T, vals []struct{ k, v string }) {
// Add more new nodes // Add more new nodes
trie, _ = New(TrieID(root), db) trie, _ = New(TrieID(root), db)
orig = trie.Copy() orig = trie.Copy()
// nolint:prealloc
var keys []string var keys []string
for i := 0; i < 30; i++ { for i := 0; i < 30; i++ {

View file

@ -470,6 +470,7 @@ func verifyAccessList(oldTrie *Trie, newTrie *Trie, set *NodeSet) error {
return nil return nil
} }
// nolint:gocognit
func runRandTest(rt randTest) bool { func runRandTest(rt randTest) bool {
var ( var (
triedb = NewDatabase(rawdb.NewMemoryDatabase()) triedb = NewDatabase(rawdb.NewMemoryDatabase())