mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
dev: fix: more errcheck lint issues
This commit is contained in:
parent
6223765aab
commit
82f33b22f5
26 changed files with 54 additions and 30 deletions
|
|
@ -49,7 +49,7 @@ linters:
|
|||
- tparallel
|
||||
- unconvert
|
||||
- unparam
|
||||
- wsl
|
||||
# - wsl
|
||||
- asasalint
|
||||
#- errorlint causes stack overflow. TODO: recheck after each golangci update
|
||||
|
||||
|
|
|
|||
|
|
@ -91,11 +91,11 @@ func TestCalcDifficulty(t *testing.T) {
|
|||
|
||||
func randSlice(min, max uint32) []byte {
|
||||
var b = make([]byte, 4)
|
||||
crand.Read(b)
|
||||
_ , _ = crand.Read(b)
|
||||
a := binary.LittleEndian.Uint32(b)
|
||||
size := min + a%(max-min)
|
||||
out := make([]byte, size)
|
||||
crand.Read(out)
|
||||
_ , _ = crand.Read(out)
|
||||
return out
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ func (f *chainFreezer) Close() error {
|
|||
//
|
||||
// This functionality is deliberately broken off from block importing to avoid
|
||||
// incurring additional data shuffling delays on block propagation.
|
||||
// nolint:gocognit
|
||||
func (f *chainFreezer) freeze(db ethdb.KeyValueStore) {
|
||||
var (
|
||||
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) {
|
||||
hashes = make([]common.Hash, 0, limit-number)
|
||||
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@ func resolveChainFreezerDir(ancient string) string {
|
|||
// value data store with a freezer moving immutable chain segments into cold
|
||||
// storage. The passed ancient indicates the path of root ancient directory
|
||||
// where the chain freezer can be opened.
|
||||
// nolint:gocognit
|
||||
func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace string, readonly bool) (ethdb.Database, error) {
|
||||
// Create the idle freezer instance
|
||||
frdb, err := newChainFreezer(resolveChainFreezerDir(ancient), namespace, readonly)
|
||||
|
|
|
|||
|
|
@ -409,6 +409,7 @@ type convertLegacyFn = func([]byte) ([]byte, error)
|
|||
|
||||
// MigrateTable processes the entries in a given table in sequence
|
||||
// converting them to a new format if they're of an old format.
|
||||
// nolint:gocognit
|
||||
func (f *Freezer) MigrateTable(kind string, convert convertLegacyFn) error {
|
||||
if f.readonly {
|
||||
return errReadOnly
|
||||
|
|
|
|||
|
|
@ -555,13 +555,13 @@ func (t *freezerTable) Close() error {
|
|||
defer t.lock.Unlock()
|
||||
|
||||
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 err := f.Sync(); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
if close {
|
||||
if closed {
|
||||
if err := f.Close(); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func TestNodeIteratorCoverage(t *testing.T) {
|
|||
|
||||
// isTrieNode is a helper function which reports if the provided
|
||||
// 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 len(key) == common.HashLength {
|
||||
return true, common.BytesToHash(key)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// specified state version. If user doesn't specify the state version, use
|
||||
// the bottom-most snapshot diff layer as the target.
|
||||
// nolint:nestif
|
||||
func (p *Pruner) Prune(root common.Hash) error {
|
||||
// If the state bloom filter is already committed previously,
|
||||
// reuse it for pruning instead of generating a new one. It's
|
||||
|
|
|
|||
|
|
@ -244,6 +244,7 @@ func runReport(stats *generateStats, stop chan bool) {
|
|||
// generateTrieRoot generates the trie hash based on the snapshot iterator.
|
||||
// It can be used for generating account trie, storage trie or even the
|
||||
// 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) {
|
||||
var (
|
||||
in = make(chan trieKV) // chan to pass leaves
|
||||
|
|
|
|||
|
|
@ -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 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) {
|
||||
var (
|
||||
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
|
||||
// either verify the correctness of existing state through range-proof and skip
|
||||
// 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) {
|
||||
// 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)
|
||||
|
|
@ -573,6 +575,7 @@ func generateStorages(ctx *generatorContext, dl *diskLayer, stateRoot common.Has
|
|||
// generateAccounts generates the missing snapshot accounts as well as their
|
||||
// storage slots in the main trie. It's supposed to restart the generation
|
||||
// from the given origin position.
|
||||
// nolint:nestif,gocognit
|
||||
func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) error {
|
||||
onAccount := func(key []byte, val []byte, write bool, delete bool) error {
|
||||
// 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
|
||||
// verify or regenerate the contract storage.
|
||||
if acc.Root == types.EmptyRootHash {
|
||||
ctx.removeStorageAt(account)
|
||||
_ = ctx.removeStorageAt(account)
|
||||
} else {
|
||||
var storeMarker []byte
|
||||
if accMarker != nil && bytes.Equal(account[:], accMarker) && len(dl.genMarker) > common.HashLength {
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ func (t *testHelper) makeStorageTrie(stateRoot, owner common.Hash, keys []string
|
|||
root, nodes := stTrie.Commit(false)
|
||||
|
||||
if nodes != nil {
|
||||
t.nodes.Merge(nodes)
|
||||
_ = t.nodes.Merge(nodes)
|
||||
}
|
||||
return root.Bytes()
|
||||
}
|
||||
|
|
@ -208,10 +208,10 @@ func (t *testHelper) makeStorageTrie(stateRoot, owner common.Hash, keys []string
|
|||
func (t *testHelper) Commit() common.Hash {
|
||||
root, nodes := t.accTrie.Commit(true)
|
||||
if nodes != nil {
|
||||
t.nodes.Merge(nodes)
|
||||
_ = t.nodes.Merge(nodes)
|
||||
}
|
||||
t.triedb.Update(t.nodes)
|
||||
t.triedb.Commit(root, false)
|
||||
_ = t.triedb.Update(t.nodes)
|
||||
_ = t.triedb.Commit(root, false)
|
||||
|
||||
return root
|
||||
}
|
||||
|
|
@ -400,8 +400,8 @@ func TestGenerateCorruptAccountTrie(t *testing.T) {
|
|||
root := helper.Commit() // Root: 0xa04693ea110a31037fb5ee814308a6f1d76bdab0b11676bdf4541d2de55ba978
|
||||
|
||||
// Delete an account trie leaf and ensure the generator chokes
|
||||
helper.triedb.Commit(root, false)
|
||||
helper.diskdb.Delete(common.HexToHash("0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7").Bytes())
|
||||
_ = helper.triedb.Commit(root, false)
|
||||
_ = helper.diskdb.Delete(common.HexToHash("0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7").Bytes())
|
||||
|
||||
snap := generateSnapshot(helper.diskdb, helper.triedb, 16, root)
|
||||
select {
|
||||
|
|
@ -436,7 +436,7 @@ func TestGenerateMissingStorageTrie(t *testing.T) {
|
|||
root := helper.Commit()
|
||||
|
||||
// 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)
|
||||
select {
|
||||
|
|
@ -470,7 +470,7 @@ func TestGenerateCorruptStorageTrie(t *testing.T) {
|
|||
root := helper.Commit()
|
||||
|
||||
// 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)
|
||||
select {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func TestAccountIteratorBasics(t *testing.T) {
|
|||
if rand.Intn(2) == 0 {
|
||||
accStorage := make(map[common.Hash][]byte)
|
||||
value := make([]byte, 32)
|
||||
crand.Read(value)
|
||||
_ , _ = crand.Read(value)
|
||||
accStorage[randomHash()] = value
|
||||
storage[h] = accStorage
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ func TestStorageIteratorBasics(t *testing.T) {
|
|||
|
||||
var nilstorage int
|
||||
for i := 0; i < 100; i++ {
|
||||
crand.Read(value)
|
||||
_ , _ = crand.Read(value)
|
||||
if rand.Intn(2) == 0 {
|
||||
accStorage[randomHash()] = common.CopyBytes(value)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -281,6 +281,7 @@ type journalCallback = func(parent common.Hash, root common.Hash, destructs map[
|
|||
// the most recent layer.
|
||||
// This method returns error either if there was some error reading from disk,
|
||||
// OR if the callback returns an error when invoked.
|
||||
// nolint:gocognit
|
||||
func iterateJournal(db ethdb.KeyValueReader, callback journalCallback) error {
|
||||
journal := rawdb.ReadSnapshotJournal(db)
|
||||
if len(journal) == 0 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
var onSlot func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error
|
||||
if onLeaf != nil {
|
||||
// nolint:unparam
|
||||
onSlot = func(keys [][]byte, path []byte, leaf []byte, parent common.Hash, parentPath []byte) error {
|
||||
return onLeaf(keys, leaf)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@ type stateElement struct {
|
|||
syncPath trie.SyncPath
|
||||
}
|
||||
|
||||
// nolint:nestif
|
||||
func testIterativeStateSync(t *testing.T, count int, commit bool, bypath bool) {
|
||||
// Create a random state to copy
|
||||
_, 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
|
||||
// partial results are returned, and the others sent only later.
|
||||
// nolint:prealloc
|
||||
func TestIterativeDelayedStateSync(t *testing.T) {
|
||||
// Create a random state to copy
|
||||
_, srcDb, srcRoot, srcAccounts := makeTestState()
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
|
|||
}
|
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
// nolint:gocognit
|
||||
func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||
var dec txJSON
|
||||
if err := json.Unmarshal(input, &dec); err != nil {
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ func opBenchmark(bench *testing.B, op executionFunc, args ...string) {
|
|||
for _, arg := range intArgs {
|
||||
stack.push(arg)
|
||||
}
|
||||
op(&pc, evmInterpreter, scope)
|
||||
_ , _ = op(&pc, evmInterpreter, scope)
|
||||
stack.pop()
|
||||
}
|
||||
bench.StopTimer()
|
||||
|
|
@ -610,14 +610,14 @@ func TestOpTstore(t *testing.T) {
|
|||
stack.push(new(uint256.Int).SetBytes(value))
|
||||
// push the location to the stack
|
||||
stack.push(new(uint256.Int))
|
||||
opTstore(&pc, evmInterpreter, &scopeContext)
|
||||
_ , _ = opTstore(&pc, evmInterpreter, &scopeContext)
|
||||
// there should be no elements on the stack after TSTORE
|
||||
if stack.len() != 0 {
|
||||
t.Fatal("stack wrong size")
|
||||
}
|
||||
// push the location to the stack
|
||||
stack.push(new(uint256.Int))
|
||||
opTload(&pc, evmInterpreter, &scopeContext)
|
||||
_ , _ = opTload(&pc, evmInterpreter, &scopeContext)
|
||||
// there should be one element on the stack after TLOAD
|
||||
if stack.len() != 1 {
|
||||
t.Fatal("stack wrong size")
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, err error) {
|
|||
if err != nil {
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -191,6 +191,7 @@ func init() {
|
|||
|
||||
// Setup initializes profiling and logging based on the CLI flags.
|
||||
// It should be called as early as possible in the program.
|
||||
// nolint:nestif
|
||||
func Setup(ctx *cli.Context) error {
|
||||
var (
|
||||
logfmt log.Format
|
||||
|
|
|
|||
|
|
@ -471,8 +471,9 @@ func (mr mapResolver) LookupTXT(ctx context.Context, name string) ([]string, err
|
|||
return nil, errors.New("not found")
|
||||
}
|
||||
|
||||
// nolint:prealloc
|
||||
func parseNodes(rec []string) []*enode.Node {
|
||||
ns := make([]*enode.Node, len(rec))
|
||||
var ns []*enode.Node
|
||||
|
||||
for _, r := range rec {
|
||||
var n enode.Node
|
||||
|
|
|
|||
|
|
@ -770,6 +770,7 @@ func (c *cleaner) Delete(key []byte) error {
|
|||
|
||||
// Update inserts the dirty nodes in provided nodeset into database and
|
||||
// link the account trie with multiple storage tries if necessary.
|
||||
// nolint:prealloc
|
||||
func (db *Database) Update(nodes *MergedNodeSet) error {
|
||||
db.lock.Lock()
|
||||
defer db.lock.Unlock()
|
||||
|
|
|
|||
|
|
@ -154,11 +154,13 @@ func (set *NodeSet) Size() (int, int) {
|
|||
|
||||
// Hashes returns the hashes of all updated nodes. TODO(rjl493456442) how can
|
||||
// we get rid of it?
|
||||
// nolint:makezero
|
||||
func (set *NodeSet) Hashes() []common.Hash {
|
||||
var ret []common.Hash
|
||||
ret := make([]common.Hash, len(set.nodes))
|
||||
for _, node := range set.nodes {
|
||||
ret = append(ret, node.hash)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -422,6 +422,7 @@ func (s *Sync) scheduleCodeRequest(req *codeRequest) {
|
|||
|
||||
// children retrieves all the missing children of a state trie entry for future
|
||||
// retrieval scheduling.
|
||||
// nolint:gocognit
|
||||
func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
|
||||
// Gather all the children of the node, irrelevant whether known or not
|
||||
type childNode struct {
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ func TestIterativeSyncBatched(t *testing.T) { testIterativeSync(t, 100,
|
|||
func TestIterativeSyncIndividualByPath(t *testing.T) { testIterativeSync(t, 1, true) }
|
||||
func TestIterativeSyncBatchedByPath(t *testing.T) { testIterativeSync(t, 100, true) }
|
||||
|
||||
// nolint:prealloc
|
||||
func testIterativeSync(t *testing.T, count int, bypath bool) {
|
||||
// Create a random trie to copy
|
||||
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
|
||||
// partial results are returned, and the others sent only later.
|
||||
// nolint:prealloc
|
||||
func TestIterativeDelayedSync(t *testing.T) {
|
||||
// Create a random trie to copy
|
||||
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)
|
||||
}
|
||||
|
||||
// Tests that a trie sync will not request nodes multiple times, even if they
|
||||
// have such references.
|
||||
// Tests that a trie sync will not request nodes multiple times, even if they have such references.
|
||||
// nolint:prealloc
|
||||
func TestDuplicateAvoidanceSync(t *testing.T) {
|
||||
// Create a random trie to copy
|
||||
srcDb, srcTrie, srcData := makeTestTrie()
|
||||
|
|
@ -456,8 +458,8 @@ func TestDuplicateAvoidanceSync(t *testing.T) {
|
|||
checkTrieContents(t, triedb, srcTrie.Hash().Bytes(), srcData)
|
||||
}
|
||||
|
||||
// Tests that at any point in time during a sync, only complete sub-tries are in
|
||||
// the database.
|
||||
// Tests that at any point in time during a sync, only complete sub-tries are in the database.
|
||||
// nolint:prealloc
|
||||
func TestIncompleteSync(t *testing.T) {
|
||||
t.Parallel()
|
||||
// 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
|
||||
// depth.
|
||||
// Tests that trie nodes get scheduled lexicographically when having the same depth.
|
||||
// nolint:prealloc
|
||||
func TestSyncOrdering(t *testing.T) {
|
||||
// Create a random trie to copy
|
||||
srcDb, srcTrie, srcData := makeTestTrie()
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ func testAccessList(t *testing.T, vals []struct{ k, v string }) {
|
|||
// Add more new nodes
|
||||
trie, _ = New(TrieID(root), db)
|
||||
orig = trie.Copy()
|
||||
// nolint:prealloc
|
||||
var keys []string
|
||||
|
||||
for i := 0; i < 30; i++ {
|
||||
|
|
|
|||
|
|
@ -470,6 +470,7 @@ func verifyAccessList(oldTrie *Trie, newTrie *Trie, set *NodeSet) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// nolint:gocognit
|
||||
func runRandTest(rt randTest) bool {
|
||||
var (
|
||||
triedb = NewDatabase(rawdb.NewMemoryDatabase())
|
||||
|
|
|
|||
Loading…
Reference in a new issue