diff --git a/.golangci.yml b/.golangci.yml index e9ae98b41..e32d7f45c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,22 +2,35 @@ run: deadline: 10m linters: - disable-all: true + presets: + - bugs + - error + - unused + - performance + disable: + - exhaustive + - musttag + - contextcheck + - wrapcheck + - goerr113 + - unparam + - makezero #TODO: enable me + - noctx #TODO: enable me + - nilerr #TODO: enable me + - errorlint #TODO: enable me + - errchkjson #TODO: enable me + - unused #TODO: enable me + - gocheckcompilerdirectives enable: - - gofmt - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck -# - structcheck # 1.18 -# - unused # 1.18 - - gocritic - - bodyclose - - gosec -# - forcetypeassert - - prealloc - unconvert + # - predeclared #TODO: enable me + # - thelper #TODO: enable me + # - wastedassign + - gofmt + - gocritic +# - revive +# - forcetypeassert +# - stylecheck linters-settings: gocritic: diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 69a8238f4..632a37479 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -49,7 +49,6 @@ import ( "github.com/ledgerwatch/erigon/ethdb/olddb" "github.com/ledgerwatch/erigon/event" "github.com/ledgerwatch/erigon/params" - "github.com/ledgerwatch/erigon/rpc" "github.com/ledgerwatch/erigon/turbo/snapshotsync" "github.com/ledgerwatch/erigon/turbo/stages" ) @@ -570,9 +569,9 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs // Determine the lowest and highest possible gas limits to binary search in between var ( - lo = params.TxGas - 1 - hi uint64 - cap uint64 + lo = params.TxGas - 1 + hi uint64 + gasCap uint64 ) if call.Gas >= params.TxGas { hi = call.Gas @@ -600,7 +599,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs hi = allowance.Uint64() } } - cap = hi + gasCap = hi b.pendingState.Prepare(libcommon.Hash{}, libcommon.Hash{}, len(b.pendingBlock.Transactions())) // Create a helper to check if a gas allowance results in an executable transaction @@ -637,7 +636,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs } } // Reject the transaction as invalid if it still fails at the highest allowance - if hi == cap { + if hi == gasCap { failed, result, err := executable(hi) if err != nil { return 0, err @@ -650,7 +649,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs return 0, result.Err } // Otherwise, the specified gas cap is too low - return 0, fmt.Errorf("gas required exceeds allowance (%d)", cap) + return 0, fmt.Errorf("gas required exceeds allowance (%d)", gasCap) } } return hi, nil @@ -799,6 +798,7 @@ func (m callMsg) Data() []byte { return m.CallMsg.Data } func (m callMsg) AccessList() types2.AccessList { return m.CallMsg.AccessList } func (m callMsg) IsFree() bool { return false } +/* // filterBackend implements filters.Backend to support filtering for logs without // taking bloom-bits acceleration structures into account. type filterBackend struct { @@ -895,3 +895,4 @@ func nullSubscription() event.Subscription { return nil }) } +*/ diff --git a/accounts/abi/pack.go b/accounts/abi/pack.go index 08d40611a..2f0fe3f45 100644 --- a/accounts/abi/pack.go +++ b/accounts/abi/pack.go @@ -30,8 +30,8 @@ import ( // packBytesSlice packs the given bytes as [L, V] as the canonical representation // bytes slice. func packBytesSlice(bytes []byte, l int) []byte { - len := packNum(reflect.ValueOf(l)) - return append(len, common.RightPadBytes(bytes, (l+31)/32*32)...) + packedLen := packNum(reflect.ValueOf(l)) + return append(packedLen, common.RightPadBytes(bytes, (l+31)/32*32)...) } // packElement packs the given reflect value according to the abi specification in diff --git a/accounts/abi/unpack_test.go b/accounts/abi/unpack_test.go index 313fe4636..880fb5893 100644 --- a/accounts/abi/unpack_test.go +++ b/accounts/abi/unpack_test.go @@ -327,8 +327,8 @@ func TestMethodMultiReturn(t *testing.T) { Int *big.Int } - newInterfaceSlice := func(len int) interface{} { - slice := make([]interface{}, len) + newInterfaceSlice := func(l int) interface{} { + slice := make([]interface{}, l) return &slice } diff --git a/cmd/erigon-cl/core/rawdb/accessors_test.go b/cmd/erigon-cl/core/rawdb/accessors_test.go index f044f8fc9..50619bf5f 100644 --- a/cmd/erigon-cl/core/rawdb/accessors_test.go +++ b/cmd/erigon-cl/core/rawdb/accessors_test.go @@ -10,9 +10,9 @@ import ( ) func TestBytes2(t *testing.T) { - len := 1000 - buf := rawdb.Bytes2FromLength(len) - require.Equal(t, len, rawdb.LengthFromBytes2(buf)) + l := 1000 + buf := rawdb.Bytes2FromLength(l) + require.Equal(t, l, rawdb.LengthFromBytes2(buf)) } var emptyBlock = &cltypes.Eth1Block{} diff --git a/cmd/rpcdaemon/commands/eth_call.go b/cmd/rpcdaemon/commands/eth_call.go index 74a0fdf3c..60413bc91 100644 --- a/cmd/rpcdaemon/commands/eth_call.go +++ b/cmd/rpcdaemon/commands/eth_call.go @@ -127,9 +127,9 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs // Binary search the gas requirement, as it may be higher than the amount used var ( - lo = params.TxGas - 1 - hi uint64 - cap uint64 + lo = params.TxGas - 1 + hi uint64 + gasCap uint64 ) // Use zero address if sender unspecified. if args.From == nil { @@ -217,7 +217,7 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs log.Warn("Caller gas above allowance, capping", "requested", hi, "cap", api.GasCap) hi = api.GasCap } - cap = hi + gasCap = hi chainConfig, err := api.chainConfig(dbtx) if err != nil { @@ -286,7 +286,7 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs } // Reject the transaction as invalid if it still fails at the highest allowance - if hi == cap { + if hi == gasCap { failed, result, err := executable(hi) if err != nil { return 0, err @@ -299,7 +299,7 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs return 0, result.Err } // Otherwise, the specified gas cap is too low - return 0, fmt.Errorf("gas required exceeds allowance (%d)", cap) + return 0, fmt.Errorf("gas required exceeds allowance (%d)", gasCap) } } return hexutil.Uint64(hi), nil diff --git a/cmd/rpcdaemon/commands/eth_receipts.go b/cmd/rpcdaemon/commands/eth_receipts.go index c13b29434..ee53925ea 100644 --- a/cmd/rpcdaemon/commands/eth_receipts.go +++ b/cmd/rpcdaemon/commands/eth_receipts.go @@ -765,44 +765,6 @@ func marshalReceipt(receipt *types.Receipt, txn types.Transaction, chainConfig * return fields } -func includes(addresses []common.Address, a common.Address) bool { - for _, addr := range addresses { - if addr == a { - return true - } - } - return false -} - -// filterLogs creates a slice of logs matching the given criteria. -func filterLogsOld(logs []*types.Log, addresses []common.Address, topics [][]common.Hash) []*types.Log { - result := make(types.Logs, 0, len(logs)) -Logs: - for _, log := range logs { - if len(addresses) > 0 && !includes(addresses, log.Address) { - continue - } - // If the to filtered topics is greater than the amount of topics in logs, skip. - if len(topics) > len(log.Topics) { - continue Logs - } - for i, sub := range topics { - match := len(sub) == 0 // empty rule set == wildcard - for _, topic := range sub { - if log.Topics[i] == topic { - match = true - break - } - } - if !match { - continue Logs - } - } - result = append(result, log) - } - return result -} - // MapTxNum2BlockNumIter - enrich iterator by TxNumbers, adding more info: // - blockNum // - txIndex in block: -1 means first system tx diff --git a/cmd/rpcdaemon/commands/send_transaction.go b/cmd/rpcdaemon/commands/send_transaction.go index bd274d192..0efae23c8 100644 --- a/cmd/rpcdaemon/commands/send_transaction.go +++ b/cmd/rpcdaemon/commands/send_transaction.go @@ -91,15 +91,15 @@ func (api *APIImpl) SendTransaction(_ context.Context, txObject interface{}) (co // checkTxFee is an internal function used to check whether the fee of // the given transaction is _reasonable_(under the cap). -func checkTxFee(gasPrice *big.Int, gas uint64, cap float64) error { - // Short circuit if there is no cap for transaction fee at all. - if cap == 0 { +func checkTxFee(gasPrice *big.Int, gas uint64, gasCap float64) error { + // Short circuit if there is no gasCap for transaction fee at all. + if gasCap == 0 { return nil } feeEth := new(big.Float).Quo(new(big.Float).SetInt(new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(gas))), new(big.Float).SetInt(big.NewInt(params.Ether))) feeFloat, _ := feeEth.Float64() - if feeFloat > cap { - return fmt.Errorf("tx fee (%.2f ether) exceeds the configured cap (%.2f ether)", feeFloat, cap) + if feeFloat > gasCap { + return fmt.Errorf("tx fee (%.2f ether) exceeds the configured cap (%.2f ether)", feeFloat, gasCap) } return nil } diff --git a/cmd/state/exec3/state_recon.go b/cmd/state/exec3/state_recon.go index 9e9abe54d..63baf5296 100644 --- a/cmd/state/exec3/state_recon.go +++ b/cmd/state/exec3/state_recon.go @@ -30,11 +30,10 @@ import ( ) type ScanWorker struct { - txNum uint64 - as *libstate.AggregatorStep - fromKey, toKey []byte - currentKey []byte - bitmap roaring64.Bitmap + txNum uint64 + as *libstate.AggregatorStep + toKey []byte + bitmap roaring64.Bitmap } func NewScanWorker(txNum uint64, as *libstate.AggregatorStep) *ScanWorker { diff --git a/cmd/verkle/verkletrie/verkle_tree_writer.go b/cmd/verkle/verkletrie/verkle_tree_writer.go index 78504a582..52731cede 100644 --- a/cmd/verkle/verkletrie/verkle_tree_writer.go +++ b/cmd/verkle/verkletrie/verkle_tree_writer.go @@ -19,10 +19,6 @@ import ( "github.com/ledgerwatch/erigon/turbo/trie/vtree" ) -func identityFuncForVerkleTree(k []byte, value []byte, _ etl.CurrentTableReader, next etl.LoadNextFunc) error { - return next(k, k, value) -} - func int256ToVerkleFormat(x *uint256.Int, buffer []byte) { bbytes := x.ToBig().Bytes() if len(bbytes) > 0 { diff --git a/common/math/big_test.go b/common/math/big_test.go index b9a418d6c..c01863024 100644 --- a/common/math/big_test.go +++ b/common/math/big_test.go @@ -181,9 +181,9 @@ func BenchmarkByteAtOld(b *testing.B) { func TestReadBits(t *testing.T) { check := func(input string) { want, _ := hex.DecodeString(input) - int, _ := new(big.Int).SetString(input, 16) + in, _ := new(big.Int).SetString(input, 16) buf := make([]byte, len(want)) - ReadBits(int, buf) + ReadBits(in, buf) if !bytes.Equal(buf, want) { t.Errorf("have: %x\nwant: %x", buf, want) } diff --git a/common/math/integer.go b/common/math/integer.go index 5b306de42..63f368003 100644 --- a/common/math/integer.go +++ b/common/math/integer.go @@ -45,11 +45,11 @@ type HexOrDecimal64 uint64 // UnmarshalText implements encoding.TextUnmarshaler. func (i *HexOrDecimal64) UnmarshalText(input []byte) error { - int, ok := ParseUint64(string(input)) + in, ok := ParseUint64(string(input)) if !ok { return fmt.Errorf("invalid hex or decimal integer %q", input) } - *i = HexOrDecimal64(int) + *i = HexOrDecimal64(in) return nil } diff --git a/consensus/clique/snapshot.go b/consensus/clique/snapshot.go index e9b7fddb5..5ffea2ad1 100644 --- a/consensus/clique/snapshot.go +++ b/consensus/clique/snapshot.go @@ -124,7 +124,7 @@ func lastSnapshot(db kv.RwDB) (uint64, error) { lastEnc, err := tx.GetOne(kv.CliqueLastSnapshot, LastSnapshotKey()) if err != nil { - return 0, fmt.Errorf("failed check last clique snapshot: %d", err) + return 0, fmt.Errorf("failed check last clique snapshot: %w", err) } if len(lastEnc) == 0 { return 0, ErrNotFound diff --git a/core/asm/lexer.go b/core/asm/lexer.go index f025b4981..4f62cd5cc 100644 --- a/core/asm/lexer.go +++ b/core/asm/lexer.go @@ -116,14 +116,14 @@ func Lex(source []byte, debug bool) <-chan token { } // next returns the next rune in the program's source. -func (l *lexer) next() (rune rune) { +func (l *lexer) next() (runeVal rune) { if l.pos >= len(l.input) { l.width = 0 return 0 } - rune, l.width = utf8.DecodeRuneInString(l.input[l.pos:]) + runeVal, l.width = utf8.DecodeRuneInString(l.input[l.pos:]) l.pos += l.width - return rune + return runeVal } // backup backsup the last parsed element (multi-character) diff --git a/core/state/intra_block_state.go b/core/state/intra_block_state.go index ff8028ca5..e916c4f17 100644 --- a/core/state/intra_block_state.go +++ b/core/state/intra_block_state.go @@ -235,11 +235,11 @@ func (sdb *IntraBlockState) GetCodeSize(addr libcommon.Address) int { if stateObject.code != nil { return len(stateObject.code) } - len, err := sdb.stateReader.ReadAccountCodeSize(addr, stateObject.data.Incarnation, stateObject.data.CodeHash) + l, err := sdb.stateReader.ReadAccountCodeSize(addr, stateObject.data.Incarnation, stateObject.data.CodeHash) if err != nil { sdb.setErrorUnsafe(err) } - return len + return l } // DESCRIBED: docs/programmers_guide/guide.md#address---identifier-of-an-account diff --git a/core/state/recon_writer_inc.go b/core/state/recon_writer_inc.go index 17cbf01e9..05862023d 100644 --- a/core/state/recon_writer_inc.go +++ b/core/state/recon_writer_inc.go @@ -14,12 +14,11 @@ import ( ) type StateReconWriterInc struct { - as *libstate.AggregatorStep - rs *ReconState - txNum uint64 - tx kv.Tx - chainTx kv.Tx - composite []byte + as *libstate.AggregatorStep + rs *ReconState + txNum uint64 + tx kv.Tx + chainTx kv.Tx } func NewStateReconWriterInc(as *libstate.AggregatorStep, rs *ReconState) *StateReconWriterInc { diff --git a/core/state/temporal/kv_temporal.go b/core/state/temporal/kv_temporal.go index 8e5b4166c..51e8ce910 100644 --- a/core/state/temporal/kv_temporal.go +++ b/core/state/temporal/kv_temporal.go @@ -70,6 +70,7 @@ func New(db kv.RwDB, agg *state.AggregatorV3, cb1 tConvertV3toV2, cb2 tRestoreCo return &DB{RwDB: db, agg: agg, convertV3toV2: cb1, restoreCodeHash: cb2, parseInc: cb3, systemContractLookup: systemContractLookup}, nil } + func (db *DB) BeginTemporalRo(ctx context.Context) (kv.TemporalTx, error) { kvTx, err := db.RwDB.BeginRo(ctx) if err != nil { @@ -103,7 +104,7 @@ func (db *DB) View(ctx context.Context, f func(tx kv.Tx) error) error { } func (db *DB) BeginTemporalRw(ctx context.Context) (kv.RwTx, error) { - kvTx, err := db.RwDB.BeginRw(ctx) + kvTx, err := db.RwDB.BeginRw(ctx) //nolint:gocritic if err != nil { return nil, err } @@ -125,7 +126,7 @@ func (db *DB) Update(ctx context.Context, f func(tx kv.RwTx) error) error { } func (db *DB) BeginTemporalRwNosync(ctx context.Context) (kv.RwTx, error) { - kvTx, err := db.RwDB.BeginRwNosync(ctx) + kvTx, err := db.RwDB.BeginRwNosync(ctx) //nolint:gocritic if err != nil { return nil, err } @@ -135,7 +136,7 @@ func (db *DB) BeginTemporalRwNosync(ctx context.Context) (kv.RwTx, error) { return tx, nil } func (db *DB) BeginRwNosync(ctx context.Context) (kv.RwTx, error) { - return db.BeginTemporalRwNosync(ctx) + return db.BeginTemporalRwNosync(ctx) //nolint:gocritic } func (db *DB) UpdateNosync(ctx context.Context, f func(tx kv.RwTx) error) error { tx, err := db.BeginTemporalRwNosync(ctx) diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 0c5b065e9..7e011f713 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -93,7 +93,7 @@ var blake2FMalformedInputTests = []precompiledFailureTest{ }, } -func testPrecompiled(addr string, test precompiledTest, t *testing.T) { +func testPrecompiled(t *testing.T, addr string, test precompiledTest) { p := allPrecompiles[libcommon.HexToAddress(addr)] in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) @@ -114,7 +114,7 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) { }) } -func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) { +func testPrecompiledOOG(t *testing.T, addr string, test precompiledTest) { p := allPrecompiles[libcommon.HexToAddress(addr)] in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) - 1 @@ -149,7 +149,7 @@ func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing }) } -func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) { +func benchmarkPrecompiled(b *testing.B, addr string, test precompiledTest) { if test.NoBenchmark { return } @@ -163,7 +163,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) { data = make([]byte, len(in)) ) - bench.Run(fmt.Sprintf("%s-Gas=%d", test.Name, reqGas), func(bench *testing.B) { + b.Run(fmt.Sprintf("%s-Gas=%d", test.Name, reqGas), func(bench *testing.B) { bench.ReportAllocs() start := time.Now() bench.ResetTimer() @@ -200,7 +200,7 @@ func BenchmarkPrecompiledEcrecover(bench *testing.B) { Expected: "000000000000000000000000ceaccac640adf55b2028469bd36ba501f28b699d", Name: "", } - benchmarkPrecompiled("01", t, bench) + benchmarkPrecompiled(bench, "01", t) } // Benchmarks the sample inputs from the SHA256 precompile. @@ -210,27 +210,27 @@ func BenchmarkPrecompiledSha256(bench *testing.B) { Expected: "811c7003375852fabd0d362e40e68607a12bdabae61a7d068fe5fdd1dbbf2a5d", Name: "128", } - benchmarkPrecompiled("02", t, bench) + benchmarkPrecompiled(bench, "02", t) } // Benchmarks the sample inputs from the RIPEMD precompile. -func BenchmarkPrecompiledRipeMD(bench *testing.B) { +func BenchmarkPrecompiledRipeMD(b *testing.B) { t := precompiledTest{ Input: "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", Expected: "0000000000000000000000009215b8d9882ff46f0dfde6684d78e831467f65e6", Name: "128", } - benchmarkPrecompiled("03", t, bench) + benchmarkPrecompiled(b, "03", t) } // Benchmarks the sample inputs from the identiy precompile. -func BenchmarkPrecompiledIdentity(bench *testing.B) { +func BenchmarkPrecompiledIdentity(b *testing.B) { t := precompiledTest{ Input: "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", Expected: "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02", Name: "128", } - benchmarkPrecompiled("04", t, bench) + benchmarkPrecompiled(b, "04", t) } // Tests the sample inputs from the ModExp EIP 198. @@ -251,7 +251,7 @@ func TestPrecompiledModExpOOG(t *testing.T) { t.Fatal(err) } for _, test := range modexpTests { - testPrecompiledOOG("05", test, t) + testPrecompiledOOG(t, "05", test) } } @@ -280,7 +280,7 @@ func testJson(name, addr string, t *testing.T) { t.Fatal(err) } for _, test := range tests { - testPrecompiled(addr, test, t) + testPrecompiled(t, addr, test) } } @@ -300,7 +300,7 @@ func benchJson(name, addr string, b *testing.B) { b.Fatal(err) } for _, test := range tests { - benchmarkPrecompiled(addr, test, b) + benchmarkPrecompiled(b, addr, test) } } @@ -370,7 +370,7 @@ func BenchmarkPrecompiledBLS12381G1MultiExpWorstCase(b *testing.B) { Name: "WorstCaseG1", NoBenchmark: false, } - benchmarkPrecompiled("0c", testcase, b) + benchmarkPrecompiled(b, "0c", testcase) } // BenchmarkPrecompiledBLS12381G2MultiExpWorstCase benchmarks the worst case we could find that still fits a gaslimit of 10MGas. @@ -391,5 +391,5 @@ func BenchmarkPrecompiledBLS12381G2MultiExpWorstCase(b *testing.B) { Name: "WorstCaseG2", NoBenchmark: false, } - benchmarkPrecompiled("0f", testcase, b) + benchmarkPrecompiled(b, "0f", testcase) } diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index 3833fcbcf..49d11fe64 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -282,7 +282,7 @@ func TestJsonTestcases(t *testing.T) { } } -func opBenchmark(bench *testing.B, op executionFunc, args ...string) { +func opBenchmark(b *testing.B, op executionFunc, args ...string) { var ( env = NewEVM(evmtypes.BlockContext{}, evmtypes.TxContext{}, nil, params.TestChainConfig, Config{}) stack = stack.New() @@ -296,8 +296,8 @@ func opBenchmark(bench *testing.B, op executionFunc, args ...string) { byteArgs[i] = common.Hex2Bytes(arg) } pc := uint64(0) - bench.ResetTimer() - for i := 0; i < bench.N; i++ { + b.ResetTimer() + for i := 0; i < b.N; i++ { for _, arg := range byteArgs { a := new(uint256.Int) a.SetBytes(arg) diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go index 04a5f69ae..4ce703232 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/runtime/runtime_test.go @@ -169,8 +169,8 @@ func BenchmarkCall(b *testing.B) { } } } -func benchmarkEVM_Create(bench *testing.B, code string) { - _, tx := memdb.NewTestTx(bench) +func benchmarkEVM_Create(b *testing.B, code string) { + _, tx := memdb.NewTestTx(b) var ( statedb = state.New(state.NewPlainState(tx, 1, nil)) sender = libcommon.BytesToAddress([]byte("sender")) @@ -198,11 +198,11 @@ func benchmarkEVM_Create(bench *testing.B, code string) { EVMConfig: vm.Config{}, } // Warm up the intpools and stuff - bench.ResetTimer() - for i := 0; i < bench.N; i++ { + b.ResetTimer() + for i := 0; i < b.N; i++ { _, _, _ = Call(receiver, []byte{}, &runtimeConfig) } - bench.StopTimer() + b.StopTimer() } func BenchmarkEVM_CREATE_500(bench *testing.B) { diff --git a/eth/stagedsync/stage_call_traces.go b/eth/stagedsync/stage_call_traces.go index 15ddfd03e..fe5e620fa 100644 --- a/eth/stagedsync/stage_call_traces.go +++ b/eth/stagedsync/stage_call_traces.go @@ -325,12 +325,12 @@ func DoUnwindCallTraces(logPrefix string, db kv.RwTx, from, to uint64, ctx conte mapKey := v[:length.Addr] if v[length.Addr]&1 > 0 { if err = froms.Collect(mapKey, nil); err != nil { - return nil + return err } } if v[length.Addr]&2 > 0 { if err = tos.Collect(mapKey, nil); err != nil { - return nil + return err } } select { diff --git a/go.mod b/go.mod index 45ad0f4d8..3c6365397 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon go 1.19 require ( - github.com/ledgerwatch/erigon-lib v0.0.0-20230325033216-5ae3af617b53 + github.com/ledgerwatch/erigon-lib v0.0.0-20230325050315-9211cdcb327c github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 github.com/ledgerwatch/log/v3 v3.7.0 github.com/ledgerwatch/secp256k1 v1.0.0 diff --git a/go.sum b/go.sum index 5a6d0a1e6..f84315c56 100644 --- a/go.sum +++ b/go.sum @@ -519,8 +519,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/ledgerwatch/erigon-lib v0.0.0-20230325033216-5ae3af617b53 h1:FTIeWRzOoUqVMyJPKR91NJWG0THkfYAsss6SarUt7PI= -github.com/ledgerwatch/erigon-lib v0.0.0-20230325033216-5ae3af617b53/go.mod h1:CkP5qnLv68u1AAHHamS7TBgPmlPBn0aVcPrHi7njrIU= +github.com/ledgerwatch/erigon-lib v0.0.0-20230325050315-9211cdcb327c h1:i1QwW0t/sOmXY7UIeUpB6U7dB2iNC+ucgOR28CoyQrY= +github.com/ledgerwatch/erigon-lib v0.0.0-20230325050315-9211cdcb327c/go.mod h1:CkP5qnLv68u1AAHHamS7TBgPmlPBn0aVcPrHi7njrIU= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 h1:tfzawK1gIIgRjVZeANXOr0Ziu+kqCIBuKMe0TXfl5Aw= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og= diff --git a/p2p/discover/v5wire/encoding_test.go b/p2p/discover/v5wire/encoding_test.go index 55cb86af9..f49f789d3 100644 --- a/p2p/discover/v5wire/encoding_test.go +++ b/p2p/discover/v5wire/encoding_test.go @@ -536,13 +536,13 @@ func (n *handshakeTestNode) init(key *ecdsa.PrivateKey, ip net.IP, clock mclock. n.c = NewCodec(n.ln, key, clock) } -func (n *handshakeTestNode) encode(t testing.TB, to handshakeTestNode, p Packet) ([]byte, Nonce) { - t.Helper() - return n.encodeWithChallenge(t, to, nil, p) +func (n *handshakeTestNode) encode(tb testing.TB, to handshakeTestNode, p Packet) ([]byte, Nonce) { + tb.Helper() + return n.encodeWithChallenge(tb, to, nil, p) } -func (n *handshakeTestNode) encodeWithChallenge(t testing.TB, to handshakeTestNode, c *Whoareyou, p Packet) ([]byte, Nonce) { - t.Helper() +func (n *handshakeTestNode) encodeWithChallenge(tb testing.TB, to handshakeTestNode, c *Whoareyou, p Packet) ([]byte, Nonce) { + tb.Helper() // Copy challenge and add destination node. This avoids sharing 'c' among the two codecs. var challenge *Whoareyou @@ -554,9 +554,9 @@ func (n *handshakeTestNode) encodeWithChallenge(t testing.TB, to handshakeTestNo // Encode to destination. enc, nonce, err := n.c.Encode(to.id(), to.addr(), p, challenge) if err != nil { - t.Fatal(fmt.Errorf("(%s) %w", n.ln.ID().TerminalString(), err)) + tb.Fatal(fmt.Errorf("(%s) %w", n.ln.ID().TerminalString(), err)) } - t.Logf("(%s) -> (%s) %s\n%s", n.ln.ID().TerminalString(), to.id().TerminalString(), p.Name(), hex.Dump(enc)) + tb.Logf("(%s) -> (%s) %s\n%s", n.ln.ID().TerminalString(), to.id().TerminalString(), p.Name(), hex.Dump(enc)) return enc, nonce } diff --git a/p2p/enode/iter_test.go b/p2p/enode/iter_test.go index 27cb41dc8..83eaa8da1 100644 --- a/p2p/enode/iter_test.go +++ b/p2p/enode/iter_test.go @@ -240,11 +240,11 @@ func idPrefixDistribution(nodes []*Node) map[uint32]int { return d } -func approxEqual(x, y, ε int) bool { +func approxEqual(x, y, epsilon int) bool { if y > x { x, y = y, x } - return x-y > ε + return x-y > epsilon } // genIter creates fake nodes with numbered IDs based on 'index' and 'gen' diff --git a/rpc/server_test.go b/rpc/server_test.go index ed07e7f22..3c1e2f95e 100644 --- a/rpc/server_test.go +++ b/rpc/server_test.go @@ -109,13 +109,19 @@ func runTestScript(t *testing.T, file string) { sort.Slice(msgs, func(i, j int) bool { return string(msgs[i].ID) < string(msgs[j].ID) }) - b, _ := json.Marshal(msgs) + b, err := json.Marshal(msgs) + if err != nil { + panic(err) + } sent = string(b) msgs, _ = parseMessage(json.RawMessage(want)) sort.Slice(msgs, func(i, j int) bool { return string(msgs[i].ID) < string(msgs[j].ID) }) - b, _ = json.Marshal(msgs) + b, err = json.Marshal(msgs) + if err != nil { + panic(err) + } want = string(b) } if sent != want { diff --git a/tests/rlp_test_util.go b/tests/rlp_test_util.go index 553de0f85..eb71f3d35 100644 --- a/tests/rlp_test_util.go +++ b/tests/rlp_test_util.go @@ -107,11 +107,11 @@ func translateJSON(v interface{}) interface{} { } return []byte(v) case []interface{}: - new := make([]interface{}, len(v)) + newJson := make([]interface{}, len(v)) for i := range v { - new[i] = translateJSON(v[i]) + newJson[i] = translateJSON(v[i]) } - return new + return newJson default: panic(fmt.Errorf("can't handle %T", v)) } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 65c247edd..a681098df 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -81,19 +81,6 @@ type stPostState struct { } } -type stTransaction struct { - GasPrice *big.Int `json:"gasPrice"` - MaxFeePerGas *big.Int `json:"maxFeePerGas"` - MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas"` - Nonce uint64 `json:"nonce"` - To string `json:"to"` - Data []string `json:"data"` - AccessLists []*types2.AccessList `json:"accessLists,omitempty"` - GasLimit []uint64 `json:"gasLimit"` - Value []string `json:"value"` - PrivateKey []byte `json:"secretKey"` -} - type stTransactionMarshaling struct { GasPrice *math.HexOrDecimal256 `json:"gasPrice"` MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"` diff --git a/turbo/rpchelper/subscription.go b/turbo/rpchelper/subscription.go index ec9db963c..720787257 100644 --- a/turbo/rpchelper/subscription.go +++ b/turbo/rpchelper/subscription.go @@ -18,8 +18,6 @@ type chan_sub[T any] struct { ctx context.Context cn context.CancelFunc - - c sync.Cond } // buffered channel diff --git a/turbo/shards/state_cache.go b/turbo/shards/state_cache.go index f7d857ecc..918a42605 100644 --- a/turbo/shards/state_cache.go +++ b/turbo/shards/state_cache.go @@ -612,7 +612,7 @@ func (sc *StateCache) SetAccountAbsent(address []byte) { sc.setRead(&ai, true /* absent */) } -func (sc *StateCache) setWrite(item CacheItem, writeItem CacheWriteItem, delete bool) { +func (sc *StateCache) setWrite(item CacheItem, writeItem CacheWriteItem, del bool) { id := id(item) // Check if this is going to be modification of the existing entry if existing := sc.writes[id].Get(writeItem); existing != nil { @@ -622,7 +622,7 @@ func (sc *StateCache) setWrite(item CacheItem, writeItem CacheWriteItem, delete sc.readSize -= cacheItem.GetSize() sc.writeSize += writeItem.GetSize() sc.writeSize -= cacheWriteItem.GetSize() - if delete { + if del { cacheItem.SetFlags(DeletedFlag) } else { cacheItem.CopyValueFrom(item) @@ -643,7 +643,7 @@ func (sc *StateCache) setWrite(item CacheItem, writeItem CacheWriteItem, delete sc.readSize -= cacheItem.GetSize() cacheItem.SetFlags(ModifiedFlag) cacheItem.ClearFlags(AbsentFlag) - if delete { + if del { cacheItem.SetFlags(DeletedFlag) } else { cacheItem.CopyValueFrom(item) @@ -668,7 +668,7 @@ func (sc *StateCache) setWrite(item CacheItem, writeItem CacheWriteItem, delete sc.sequence++ item.SetFlags(ModifiedFlag) item.ClearFlags(AbsentFlag) - if delete { + if del { item.SetFlags(DeletedFlag) } else { item.ClearFlags(DeletedFlag) diff --git a/turbo/stages/bodydownload/body_algos.go b/turbo/stages/bodydownload/body_algos.go index 3f055c249..8ce620b64 100644 --- a/turbo/stages/bodydownload/body_algos.go +++ b/turbo/stages/bodydownload/body_algos.go @@ -420,8 +420,8 @@ func (bd *BodyDownload) addBodyToCache(key uint64, body *types.RawBody) { } } -func (bd *BodyDownload) GetBodyFromCache(blockNum uint64, delete bool) *types.RawBody { - if delete { +func (bd *BodyDownload) GetBodyFromCache(blockNum uint64, del bool) *types.RawBody { + if del { if item, ok := bd.bodyCache.Delete(BodyTreeItem{blockNum: blockNum}); ok { bd.bodyCacheSize -= item.payloadSize return item.rawBody diff --git a/turbo/trie/hashbuilder.go b/turbo/trie/hashbuilder.go index f89f74e33..fde75eedc 100644 --- a/turbo/trie/hashbuilder.go +++ b/turbo/trie/hashbuilder.go @@ -255,7 +255,7 @@ func (hb *HashBuilder) accountLeaf(length int, keyHex []byte, balance *uint256.I var accountCode codeNode if fieldSet&uint32(8) != 0 { copy(hb.acc.CodeHash[:], hb.hashStack[len(hb.hashStack)-popped*hashStackStride-length2.Hash:len(hb.hashStack)-popped*hashStackStride]) - ok := false + var ok bool if !bytes.Equal(hb.acc.CodeHash[:], EmptyCodeHash[:]) { stackTop := hb.nodeStack[len(hb.nodeStack)-popped-1] if stackTop != nil { // if we don't have any stack top it might be okay because we didn't resolve the code yet (stateful resolver) diff --git a/turbo/trie/trie.go b/turbo/trie/trie.go index c3a552d29..fc81451ed 100644 --- a/turbo/trie/trie.go +++ b/turbo/trie/trie.go @@ -339,7 +339,7 @@ func (t *Trie) NeedLoadCode(addrHash libcommon.Hash, codeHash libcommon.Hash, by return false, nil } - ok := false + var ok bool if bytecode { _, ok = t.GetAccountCode(addrHash[:]) } else { diff --git a/turbo/trie/witness_builder.go b/turbo/trie/witness_builder.go index dd9296ef2..d517b0ad8 100644 --- a/turbo/trie/witness_builder.go +++ b/turbo/trie/witness_builder.go @@ -187,7 +187,7 @@ func (b *WitnessBuilder) makeBlockWitness( if limiter != nil { retainDec = limiter.RetainDecider } - codeSize := 0 + var codeSize int var err error if codeSize, err = b.processAccountCode(n, retainDec); err != nil { return err