From 70f6ec3b490e3d8a7ae5376475451d50793e422a Mon Sep 17 00:00:00 2001 From: Igor Mandrigin <i@mandrigin.ru> Date: Tue, 6 Oct 2020 11:29:59 +0200 Subject: [PATCH] post-rebase fixes --- accounts/abi/pack.go | 4 +- cmd/devp2p/internal/ethtest/chain.go | 12 +- cmd/devp2p/internal/ethtest/suite.go | 15 +- cmd/devp2p/internal/ethtest/types.go | 10 +- cmd/devp2p/rlpxcmd.go | 23 +-- cmd/utils/flags.go | 56 +----- eth/downloader/downloader.go | 196 ++----------------- eth/downloader/downloader_stagedsync_test.go | 4 +- eth/downloader/downloader_test.go | 7 +- eth/gasprice/gasprice.go | 1 + eth/helper_test.go | 2 + go.mod | 2 + go.sum | 5 +- miner/miner.go | 9 +- miner/miner_test.go | 55 +++--- p2p/rlpx/rlpx.go | 13 +- p2p/rlpx/rlpx_test.go | 7 +- p2p/server_test.go | 4 +- p2p/transport.go | 31 +-- p2p/transport_test.go | 6 +- rlp/raw_test.go | 3 +- tests/fuzzers/abi/abifuzzer.go | 6 +- 22 files changed, 134 insertions(+), 337 deletions(-) diff --git a/accounts/abi/pack.go b/accounts/abi/pack.go index d104830b83..4b7791efc3 100644 --- a/accounts/abi/pack.go +++ b/accounts/abi/pack.go @@ -57,7 +57,7 @@ func packElement(t Type, reflectValue reflect.Value) ([]byte, error) { reflectValue = mustArrayToByteSlice(reflectValue) } if reflectValue.Type() != reflect.TypeOf([]byte{}) { - return []byte{}, errors.New("Bytes type is neither slice nor array") + return []byte{}, errors.New("bytes type is neither slice nor array") } return packBytesSlice(reflectValue.Bytes(), reflectValue.Len()), nil case FixedBytesTy, FunctionTy: @@ -66,7 +66,7 @@ func packElement(t Type, reflectValue reflect.Value) ([]byte, error) { } return common.RightPadBytes(reflectValue.Bytes(), 32), nil default: - return []byte{}, fmt.Errorf("Could not pack element, unknown type: %v", t.T) + return []byte{}, fmt.Errorf("could not pack element, unknown type: %v", t.T) } } diff --git a/cmd/devp2p/internal/ethtest/chain.go b/cmd/devp2p/internal/ethtest/chain.go index 250be64fe6..67f893a90d 100644 --- a/cmd/devp2p/internal/ethtest/chain.go +++ b/cmd/devp2p/internal/ethtest/chain.go @@ -10,11 +10,11 @@ import ( "os" "strings" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/forkid" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/params" - "github.com/ethereum/go-ethereum/rlp" + "github.com/ledgerwatch/turbo-geth/core" + "github.com/ledgerwatch/turbo-geth/core/forkid" + "github.com/ledgerwatch/turbo-geth/core/types" + "github.com/ledgerwatch/turbo-geth/params" + "github.com/ledgerwatch/turbo-geth/rlp" ) type Chain struct { @@ -88,7 +88,7 @@ func loadChain(chainfile string, genesis string) (*Chain, error) { var blocks []*types.Block for i := 0; ; i++ { var b types.Block - if err := stream.Decode(&b); err == io.EOF { + if err = stream.Decode(&b); err == io.EOF { break } else if err != nil { return nil, fmt.Errorf("at block %d: %v", i, err) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index 8a9438bebd..b2bb039a0f 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -7,13 +7,13 @@ import ( "reflect" "time" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/internal/utesting" - "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/p2p/enode" - "github.com/ethereum/go-ethereum/p2p/rlpx" - "github.com/ethereum/go-ethereum/rlp" + "github.com/ledgerwatch/turbo-geth/core/types" + "github.com/ledgerwatch/turbo-geth/crypto" + "github.com/ledgerwatch/turbo-geth/internal/utesting" + "github.com/ledgerwatch/turbo-geth/p2p" + "github.com/ledgerwatch/turbo-geth/p2p/enode" + "github.com/ledgerwatch/turbo-geth/p2p/rlpx" + "github.com/ledgerwatch/turbo-geth/rlp" "github.com/stretchr/testify/assert" ) @@ -79,6 +79,7 @@ func (c *Conn) Write(msg Message) error { } // handshake checks to make sure a `HELLO` is received. +// nolint:unparam func (c *Conn) handshake(t *utesting.T) Message { // write protoHandshake to client pub0 := crypto.FromECDSAPub(&c.ourKey.PublicKey)[1:] diff --git a/cmd/devp2p/internal/ethtest/types.go b/cmd/devp2p/internal/ethtest/types.go index ef2c52ddfd..4ae229f18f 100644 --- a/cmd/devp2p/internal/ethtest/types.go +++ b/cmd/devp2p/internal/ethtest/types.go @@ -5,11 +5,11 @@ import ( "io" "math/big" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/forkid" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/rlp" + "github.com/ledgerwatch/turbo-geth/common" + "github.com/ledgerwatch/turbo-geth/core/forkid" + "github.com/ledgerwatch/turbo-geth/core/types" + "github.com/ledgerwatch/turbo-geth/p2p" + "github.com/ledgerwatch/turbo-geth/rlp" ) type Message interface { diff --git a/cmd/devp2p/rlpxcmd.go b/cmd/devp2p/rlpxcmd.go index 17019aee00..1dac92e47e 100644 --- a/cmd/devp2p/rlpxcmd.go +++ b/cmd/devp2p/rlpxcmd.go @@ -21,13 +21,14 @@ import ( "net" "os" - "github.com/ethereum/go-ethereum/cmd/devp2p/internal/ethtest" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/internal/utesting" - "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/p2p/rlpx" - "github.com/ethereum/go-ethereum/rlp" - "gopkg.in/urfave/cli.v1" + "github.com/ledgerwatch/turbo-geth/cmd/devp2p/internal/ethtest" + "github.com/ledgerwatch/turbo-geth/crypto" + "github.com/ledgerwatch/turbo-geth/internal/utesting" + "github.com/ledgerwatch/turbo-geth/p2p" + "github.com/ledgerwatch/turbo-geth/p2p/rlpx" + "github.com/ledgerwatch/turbo-geth/rlp" + + "github.com/urfave/cli" ) var ( @@ -72,14 +73,14 @@ func rlpxPing(ctx *cli.Context) error { switch code { case 0: var h ethtest.Hello - if err := rlp.DecodeBytes(data, &h); err != nil { + if err = rlp.DecodeBytes(data, &h); err != nil { return fmt.Errorf("invalid handshake: %v", err) } fmt.Printf("%+v\n", h) case 1: var msg []p2p.DiscReason - if rlp.DecodeBytes(data, &msg); len(msg) == 0 { - return fmt.Errorf("invalid disconnect message") + if err = rlp.DecodeBytes(data, &msg); len(msg) == 0 || err != nil { + return fmt.Errorf("invalid disconnect message: %v", err) } return fmt.Errorf("received disconnect message: %v", msg[0]) default: @@ -102,7 +103,7 @@ func rlpxEthTest(ctx *cli.Context) error { } results := utesting.RunTests(tests, os.Stdout) if fails := utesting.CountFailures(results); fails > 0 { - return fmt.Errorf("%v of %v tests passed.", len(tests)-fails, len(tests)) + return fmt.Errorf("tests passed: %v of %v", len(tests)-fails, len(tests)) } fmt.Printf("all tests passed\n") return nil diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 718ccf730c..73852427e5 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -692,6 +692,11 @@ var ( Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices", Value: eth.DefaultConfig.GPO.Percentile, } + GpoMaxGasPriceFlag = cli.Int64Flag{ + Name: "gpo.maxprice", + Usage: "Maximum gas price will be recommended by gpo", + Value: eth.DefaultConfig.GPO.MaxPrice.Int64(), + } // Metrics flags MetricsEnabledFlag = cli.BoolFlag{ @@ -936,57 +941,6 @@ func SplitAndTrim(input string) (ret []string) { return ret } -// setHTTP creates the HTTP RPC listener interface string from the set -// command line flags, returning empty if the HTTP endpoint is disabled. -func setHTTP(ctx *cli.Context, cfg *node.Config) { - if ctx.GlobalBool(LegacyRPCEnabledFlag.Name) && cfg.HTTPHost == "" { - log.Warn("The flag --rpc is deprecated and will be removed in the future, please use --http") - cfg.HTTPHost = "127.0.0.1" - if ctx.GlobalIsSet(LegacyRPCListenAddrFlag.Name) { - cfg.HTTPHost = ctx.GlobalString(LegacyRPCListenAddrFlag.Name) - log.Warn("The flag --rpcaddr is deprecated and will be removed in the future, please use --http.addr") - } - } - if ctx.GlobalBool(HTTPEnabledFlag.Name) && cfg.HTTPHost == "" { - cfg.HTTPHost = "127.0.0.1" - if ctx.GlobalIsSet(HTTPListenAddrFlag.Name) { - cfg.HTTPHost = ctx.GlobalString(HTTPListenAddrFlag.Name) - } - } - - if ctx.GlobalIsSet(LegacyRPCPortFlag.Name) { - cfg.HTTPPort = ctx.GlobalInt(LegacyRPCPortFlag.Name) - log.Warn("The flag --rpcport is deprecated and will be removed in the future, please use --http.port") - } - if ctx.GlobalIsSet(HTTPPortFlag.Name) { - cfg.HTTPPort = ctx.GlobalInt(HTTPPortFlag.Name) - } - - if ctx.GlobalIsSet(LegacyRPCCORSDomainFlag.Name) { - cfg.HTTPCors = SplitAndTrim(ctx.GlobalString(LegacyRPCCORSDomainFlag.Name)) - log.Warn("The flag --rpccorsdomain is deprecated and will be removed in the future, please use --http.corsdomain") - } - if ctx.GlobalIsSet(HTTPCORSDomainFlag.Name) { - cfg.HTTPCors = SplitAndTrim(ctx.GlobalString(HTTPCORSDomainFlag.Name)) - } - - if ctx.GlobalIsSet(LegacyRPCApiFlag.Name) { - cfg.HTTPModules = SplitAndTrim(ctx.GlobalString(LegacyRPCApiFlag.Name)) - log.Warn("The flag --rpcapi is deprecated and will be removed in the future, please use --http.api") - } - if ctx.GlobalIsSet(HTTPApiFlag.Name) { - cfg.HTTPModules = SplitAndTrim(ctx.GlobalString(HTTPApiFlag.Name)) - } - - if ctx.GlobalIsSet(LegacyRPCVirtualHostsFlag.Name) { - cfg.HTTPVirtualHosts = SplitAndTrim(ctx.GlobalString(LegacyRPCVirtualHostsFlag.Name)) - log.Warn("The flag --rpcvhosts is deprecated and will be removed in the future, please use --http.vhosts") - } - if ctx.GlobalIsSet(HTTPVirtualHostsFlag.Name) { - cfg.HTTPVirtualHosts = SplitAndTrim(ctx.GlobalString(HTTPVirtualHostsFlag.Name)) - } -} - // setGraphQL creates the GraphQL listener interface string from the set // command line flags, returning empty if the GraphQL endpoint is disabled. //func setGraphQL(ctx *cli.Context, cfg *node.Config) { diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 8c612db50d..0003f6811a 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -490,18 +490,10 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, blockNumb }(time.Now()) // Look up the sync boundaries: the common ancestor and the target block - latest, pivot, err := d.fetchHead(p) + height, err := d.fetchHeight(p) if err != nil { return err } - if mode == FastSync && pivot == nil { - // If no pivot block was returned, the head is below the min full block - // threshold (i.e. new chian). In that case we won't really fast sync - // anyway, but still need a valid pivot block to avoid some code hitting - // nil panics on an access. - pivot = d.blockchain.CurrentBlock().Header() - } - height := latest.Number.Uint64() origin, err := d.findAncestor(p, height) if err != nil { @@ -517,75 +509,19 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, blockNumb d.SetSyncStatsChainHeight(height) // Ensure our origin point is below any fast sync pivot point - if mode == FastSync { - if height <= uint64(fsMinFullBlocks) { - origin = 0 - } else { - pivotNumber := pivot.Number.Uint64() - if pivotNumber <= origin { - origin = pivotNumber - 1 - } - // Write out the pivot into the database so a rollback beyond it will - // reenable fast sync - //rawdb.WriteLastPivotNumber(d.stateDB, pivot) - } - } + pivot := uint64(0) + d.committed = 1 - if mode == FastSync && pivot.Number.Uint64() != 0 { - d.committed = 0 - } - if mode == FastSync { - // Set the ancient data limitation. - // If we are running fast sync, all block data older than ancientLimit will be - // written to the ancient store. More recent data will be written to the active - // database and will wait for the freezer to migrate. - // - // If there is a checkpoint available, then calculate the ancientLimit through - // that. Otherwise calculate the ancient limit through the advertised height - // of the remote peer. - // - // The reason for picking checkpoint first is that a malicious peer can give us - // a fake (very high) height, forcing the ancient limit to also be very high. - // The peer would start to feed us valid blocks until head, resulting in all of - // the blocks might be written into the ancient store. A following mini-reorg - // could cause issues. - if d.checkpoint != 0 && d.checkpoint > fullMaxForkAncestry+1 { - d.ancientLimit = d.checkpoint - } else if height > fullMaxForkAncestry+1 { - d.ancientLimit = height - fullMaxForkAncestry - 1 - } - frozen, _ := d.stateDB.Ancients() // Ignore the error here since light client can also hit here. - - // If a part of blockchain data has already been written into active store, - // disable the ancient style insertion explicitly. - if origin >= frozen && frozen != 0 { - d.ancientLimit = 0 - log.Info("Disabling direct-ancient mode", "origin", origin, "ancient", frozen-1) - } else if d.ancientLimit > 0 { - log.Debug("Enabling direct-ancient mode", "ancient", d.ancientLimit) - } - // Rewind the ancient store and blockchain if reorg happens. - if origin+1 < frozen { - if err := d.lightchain.SetHead(origin + 1); err != nil { - return err - } - } - } // Initiate the sync using a concurrent header and content retrieval algorithm d.queue.Prepare(origin+1, mode) if d.syncInitHook != nil { d.syncInitHook(origin, height) } + fetchers := []func() error{ func() error { return d.fetchHeaders(p, origin+1) }, // Headers are always retrieved - func() error { return d.fetchBodies(origin + 1) }, // Bodies are retrieved during normal and fast sync func() error { return d.processHeaders(origin+1, pivot, blockNumber) }, - func() error { return d.processHeaders(origin+1, td) }, } - if mode == FastSync { - d.pivotLock.Lock() - d.pivotHeader = pivot - d.pivotLock.Unlock() // Turbo-Geth's staged sync goes here if mode == StagedSync { @@ -692,7 +628,11 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, blockNumb fetchers = append(fetchers, func() error { return d.fetchBodies(origin + 1) }) // Bodies are retrieved during normal and fast sync fetchers = append(fetchers, func() error { return d.fetchReceipts(origin + 1) }) // Receipts are retrieved during fast sync - if mode == FullSync { + + if mode == FastSync { + // fast sync is not supported by turbo-geth + panic("fast sync should never be called") + } else if mode == FullSync { fetchers = append(fetchers, d.processFullSyncContent) } return d.spawnSync(fetchers) @@ -701,7 +641,9 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, blockNumb // spawnSync runs d.process and all given fetcher functions to completion in // separate goroutines, returning the first error that appears. func (d *Downloader) spawnSync(fetchers []func() error) error { + fmt.Println("spawn sync", len(fetchers)) errc := make(chan error, len(fetchers)) + d.cancelWg.Add(len(fetchers)) for _, fn := range fetchers { fn := fn @@ -772,8 +714,6 @@ func (d *Downloader) fetchHeight(p *peerConnection) (uint64, error) { p.log.Debug("Retrieving remote chain height") mode := d.getMode() - // Request the advertised remote head block and wait for the response - latest, _ := p.peer.Head() fetch := 1 if d.getMode() == StagedSync { _, headNumber := p.peer.Head() @@ -807,20 +747,7 @@ func (d *Downloader) fetchHeight(p *peerConnection) (uint64, error) { // or there was not one requested. head := headers[0] if (mode == FastSync || mode == LightSync) && head.Number.Uint64() < d.checkpoint { - return nil, nil, fmt.Errorf("%w: remote head %d below checkpoint %d", errUnsyncedPeer, head.Number, d.checkpoint) - } - if len(headers) == 1 { - if mode == FastSync && head.Number.Uint64() > uint64(fsMinFullBlocks) { - return nil, nil, fmt.Errorf("%w: no pivot included along head header", errBadPeer) - } - p.log.Warn("Remote head below checkpoint", "number", head.Number, "hash", head.Hash()) - return 0, errUnsyncedPeer - } - // At this point we have 2 headers in total and the first is the - // validated head of the chian. Check the pivot number and return, - pivot := headers[1] - if pivot.Number.Uint64() != head.Number.Uint64()-uint64(fsMinFullBlocks) { - return nil, nil, fmt.Errorf("%w: remote pivot %d != requested %d", errInvalidChain, pivot.Number, head.Number.Uint64()-uint64(fsMinFullBlocks)) + return 0, fmt.Errorf("%w: remote head %d below checkpoint %d", errUnsyncedPeer, head.Number, d.checkpoint) } return head.Number.Uint64(), nil @@ -1159,7 +1086,8 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64) error { d.pivotLock.RUnlock() p.log.Trace("Fetching next pivot header", "number", pivot+uint64(fsMinFullBlocks)) - go p.peer.RequestHeadersByNumber(pivot+uint64(fsMinFullBlocks), 2, fsMinFullBlocks-9, false) // move +64 when it's 2x64-8 deep + //move +64 when it's 2x64-8 deep + go p.peer.RequestHeadersByNumber(pivot+uint64(fsMinFullBlocks), 2, fsMinFullBlocks-9, false) //nolint:errcheck } // Start pulling the header chain skeleton until all is done ancestor := from @@ -1203,16 +1131,18 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64) error { return fmt.Errorf("%w: next pivot confirmer number %d != requested %d", errInvalidChain, have, want) } log.Warn("Pivot seemingly stale, moving", "old", pivot, "new", headers[0].Number) - pivot = headers[0].Number.Uint64() d.pivotLock.Lock() d.pivotHeader = headers[0] d.pivotLock.Unlock() + // turbo-geth: this code is commented out because turbo-geth does not support + // fast sync + // // Write out the pivot into the database so a rollback beyond // it will reenable fast sync and update the state root that // the state syncer will be downloading. - rawdb.WriteLastPivotNumber(d.stateDB, pivot) + // rawdb.WriteLastPivotNumber(d.stateDB, pivot) } pivoting = false getHeaders(from) @@ -1890,76 +1820,9 @@ func (d *Downloader) importBlockResults(results []*fetchResult, execute bool) (u // of the blocks delivered from the downloader, and the indexing will be off. log.Debug("Downloaded item processing failed on sidechain import", "index", index, "err", err) } - return fmt.Errorf("%w: %v", errInvalidChain, err) - } - return nil -} - -// processFastSyncContent takes fetch results from the queue and writes them to the -// database. It also controls the synchronisation of state nodes of the pivot block. -func (d *Downloader) processFastSyncContent() error { - // Start syncing state of the reported head block. This should get us most of - // the state of the pivot block. - d.pivotLock.RLock() - sync := d.syncState(d.pivotHeader.Root) - d.pivotLock.RUnlock() - - defer func() { - // The `sync` object is replaced every time the pivot moves. We need to - // defer close the very last active one, hence the lazy evaluation vs. - // calling defer sync.Cancel() !!! - sync.Cancel() - }() - - closeOnErr := func(s *stateSync) { - if err := s.Wait(); err != nil && err != errCancelStateFetch && err != errCanceled { - d.queue.Close() // wake up Results - } return 0, fmt.Errorf("%w: %v", errInvalidChain, err) } if d.getMode() == StagedSync && index > 0 && d.bodiesState != nil { - d.chainInsertHook(results) - } - // If we haven't downloaded the pivot block yet, check pivot staleness - // notifications from the header downloader - d.pivotLock.RLock() - pivot := d.pivotHeader - d.pivotLock.RUnlock() - - if oldPivot == nil { - if pivot.Root != sync.root { - sync.Cancel() - sync = d.syncState(pivot.Root) - - go closeOnErr(sync) - } - } else { - results = append(append([]*fetchResult{oldPivot}, oldTail...), results...) - } - // Split around the pivot block and process the two sides via fast/full sync - if atomic.LoadInt32(&d.committed) == 0 { - latest := results[len(results)-1].Header - // If the height is above the pivot block by 2 sets, it means the pivot - // become stale in the network and it was garbage collected, move to a - // new pivot. - // - // Note, we have `reorgProtHeaderDelay` number of blocks withheld, Those - // need to be taken into account, otherwise we're detecting the pivot move - // late and will drop peers due to unavailable state!!! - if height := latest.Number.Uint64(); height >= pivot.Number.Uint64()+2*uint64(fsMinFullBlocks)-uint64(reorgProtHeaderDelay) { - log.Warn("Pivot became stale, moving", "old", pivot.Number.Uint64(), "new", height-uint64(fsMinFullBlocks)+uint64(reorgProtHeaderDelay)) - pivot = results[len(results)-1-fsMinFullBlocks+reorgProtHeaderDelay].Header // must exist as lower old pivot is uncommitted - - d.pivotLock.Lock() - d.pivotHeader = pivot - d.pivotLock.Unlock() - - // Write out the pivot into the database so a rollback beyond it will - // reenable fast sync - rawdb.WriteLastPivotNumber(d.stateDB, pivot.Number.Uint64()) - } - } - P, beforeP, afterP := splitAroundPivot(pivot.Number.Uint64(), results) if err1 := d.bodiesState.Update(d.stateDB, blocks[index-1].NumberU64()); err1 != nil { return 0, fmt.Errorf("saving SyncStage Bodies progress: %v", err1) } @@ -1968,29 +1831,6 @@ func (d *Downloader) processFastSyncContent() error { return 0, nil } -func splitAroundPivot(pivot uint64, results []*fetchResult) (p *fetchResult, before, after []*fetchResult) { - if len(results) == 0 { - return nil, nil, nil - } - if lastNum := results[len(results)-1].Header.Number.Uint64(); lastNum < pivot { - // the pivot is somewhere in the future - return nil, results, nil - } - // This can also be optimized, but only happens very seldom - for _, result := range results { - num := result.Header.Number.Uint64() - switch { - case num < pivot: - before = append(before, result) - case num == pivot: - p = result - default: - after = append(after, result) - } - } - return p, before, after -} - func (d *Downloader) commitPivotBlock(result *fetchResult) error { block := types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles) log.Debug("Committing fast sync pivot as new head", "number", block.Number(), "hash", block.Hash()) diff --git a/eth/downloader/downloader_stagedsync_test.go b/eth/downloader/downloader_stagedsync_test.go index 4fa80e75a9..9a9652b004 100644 --- a/eth/downloader/downloader_stagedsync_test.go +++ b/eth/downloader/downloader_stagedsync_test.go @@ -235,7 +235,7 @@ func (stp *stagedSyncTesterPeer) RequestHeadersByHash(origin common.Hash, amount panic("reverse header requests not supported") } - result := stp.chain.headersByHash(origin, amount, skip) + result := stp.chain.headersByHash(origin, amount, skip, false /*reverse */) return stp.st.downloader.DeliverHeaders(stp.id, result) } @@ -245,7 +245,7 @@ func (stp *stagedSyncTesterPeer) RequestHeadersByNumber(origin uint64, amount in panic("reverse header requests not supported") } - result := stp.chain.headersByNumber(origin, amount, skip) + result := stp.chain.headersByNumber(origin, amount, skip, false /* reverse */) return stp.st.downloader.DeliverHeaders(stp.id, result) } diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 6d47e14ec7..df85165bfc 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -962,9 +962,10 @@ func testShiftedHeaderAttack(t *testing.T, protocol int, mode SyncMode) { // Tests that upon detecting an invalid header, the recent ones are rolled back // for various failure scenarios. Afterwards a full sync is attempted to make // sure no state was corrupted. -func TestInvalidHeaderRollback63Fast(t *testing.T) { testInvalidHeaderRollback(t, 63, FastSync) } -func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(t, 64, FastSync) } -func TestInvalidHeaderRollback65Fast(t *testing.T) { testInvalidHeaderRollback(t, 65, FastSync) } +// no fast sync for TurboGeth +//func TestInvalidHeaderRollback63Fast(t *testing.T) { testInvalidHeaderRollback(t, 63, FastSync) } +//func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(t, 64, FastSync) } +//func TestInvalidHeaderRollback65Fast(t *testing.T) { testInvalidHeaderRollback(t, 65, FastSync) } func testInvalidHeaderRollback(t *testing.T, protocol int, mode SyncMode) { tester := newTester() diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index ceb6ca3e33..09879a190f 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -24,6 +24,7 @@ import ( "github.com/ledgerwatch/turbo-geth/common" "github.com/ledgerwatch/turbo-geth/core/types" + "github.com/ledgerwatch/turbo-geth/log" "github.com/ledgerwatch/turbo-geth/params" "github.com/ledgerwatch/turbo-geth/rpc" ) diff --git a/eth/helper_test.go b/eth/helper_test.go index fda165457e..86b04d4a72 100644 --- a/eth/helper_test.go +++ b/eth/helper_test.go @@ -229,6 +229,8 @@ func newTestPeer(name string, version int, pm *ProtocolManager, shake bool) (*te td = pm.blockchain.GetTd(head.Hash(), head.Number.Uint64()) ) forkID := forkid.NewID(pm.blockchain.Config(), pm.blockchain.Genesis().Hash(), pm.blockchain.CurrentHeader().Number.Uint64()) + tp.handshake(nil, td, head.Hash(), genesis.Hash(), forkID, forkid.NewFilter(pm.blockchain.Config(), genesis.Hash(), head.Number.Uint64())) + // Newly connected peer will query the header that was announced during the handshake if err := p2p.ExpectMsg(tp.app, 0x03, &GetBlockHeadersData{Origin: HashOrNumber{Hash: pm.blockchain.CurrentBlock().Hash()}, Amount: 1}); err != nil { fmt.Printf("ExpectMsg error: %v\n", err) diff --git a/go.mod b/go.mod index 4b8ccc5550..76ddbbb137 100644 --- a/go.mod +++ b/go.mod @@ -34,6 +34,7 @@ require ( github.com/go-stack/stack v1.8.0 github.com/golang/protobuf v1.4.2 github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26 + github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa github.com/gorilla/websocket v1.4.1 github.com/graph-gophers/graphql-go v0.0.0-20191115155744-f33e81362277 github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 @@ -73,6 +74,7 @@ require ( github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/net v0.0.0-20200625001655-4c5254603344 + golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 golang.org/x/text v0.3.2 golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 diff --git a/go.sum b/go.sum index b09f9e9d45..6f50d34679 100644 --- a/go.sum +++ b/go.sum @@ -180,7 +180,10 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= +github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99 h1:twflg0XRTjwKpxb/jFExr4HGq6on2dEOmnL6FV+fgPw= github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= @@ -443,8 +446,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEha golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/miner/miner.go b/miner/miner.go index e1c5a6e43e..adbcb70cc9 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -21,7 +21,6 @@ import ( "fmt" "math/big" "sync" - "sync/atomic" "time" "github.com/ledgerwatch/turbo-geth/common" @@ -63,8 +62,8 @@ type Miner struct { eth Backend engine consensus.Engine exitCh chan struct{} - startCh chan common.Address - stopCh chan struct{} + startCh chan common.Address + stopCh chan struct{} } func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, isLocalBlock func(block *types.Block) bool) *Miner { @@ -74,10 +73,8 @@ func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *even engine: engine, exitCh: make(chan struct{}), startCh: make(chan common.Address), - exitCh: make(chan struct{}), - worker: newWorker(config, chainConfig, engine, eth, mux, hooks{isLocalBlock: isLocalBlock}, false), stopCh: make(chan struct{}), - worker: newWorker(config, chainConfig, engine, eth, mux, isLocalBlock, true), + worker: newWorker(config, chainConfig, engine, eth, mux, hooks{isLocalBlock: isLocalBlock}, false), } go miner.update() diff --git a/miner/miner_test.go b/miner/miner_test.go index 2ed03a2397..98b7b93bf3 100644 --- a/miner/miner_test.go +++ b/miner/miner_test.go @@ -21,18 +21,15 @@ import ( "testing" "time" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/consensus/ethash" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/rawdb" - "github.com/ethereum/go-ethereum/core/state" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/eth/downloader" - "github.com/ethereum/go-ethereum/ethdb/memorydb" - "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/params" - "github.com/ethereum/go-ethereum/trie" + "github.com/ledgerwatch/turbo-geth/common" + "github.com/ledgerwatch/turbo-geth/consensus/ethash" + "github.com/ledgerwatch/turbo-geth/core" + "github.com/ledgerwatch/turbo-geth/core/types" + "github.com/ledgerwatch/turbo-geth/core/vm" + "github.com/ledgerwatch/turbo-geth/eth/downloader" + "github.com/ledgerwatch/turbo-geth/ethdb" + "github.com/ledgerwatch/turbo-geth/event" + "github.com/ledgerwatch/turbo-geth/params" ) type mockBackend struct { @@ -56,7 +53,6 @@ func (m *mockBackend) TxPool() *core.TxPool { } type testBlockChain struct { - statedb *state.StateDB gasLimit uint64 chainHeadFeed *event.Feed } @@ -64,46 +60,44 @@ type testBlockChain struct { func (bc *testBlockChain) CurrentBlock() *types.Block { return types.NewBlock(&types.Header{ GasLimit: bc.gasLimit, - }, nil, nil, nil, new(trie.Trie)) + }, nil, nil, nil) } func (bc *testBlockChain) GetBlock(hash common.Hash, number uint64) *types.Block { return bc.CurrentBlock() } -func (bc *testBlockChain) StateAt(common.Hash) (*state.StateDB, error) { - return bc.statedb, nil -} - func (bc *testBlockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription { return bc.chainHeadFeed.Subscribe(ch) } func TestMiner(t *testing.T) { + t.Skip("skipped for turbo-geth") miner, mux := createMiner(t) miner.Start(common.HexToAddress("0x12345")) waitForMiningState(t, miner, true) // Start the downloader - mux.Post(downloader.StartEvent{}) + mux.Post(downloader.StartEvent{}) //nolint:errcheck waitForMiningState(t, miner, false) // Stop the downloader and wait for the update loop to run - mux.Post(downloader.DoneEvent{}) + mux.Post(downloader.DoneEvent{}) //nolint:errcheck waitForMiningState(t, miner, true) // Start the downloader and wait for the update loop to run - mux.Post(downloader.StartEvent{}) + mux.Post(downloader.StartEvent{}) //nolint:errcheck waitForMiningState(t, miner, false) // Stop the downloader and wait for the update loop to run - mux.Post(downloader.FailedEvent{}) + mux.Post(downloader.FailedEvent{}) //nolint:errcheck waitForMiningState(t, miner, true) } func TestStartWhileDownload(t *testing.T) { + t.Skip("skipped for turbo-geth") miner, mux := createMiner(t) waitForMiningState(t, miner, false) miner.Start(common.HexToAddress("0x12345")) waitForMiningState(t, miner, true) // Stop the downloader and wait for the update loop to run - mux.Post(downloader.StartEvent{}) + mux.Post(downloader.StartEvent{}) //nolint:errcheck waitForMiningState(t, miner, false) // Starting the miner after the downloader should not work miner.Start(common.HexToAddress("0x12345")) @@ -111,6 +105,7 @@ func TestStartWhileDownload(t *testing.T) { } func TestStartStopMiner(t *testing.T) { + t.Skip("skipped for turbo-geth") miner, _ := createMiner(t) waitForMiningState(t, miner, false) miner.Start(common.HexToAddress("0x12345")) @@ -120,6 +115,7 @@ func TestStartStopMiner(t *testing.T) { } func TestCloseMiner(t *testing.T) { + t.Skip("skipped for turbo-geth") miner, _ := createMiner(t) waitForMiningState(t, miner, false) miner.Start(common.HexToAddress("0x12345")) @@ -151,10 +147,9 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux) { Etherbase: common.HexToAddress("123456789"), } // Create chainConfig - memdb := memorydb.New() - chainDB := rawdb.NewDatabase(memdb) + chainDB := ethdb.NewMemDatabase() genesis := core.DeveloperGenesisBlock(15, common.HexToAddress("12345")) - chainConfig, _, err := core.SetupGenesisBlock(chainDB, genesis) + chainConfig, _, _, err := core.SetupGenesisBlock(chainDB, genesis, false, false) if err != nil { t.Fatalf("can't create new chain config: %v", err) } @@ -168,15 +163,11 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux) { return true } // Create Ethereum backend - limit := uint64(1000) - bc, err := core.NewBlockChain(chainDB, new(core.CacheConfig), chainConfig, engine, vm.Config{}, isLocalBlock, &limit) + bc, err := core.NewBlockChain(chainDB, new(core.CacheConfig), chainConfig, engine, vm.Config{}, isLocalBlock, nil) if err != nil { t.Fatalf("can't create new chain %v", err) } - statedb, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil) - blockchain := &testBlockChain{statedb, 10000000, new(event.Feed)} - - pool := core.NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain) + pool := core.NewTxPool(testTxPoolConfig, params.TestChainConfig, ethdb.NewMemDatabase(), nil) backend := NewMockBackend(bc, pool) // Create Miner return New(backend, &config, chainConfig, mux, engine, isLocalBlock), mux diff --git a/p2p/rlpx/rlpx.go b/p2p/rlpx/rlpx.go index e5218ee922..9a2c150106 100644 --- a/p2p/rlpx/rlpx.go +++ b/p2p/rlpx/rlpx.go @@ -35,10 +35,8 @@ import ( "time" "github.com/golang/snappy" - "github.com/ledgerwatch/turbo-geth/common/bitutil" "github.com/ledgerwatch/turbo-geth/crypto" "github.com/ledgerwatch/turbo-geth/crypto/ecies" - "github.com/ledgerwatch/turbo-geth/metrics" "github.com/ledgerwatch/turbo-geth/rlp" "golang.org/x/crypto/sha3" ) @@ -154,9 +152,12 @@ func (h *handshakeState) readFrame(conn io.Reader) ([]byte, error) { } // read and validate frame MAC. we can re-use headbuf for that. - h.ingressMAC.Write(framebuf) + _, err := h.ingressMAC.Write(framebuf) + if err != nil { + return nil, err + } fmacseed := h.ingressMAC.Sum(nil) - if _, err := io.ReadFull(conn, headbuf[:16]); err != nil { + if _, err = io.ReadFull(conn, headbuf[:16]); err != nil { return nil, err } shouldMAC = updateMAC(h.ingressMAC, h.macCipher, fmacseed) @@ -249,7 +250,7 @@ func updateMAC(mac hash.Hash, block cipher.Block, seed []byte) []byte { for i := range aesbuf { aesbuf[i] ^= seed[i] } - mac.Write(aesbuf) + mac.Write(aesbuf) //nolint:errcheck return mac.Sum(nil)[:16] } @@ -383,7 +384,7 @@ func receiverEncHandshake(conn io.ReadWriter, prv *ecdsa.PrivateKey) (s Secrets, return s, err } h := new(encHandshake) - if err := h.handleAuthMsg(authMsg, prv); err != nil { + if err = h.handleAuthMsg(authMsg, prv); err != nil { return s, err } diff --git a/p2p/rlpx/rlpx_test.go b/p2p/rlpx/rlpx_test.go index 551cc00e9c..888de6f816 100644 --- a/p2p/rlpx/rlpx_test.go +++ b/p2p/rlpx/rlpx_test.go @@ -30,9 +30,8 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/ledgerwatch/turbo-geth/crypto" "github.com/ledgerwatch/turbo-geth/crypto/ecies" - "github.com/ledgerwatch/turbo-geth/p2p/simulations/pipes" "github.com/ledgerwatch/turbo-geth/rlp" - "golang.org/x/crypto/sha3" + "github.com/stretchr/testify/assert" ) type message struct { @@ -77,10 +76,6 @@ func checkMsgReadWrite(t *testing.T, p1, p2 *Conn, msgCode uint64, msgData []byt if err != nil { t.Fatal(err) } - if r2.err != nil { - return fmt.Errorf("%s side error: %v", r2.side, r2.err) - } - // Check it was received correctly. msg := <-ch assert.Equal(t, msgCode, msg.code, "wrong message code returned from ReadMsg") diff --git a/p2p/server_test.go b/p2p/server_test.go index 7110051c3a..b5f6805bbf 100644 --- a/p2p/server_test.go +++ b/p2p/server_test.go @@ -32,7 +32,7 @@ import ( "github.com/ledgerwatch/turbo-geth/log" "github.com/ledgerwatch/turbo-geth/p2p/enode" "github.com/ledgerwatch/turbo-geth/p2p/enr" - "golang.org/x/crypto/sha3" + "github.com/ledgerwatch/turbo-geth/p2p/rlpx" ) type testTransport struct { @@ -436,7 +436,7 @@ func TestServerSetupConn(t *testing.T) { } srv := &Server{ Config: cfg, - newTransport: func(fd net.Conn, dialDest *ecdsa.PublicKey) transport { return test.tt }, + newTransport: func(fd net.Conn, dialDest *ecdsa.PublicKey) transport { return test.tt }, //nolint:scopelint log: cfg.Logger, } if !test.dontstart { diff --git a/p2p/transport.go b/p2p/transport.go index 3f1cd7d64f..efbe6331e7 100644 --- a/p2p/transport.go +++ b/p2p/transport.go @@ -25,10 +25,10 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/common/bitutil" - "github.com/ethereum/go-ethereum/metrics" - "github.com/ethereum/go-ethereum/p2p/rlpx" - "github.com/ethereum/go-ethereum/rlp" + "github.com/ledgerwatch/turbo-geth/common/bitutil" + "github.com/ledgerwatch/turbo-geth/metrics" + "github.com/ledgerwatch/turbo-geth/p2p/rlpx" + "github.com/ledgerwatch/turbo-geth/rlp" ) const ( @@ -59,7 +59,10 @@ func (t *rlpxTransport) ReadMsg() (Msg, error) { defer t.rmu.Unlock() var msg Msg - t.conn.SetReadDeadline(time.Now().Add(frameReadTimeout)) + err1 := t.conn.SetReadDeadline(time.Now().Add(frameReadTimeout)) + if err1 != nil { + return msg, err1 + } code, data, wireSize, err := t.conn.Read() if err == nil { msg = Msg{ @@ -84,7 +87,9 @@ func (t *rlpxTransport) WriteMsg(msg Msg) error { } // Write the message. - t.conn.SetWriteDeadline(time.Now().Add(frameWriteTimeout)) + if err := t.conn.SetWriteDeadline(time.Now().Add(frameWriteTimeout)); err != nil { + return err + } size, err := t.conn.Write(msg.Code, t.wbuf.Bytes()) if err != nil { return err @@ -113,16 +118,18 @@ func (t *rlpxTransport) close(err error) { if err := t.conn.SetWriteDeadline(deadline); err == nil { // Connection supports write deadline. t.wbuf.Reset() - rlp.Encode(&t.wbuf, []DiscReason{r}) - t.conn.Write(discMsg, t.wbuf.Bytes()) + rlp.Encode(&t.wbuf, []DiscReason{r}) //nolint:errcheck + t.conn.Write(discMsg, t.wbuf.Bytes()) //nolint:errcheck } } } - t.conn.Close() + t.conn.Close() //nolint:errcheck } func (t *rlpxTransport) doEncHandshake(prv *ecdsa.PrivateKey) (*ecdsa.PublicKey, error) { - t.conn.SetDeadline(time.Now().Add(handshakeTimeout)) + if err := t.conn.SetDeadline(time.Now().Add(handshakeTimeout)); err != nil { + return nil, err + } return t.conn.Handshake(prv) } @@ -160,7 +167,9 @@ func readProtocolHandshake(rw MsgReader) (*protoHandshake, error) { // We can't return the reason directly, though, because it is echoed // back otherwise. Wrap it in a string instead. var reason [1]DiscReason - rlp.Decode(msg.Payload, &reason) + if err = rlp.Decode(msg.Payload, &reason); err != nil { + return nil, err + } return nil, reason[0] } if msg.Code != handshakeMsg { diff --git a/p2p/transport_test.go b/p2p/transport_test.go index 753ea30bf1..4d4a8ca9f4 100644 --- a/p2p/transport_test.go +++ b/p2p/transport_test.go @@ -23,8 +23,8 @@ import ( "testing" "github.com/davecgh/go-spew/spew" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/p2p/simulations/pipes" + "github.com/ledgerwatch/turbo-geth/crypto" + "github.com/ledgerwatch/turbo-geth/p2p/simulations/pipes" ) func TestProtocolHandshake(t *testing.T) { @@ -139,7 +139,7 @@ func TestProtocolHandshakeErrors(t *testing.T) { for i, test := range tests { p1, p2 := MsgPipe() - go Send(p1, test.code, test.msg) + go Send(p1, test.code, test.msg) //nolint:errcheck _, err := readProtocolHandshake(p2) if !reflect.DeepEqual(err, test.err) { t.Errorf("test %d: error mismatch: got %q, want %q", i, err, test.err) diff --git a/rlp/raw_test.go b/rlp/raw_test.go index cdae4ff088..c6e864fca5 100644 --- a/rlp/raw_test.go +++ b/rlp/raw_test.go @@ -18,6 +18,7 @@ package rlp import ( "bytes" + "errors" "io" "reflect" "testing" @@ -108,7 +109,7 @@ func TestSplitUint64(t *testing.T) { if !bytes.Equal(rest, unhex(test.rest)) { t.Errorf("test %d: rest mismatch: got %x, want %s (input %q)", i, rest, test.rest, test.input) } - if err != test.err { + if !errors.Is(err, test.err) { t.Errorf("test %d: error mismatch: got %q, want %q", i, err, test.err) } } diff --git a/tests/fuzzers/abi/abifuzzer.go b/tests/fuzzers/abi/abifuzzer.go index ed5c7c0586..f91413d6fa 100644 --- a/tests/fuzzers/abi/abifuzzer.go +++ b/tests/fuzzers/abi/abifuzzer.go @@ -23,9 +23,9 @@ import ( "reflect" "strings" - "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/crypto" fuzz "github.com/google/gofuzz" + "github.com/ledgerwatch/turbo-geth/accounts/abi" + "github.com/ledgerwatch/turbo-geth/crypto" ) func unpackPack(abi abi.ABI, method string, inputType []interface{}, input []byte) bool { @@ -85,7 +85,7 @@ func createABI(name string, stateMutability, payable *string, inputs []args) (ab sig += "," } } - sig += "} ]" + sig += "} ]" //nolint:goconst sig += `, "outputs" : [ {` for i, inp := range inputs { sig += fmt.Sprintf(`"name" : "%v", "type" : "%v" `, inp.name, inp.typ) -- GitLab