enable more linters #954 (#7179)

This commit is contained in:
Alex Sharov 2023-03-25 12:13:27 +07:00 committed by GitHub
parent e0dd48cc67
commit 201572c6f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 133 additions and 171 deletions

View File

@ -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:

View File

@ -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"
)
@ -572,7 +571,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
var (
lo = params.TxGas - 1
hi uint64
cap 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
})
}
*/

View File

@ -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

View File

@ -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
}

View File

@ -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{}

View File

@ -129,7 +129,7 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs
var (
lo = params.TxGas - 1
hi uint64
cap 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

View File

@ -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

View File

@ -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
}

View File

@ -32,8 +32,7 @@ import (
type ScanWorker struct {
txNum uint64
as *libstate.AggregatorStep
fromKey, toKey []byte
currentKey []byte
toKey []byte
bitmap roaring64.Bitmap
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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
}

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -19,7 +19,6 @@ type StateReconWriterInc struct {
txNum uint64
tx kv.Tx
chainTx kv.Tx
composite []byte
}
func NewStateReconWriterInc(as *libstate.AggregatorStep, rs *ReconState) *StateReconWriterInc {

View File

@ -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)

View File

@ -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)
}

View File

@ -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)

View File

@ -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) {

View File

@ -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 {

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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
}

View File

@ -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'

View File

@ -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 {

View File

@ -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))
}

View File

@ -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"`

View File

@ -18,8 +18,6 @@ type chan_sub[T any] struct {
ctx context.Context
cn context.CancelFunc
c sync.Cond
}
// buffered channel

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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 {

View File

@ -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