From ec09c5ff359db4b65c09f491e4de73ec362c8daf Mon Sep 17 00:00:00 2001
From: Alex Sharov <AskAlexSharov@gmail.com>
Date: Tue, 12 Oct 2021 12:04:04 +0700
Subject: [PATCH] RemoteRPC: coherentCache for kv.Code; LocalRPC: enable small
 blocksLRU (#2815)

---
 Makefile                                 |  2 +-
 cmd/rpcdaemon/cli/config.go              |  2 +-
 cmd/rpcdaemon/commands/eth_api.go        | 14 ++++++----
 cmd/rpcdaemon/commands/eth_call.go       | 33 +++++++++++++++++++++---
 cmd/rpctest/main.go                      |  8 ++++--
 cmd/rpctest/rpctest/bench_ethcall.go     |  9 +++++--
 cmd/rpctest/rpctest/request_generator.go | 22 ++++++++++++++++
 core/state/cached_reader2.go             |  4 +--
 crypto/blake2b/blake2bAVX2_amd64.go      |  1 +
 crypto/blake2b/register.go               |  1 +
 crypto/bn256/bn256_fast.go               |  1 +
 crypto/bn256/cloudflare/gfp_decl.go      |  1 +
 crypto/signature_cgo.go                  |  1 +
 eth/backend.go                           | 24 +++++++++--------
 ethdb/olddb/database_test.go             |  1 +
 go.mod                                   |  2 +-
 go.sum                                   |  4 +--
 internal/debug/loudpanic.go              |  1 +
 internal/debug/signal.go                 |  1 +
 internal/debug/trace.go                  |  3 ++-
 metrics/cpu_enabled.go                   |  1 +
 metrics/cpu_syscall.go                   |  1 +
 metrics/runtime_cgo.go                   |  4 +--
 metrics/syslog.go                        |  1 +
 p2p/netutil/toobig_notwindows.go         |  3 ++-
 turbo/transactions/call.go               | 16 +++---------
 26 files changed, 114 insertions(+), 47 deletions(-)

diff --git a/Makefile b/Makefile
index 74b8282959..a354e4075b 100644
--- a/Makefile
+++ b/Makefile
@@ -129,7 +129,7 @@ lintci:
 
 lintci-deps:
 	rm -f ./build/bin/golangci-lint
-	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.41.1
+	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.42.1
 
 clean:
 	env GO111MODULE=on go clean -cache
diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go
index f39e68e269..814dd000f2 100644
--- a/cmd/rpcdaemon/cli/config.go
+++ b/cmd/rpcdaemon/cli/config.go
@@ -69,7 +69,7 @@ var rootCmd = &cobra.Command{
 func RootCommand() (*cobra.Command, *Flags) {
 	utils.CobraFlags(rootCmd, append(debug.Flags, utils.MetricFlags...))
 
-	cfg := &Flags{}
+	cfg := &Flags{StateCache: kvcache.DefaultCoherentConfig}
 	rootCmd.PersistentFlags().StringVar(&cfg.PrivateApiAddr, "private.api.addr", "127.0.0.1:9090", "private api network address, for example: 127.0.0.1:9090")
 	rootCmd.PersistentFlags().StringVar(&cfg.Datadir, "datadir", "", "path to Erigon working directory")
 	rootCmd.PersistentFlags().StringVar(&cfg.Chaindata, "chaindata", "", "path to the database")
diff --git a/cmd/rpcdaemon/commands/eth_api.go b/cmd/rpcdaemon/commands/eth_api.go
index 78c03e0558..07ecbb8246 100644
--- a/cmd/rpcdaemon/commands/eth_api.go
+++ b/cmd/rpcdaemon/commands/eth_api.go
@@ -8,16 +8,15 @@ import (
 
 	lru "github.com/hashicorp/golang-lru"
 	"github.com/holiman/uint256"
+	"github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
 	"github.com/ledgerwatch/erigon-lib/kv"
 	"github.com/ledgerwatch/erigon-lib/kv/kvcache"
-	"github.com/ledgerwatch/erigon/consensus/misc"
-
-	"github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
 	"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
 	"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
 	"github.com/ledgerwatch/erigon/common"
 	"github.com/ledgerwatch/erigon/common/hexutil"
 	"github.com/ledgerwatch/erigon/common/math"
+	"github.com/ledgerwatch/erigon/consensus/misc"
 	"github.com/ledgerwatch/erigon/core/rawdb"
 	"github.com/ledgerwatch/erigon/core/types"
 	ethFilters "github.com/ledgerwatch/erigon/eth/filters"
@@ -110,10 +109,15 @@ type BaseAPI struct {
 }
 
 func NewBaseApi(f *filters.Filters, stateCache kvcache.Cache, singleNodeMode bool) *BaseAPI {
-	var blocksLRU *lru.Cache
+	blocksLRUSize := 128 // ~32Mb
 	if !singleNodeMode {
-		blocksLRU, _ = lru.New(256)
+		blocksLRUSize = 512
+	}
+	blocksLRU, err := lru.New(blocksLRUSize)
+	if err != nil {
+		panic(err)
 	}
+
 	return &BaseAPI{filters: f, stateCache: stateCache, blocksLRU: blocksLRU}
 }
 
diff --git a/cmd/rpcdaemon/commands/eth_call.go b/cmd/rpcdaemon/commands/eth_call.go
index 57052c7e19..28dba7ed53 100644
--- a/cmd/rpcdaemon/commands/eth_call.go
+++ b/cmd/rpcdaemon/commands/eth_call.go
@@ -18,6 +18,7 @@ import (
 	"github.com/ledgerwatch/erigon/internal/ethapi"
 	"github.com/ledgerwatch/erigon/params"
 	"github.com/ledgerwatch/erigon/rpc"
+	"github.com/ledgerwatch/erigon/turbo/rpchelper"
 	"github.com/ledgerwatch/erigon/turbo/transactions"
 	"github.com/ledgerwatch/log/v3"
 )
@@ -43,7 +44,20 @@ func (api *APIImpl) Call(ctx context.Context, args ethapi.CallArgs, blockNrOrHas
 	if api.TevmEnabled {
 		contractHasTEVM = ethdb.GetHasTEVM(tx)
 	}
-	result, err := transactions.DoCall(ctx, args, tx, blockNrOrHash, overrides, api.GasCap, chainConfig, api.filters, api.stateCache, contractHasTEVM)
+
+	blockNumber, hash, err := rpchelper.GetCanonicalBlockNumber(blockNrOrHash, tx, api.filters) // DoCall cannot be executed on non-canonical blocks
+	if err != nil {
+		return nil, err
+	}
+	block, err := api.BaseAPI.blockWithSenders(tx, hash, blockNumber)
+	if err != nil {
+		return nil, err
+	}
+	if block == nil {
+		return nil, nil
+	}
+
+	result, err := transactions.DoCall(ctx, args, tx, blockNrOrHash, block, overrides, api.GasCap, chainConfig, api.stateCache, contractHasTEVM)
 	if err != nil {
 		return nil, err
 	}
@@ -181,8 +195,21 @@ func (api *APIImpl) EstimateGas(ctx context.Context, args ethapi.CallArgs, block
 	executable := func(gas uint64) (bool, *core.ExecutionResult, error) {
 		args.Gas = (*hexutil.Uint64)(&gas)
 
-		result, err := transactions.DoCall(ctx, args, dbtx, rpc.BlockNumberOrHash{BlockNumber: &lastBlockNum}, nil,
-			api.GasCap, chainConfig, api.filters, api.stateCache, contractHasTEVM)
+		numOrHash := rpc.BlockNumberOrHash{BlockNumber: &lastBlockNum}
+		blockNumber, hash, err := rpchelper.GetCanonicalBlockNumber(numOrHash, dbtx, api.filters) // DoCall cannot be executed on non-canonical blocks
+		if err != nil {
+			return false, nil, err
+		}
+		block, err := api.BaseAPI.blockWithSenders(dbtx, hash, blockNumber)
+		if err != nil {
+			return false, nil, err
+		}
+		if block == nil {
+			return false, nil, nil
+		}
+
+		result, err := transactions.DoCall(ctx, args, dbtx, numOrHash, block, nil,
+			api.GasCap, chainConfig, api.stateCache, contractHasTEVM)
 		if err != nil {
 			if errors.Is(err, core.ErrIntrinsicGas) {
 				// Special case, raise gas limit
diff --git a/cmd/rpctest/main.go b/cmd/rpctest/main.go
index f00d5351dc..cb8a7d099c 100644
--- a/cmd/rpctest/main.go
+++ b/cmd/rpctest/main.go
@@ -22,6 +22,7 @@ func main() {
 		erigonURL   string
 		blockFrom   uint64
 		blockTo     uint64
+		latest      bool
 		recordFile  string
 		errorFile   string
 	)
@@ -35,6 +36,9 @@ func main() {
 		cmd.Flags().Uint64Var(&blockFrom, "blockFrom", 2000000, "Block number to start test generation from")
 		cmd.Flags().Uint64Var(&blockTo, "blockTo", 2101000, "Block number to end test generation at")
 	}
+	withLatest := func(cmd *cobra.Command) {
+		cmd.Flags().BoolVar(&latest, "latest", false, "Exec on latest ")
+	}
 	withNeedCompare := func(cmd *cobra.Command) {
 		cmd.Flags().BoolVar(&needCompare, "needCompare", false, "need compare with geth")
 	}
@@ -55,10 +59,10 @@ func main() {
 		Short: "",
 		Long:  ``,
 		Run: func(cmd *cobra.Command, args []string) {
-			rpctest.BenchEthCall(erigonURL, gethURL, needCompare, blockFrom, blockTo, recordFile, errorFile)
+			rpctest.BenchEthCall(erigonURL, gethURL, needCompare, latest, blockFrom, blockTo, recordFile, errorFile)
 		},
 	}
-	with(benchEthCallCmd, withErigonUrl, withGethUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile)
+	with(benchEthCallCmd, withErigonUrl, withGethUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile, withLatest)
 
 	var bench1Cmd = &cobra.Command{
 		Use:   "bench1",
diff --git a/cmd/rpctest/rpctest/bench_ethcall.go b/cmd/rpctest/rpctest/bench_ethcall.go
index 39a8b30acb..3358f98c59 100644
--- a/cmd/rpctest/rpctest/bench_ethcall.go
+++ b/cmd/rpctest/rpctest/bench_ethcall.go
@@ -15,7 +15,7 @@ import (
 // 		    false value - to generate vegeta files, it's faster but we can generate vegeta files for Geth and Erigon
 //                  recordFile stores all eth_call returned with success
 //                  errorFile stores information when erigon and geth doesn't return same data
-func BenchEthCall(erigonURL, gethURL string, needCompare bool, blockFrom uint64, blockTo uint64, recordFile string, errorFile string) {
+func BenchEthCall(erigonURL, gethURL string, needCompare, latest bool, blockFrom, blockTo uint64, recordFile string, errorFile string) {
 	setRoutes(erigonURL, gethURL)
 	var client = &http.Client{
 		Timeout: time.Second * 600,
@@ -103,7 +103,12 @@ func BenchEthCall(erigonURL, gethURL string, needCompare bool, blockFrom uint64,
 			reqGen.reqID++
 			nTransactions = nTransactions + 1
 
-			request := reqGen.ethCall(tx.From, tx.To, &tx.Gas, &tx.GasPrice, &tx.Value, tx.Input, bn-1)
+			var request string
+			if latest {
+				request = reqGen.ethCallLatest(tx.From, tx.To, &tx.Gas, &tx.GasPrice, &tx.Value, tx.Input)
+			} else {
+				request = reqGen.ethCall(tx.From, tx.To, &tx.Gas, &tx.GasPrice, &tx.Value, tx.Input, bn-1)
+			}
 			errCtx := fmt.Sprintf(" bn=%d hash=%s", bn, tx.Hash)
 
 			if err := requestAndCompare(request, "eth_call", errCtx, reqGen, needCompare, rec, errs, resultsCh); err != nil {
diff --git a/cmd/rpctest/rpctest/request_generator.go b/cmd/rpctest/rpctest/request_generator.go
index ece3bc4631..4dcbe3c4da 100644
--- a/cmd/rpctest/rpctest/request_generator.go
+++ b/cmd/rpctest/rpctest/request_generator.go
@@ -241,6 +241,28 @@ func (g *RequestGenerator) ethCall(from common.Address, to *common.Address, gas
 	return sb.String()
 }
 
+func (g *RequestGenerator) ethCallLatest(from common.Address, to *common.Address, gas *hexutil.Big, gasPrice *hexutil.Big, value *hexutil.Big, data hexutil.Bytes) string {
+	var sb strings.Builder
+	fmt.Fprintf(&sb, `{ "jsonrpc": "2.0", "method": "eth_call", "params": [{"from":"0x%x"`, from)
+	if to != nil {
+		fmt.Fprintf(&sb, `,"to":"0x%x"`, *to)
+	}
+	if gas != nil {
+		fmt.Fprintf(&sb, `,"gas":"%s"`, gas)
+	}
+	if gasPrice != nil {
+		fmt.Fprintf(&sb, `,"gasPrice":"%s"`, gasPrice)
+	}
+	if len(data) > 0 {
+		fmt.Fprintf(&sb, `,"data":"%s"`, data)
+	}
+	if value != nil {
+		fmt.Fprintf(&sb, `,"value":"%s"`, value)
+	}
+	fmt.Fprintf(&sb, `},"latest"], "id":%d}`, g.reqID)
+	return sb.String()
+}
+
 func (g *RequestGenerator) call(target string, method, body string, response interface{}) CallResult {
 	start := time.Now()
 	err := post(g.client, routes[target], body, response)
diff --git a/core/state/cached_reader2.go b/core/state/cached_reader2.go
index 1f841330c1..bb438a618c 100644
--- a/core/state/cached_reader2.go
+++ b/core/state/cached_reader2.go
@@ -25,7 +25,7 @@ func NewCachedReader2(cache kvcache.CacheView, tx kv.Tx) *CachedReader2 {
 
 // ReadAccountData is called when an account needs to be fetched from the state
 func (r *CachedReader2) ReadAccountData(address common.Address) (*accounts.Account, error) {
-	enc, err := r.cache.Get(address.Bytes())
+	enc, err := r.cache.Get(address[:])
 	if err != nil {
 		return nil, err
 	}
@@ -55,7 +55,7 @@ func (r *CachedReader2) ReadAccountCode(address common.Address, incarnation uint
 	if bytes.Equal(codeHash.Bytes(), emptyCodeHash) {
 		return nil, nil
 	}
-	code, err := r.db.GetOne(kv.Code, codeHash.Bytes())
+	code, err := r.cache.GetCode(codeHash.Bytes())
 	if len(code) == 0 {
 		return nil, nil
 	}
diff --git a/crypto/blake2b/blake2bAVX2_amd64.go b/crypto/blake2b/blake2bAVX2_amd64.go
index 0d52b18699..3a85d0e73a 100644
--- a/crypto/blake2b/blake2bAVX2_amd64.go
+++ b/crypto/blake2b/blake2bAVX2_amd64.go
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build go1.7 && amd64 && !gccgo && !appengine
 // +build go1.7,amd64,!gccgo,!appengine
 
 package blake2b
diff --git a/crypto/blake2b/register.go b/crypto/blake2b/register.go
index efd689af4b..9d8633963c 100644
--- a/crypto/blake2b/register.go
+++ b/crypto/blake2b/register.go
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+//go:build go1.9
 // +build go1.9
 
 package blake2b
diff --git a/crypto/bn256/bn256_fast.go b/crypto/bn256/bn256_fast.go
index 9e4935d370..e8b9a4adf3 100644
--- a/crypto/bn256/bn256_fast.go
+++ b/crypto/bn256/bn256_fast.go
@@ -2,6 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be found
 // in the LICENSE file.
 
+//go:build amd64 || arm64
 // +build amd64 arm64
 
 // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
diff --git a/crypto/bn256/cloudflare/gfp_decl.go b/crypto/bn256/cloudflare/gfp_decl.go
index be1b809063..652089de21 100644
--- a/crypto/bn256/cloudflare/gfp_decl.go
+++ b/crypto/bn256/cloudflare/gfp_decl.go
@@ -1,3 +1,4 @@
+//go:build (amd64 && !generic) || (arm64 && !generic)
 // +build amd64,!generic arm64,!generic
 
 package bn256
diff --git a/crypto/signature_cgo.go b/crypto/signature_cgo.go
index d7d895e498..3b7d0fd33f 100644
--- a/crypto/signature_cgo.go
+++ b/crypto/signature_cgo.go
@@ -14,6 +14,7 @@
 // You should have received a copy of the GNU Lesser General Public License
 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
 
+//go:build !nacl && !js && cgo && !gofuzz
 // +build !nacl,!js,cgo,!gofuzz
 
 package crypto
diff --git a/eth/backend.go b/eth/backend.go
index bde8a588b7..40475ad0e3 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -499,17 +499,19 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
 			}
 
 			if backend.config.TxPool.V2 {
-				if err := backend.txPool2DB.View(context.Background(), func(tx kv.Tx) error {
-					pendingBaseFee := misc.CalcBaseFee(chainConfig, hh)
-					return backend.txPool2.OnNewBlock(context.Background(), &remote.StateChangeBatch{
-						PendingBlockBaseFee: pendingBaseFee.Uint64(),
-						DatabaseViewID:      tx.ViewID(),
-						ChangeBatch: []*remote.StateChange{
-							{BlockHeight: hh.Number.Uint64(), BlockHash: gointerfaces.ConvertHashToH256(hh.Hash())},
-						},
-					}, txpool2.TxSlots{}, txpool2.TxSlots{}, tx)
-				}); err != nil {
-					return nil, err
+				if hh != nil {
+					if err := backend.txPool2DB.View(context.Background(), func(tx kv.Tx) error {
+						pendingBaseFee := misc.CalcBaseFee(chainConfig, hh)
+						return backend.txPool2.OnNewBlock(context.Background(), &remote.StateChangeBatch{
+							PendingBlockBaseFee: pendingBaseFee.Uint64(),
+							DatabaseViewID:      tx.ViewID(),
+							ChangeBatch: []*remote.StateChange{
+								{BlockHeight: hh.Number.Uint64(), BlockHash: gointerfaces.ConvertHashToH256(hh.Hash())},
+							},
+						}, txpool2.TxSlots{}, txpool2.TxSlots{}, tx)
+					}); err != nil {
+						return nil, err
+					}
 				}
 			} else {
 				if hh != nil {
diff --git a/ethdb/olddb/database_test.go b/ethdb/olddb/database_test.go
index 3294936571..de4987018c 100644
--- a/ethdb/olddb/database_test.go
+++ b/ethdb/olddb/database_test.go
@@ -14,6 +14,7 @@
 // You should have received a copy of the GNU Lesser General Public License
 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
 
+//go:build !js
 // +build !js
 
 package olddb
diff --git a/go.mod b/go.mod
index 9d52f8b4a2..e7d4be84d9 100644
--- a/go.mod
+++ b/go.mod
@@ -36,7 +36,7 @@ require (
 	github.com/json-iterator/go v1.1.12
 	github.com/julienschmidt/httprouter v1.3.0
 	github.com/kevinburke/go-bindata v3.21.0+incompatible
-	github.com/ledgerwatch/erigon-lib v0.0.0-20211011173149-083ee839067f
+	github.com/ledgerwatch/erigon-lib v0.0.0-20211012041733-a745f2391c49
 	github.com/ledgerwatch/log/v3 v3.3.1
 	github.com/ledgerwatch/secp256k1 v0.0.0-20210626115225-cd5cd00ed72d
 	github.com/logrusorgru/aurora/v3 v3.0.0
diff --git a/go.sum b/go.sum
index 2b25dce6aa..e51ccb946e 100644
--- a/go.sum
+++ b/go.sum
@@ -497,8 +497,8 @@ github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3P
 github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
 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-20211011173149-083ee839067f h1:gxkNMQ0Bx4+VzT83xMvKshvvSrD2tkz4pzLM/RBSyoQ=
-github.com/ledgerwatch/erigon-lib v0.0.0-20211011173149-083ee839067f/go.mod h1:kM8TzB/YifxKol66U0bNLsmdopypP+ag6REvUGU62s4=
+github.com/ledgerwatch/erigon-lib v0.0.0-20211012041733-a745f2391c49 h1:cpbGDRm6kkCvcZ9WjejziSTqgxRqYGvZcpIG5AmJxe8=
+github.com/ledgerwatch/erigon-lib v0.0.0-20211012041733-a745f2391c49/go.mod h1:kM8TzB/YifxKol66U0bNLsmdopypP+ag6REvUGU62s4=
 github.com/ledgerwatch/log/v3 v3.3.1 h1:HmvLeTEvtCtqSvtu4t/a5MAdcLfeBcbIeowXbLYuzLc=
 github.com/ledgerwatch/log/v3 v3.3.1/go.mod h1:S3VJqhhVX32rbp1JyyvhJou12twtFwNEPESBgpbNkRk=
 github.com/ledgerwatch/secp256k1 v0.0.0-20210626115225-cd5cd00ed72d h1:/IKMrJdfRsoYNc36PXqP4xMH3vhW/8IQyBKGQbKZUno=
diff --git a/internal/debug/loudpanic.go b/internal/debug/loudpanic.go
index 572ebcefa1..86e6bc88f8 100644
--- a/internal/debug/loudpanic.go
+++ b/internal/debug/loudpanic.go
@@ -14,6 +14,7 @@
 // You should have received a copy of the GNU Lesser General Public License
 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
 
+//go:build go1.6
 // +build go1.6
 
 package debug
diff --git a/internal/debug/signal.go b/internal/debug/signal.go
index 0f5f1e3849..a8380d59e4 100644
--- a/internal/debug/signal.go
+++ b/internal/debug/signal.go
@@ -1,3 +1,4 @@
+//go:build !windows
 // +build !windows
 
 package debug
diff --git a/internal/debug/trace.go b/internal/debug/trace.go
index 35d791ec25..367b5727e3 100644
--- a/internal/debug/trace.go
+++ b/internal/debug/trace.go
@@ -14,7 +14,8 @@
 // You should have received a copy of the GNU Lesser General Public License
 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
 
-//+build go1.5
+//go:build go1.5
+// +build go1.5
 
 package debug
 
diff --git a/metrics/cpu_enabled.go b/metrics/cpu_enabled.go
index f4e01cc67c..4996d0f7b7 100644
--- a/metrics/cpu_enabled.go
+++ b/metrics/cpu_enabled.go
@@ -14,6 +14,7 @@
 // You should have received a copy of the GNU Lesser General Public License
 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
 
+//go:build !ios
 // +build !ios
 
 package metrics
diff --git a/metrics/cpu_syscall.go b/metrics/cpu_syscall.go
index 4ec9c89671..ca74ff5fdd 100644
--- a/metrics/cpu_syscall.go
+++ b/metrics/cpu_syscall.go
@@ -14,6 +14,7 @@
 // You should have received a copy of the GNU Lesser General Public License
 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
 
+//go:build !windows
 // +build !windows
 
 package metrics
diff --git a/metrics/runtime_cgo.go b/metrics/runtime_cgo.go
index e3391f4e89..7d0af4f7e4 100644
--- a/metrics/runtime_cgo.go
+++ b/metrics/runtime_cgo.go
@@ -1,5 +1,5 @@
-// +build cgo
-// +build !appengine
+//go:build cgo && !appengine
+// +build cgo,!appengine
 
 package metrics
 
diff --git a/metrics/syslog.go b/metrics/syslog.go
index a0ed4b1b23..551a2bd0f0 100644
--- a/metrics/syslog.go
+++ b/metrics/syslog.go
@@ -1,3 +1,4 @@
+//go:build !windows
 // +build !windows
 
 package metrics
diff --git a/p2p/netutil/toobig_notwindows.go b/p2p/netutil/toobig_notwindows.go
index 47b6438572..f9f936ae56 100644
--- a/p2p/netutil/toobig_notwindows.go
+++ b/p2p/netutil/toobig_notwindows.go
@@ -14,7 +14,8 @@
 // You should have received a copy of the GNU Lesser General Public License
 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
 
-//+build !windows
+//go:build !windows
+// +build !windows
 
 package netutil
 
diff --git a/turbo/transactions/call.go b/turbo/transactions/call.go
index ea18b1f2b5..41364db832 100644
--- a/turbo/transactions/call.go
+++ b/turbo/transactions/call.go
@@ -9,7 +9,6 @@ import (
 	"github.com/holiman/uint256"
 	"github.com/ledgerwatch/erigon-lib/kv"
 	"github.com/ledgerwatch/erigon-lib/kv/kvcache"
-	"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
 	"github.com/ledgerwatch/erigon/common"
 	"github.com/ledgerwatch/erigon/core"
 	"github.com/ledgerwatch/erigon/core/rawdb"
@@ -19,15 +18,12 @@ import (
 	"github.com/ledgerwatch/erigon/internal/ethapi"
 	"github.com/ledgerwatch/erigon/params"
 	"github.com/ledgerwatch/erigon/rpc"
-	"github.com/ledgerwatch/erigon/turbo/rpchelper"
 	"github.com/ledgerwatch/log/v3"
 )
 
 const callTimeout = 5 * time.Minute
 
-func DoCall(ctx context.Context, args ethapi.CallArgs, tx kv.Tx, blockNrOrHash rpc.BlockNumberOrHash,
-	overrides *map[common.Address]ethapi.Account, gasCap uint64, chainConfig *params.ChainConfig,
-	filters *filters.Filters, stateCache kvcache.Cache, contractHasTEVM func(hash common.Hash) (bool, error)) (*core.ExecutionResult, error) {
+func DoCall(ctx context.Context, args ethapi.CallArgs, tx kv.Tx, blockNrOrHash rpc.BlockNumberOrHash, block *types.Block, overrides *map[common.Address]ethapi.Account, gasCap uint64, chainConfig *params.ChainConfig, stateCache kvcache.Cache, contractHasTEVM func(hash common.Hash) (bool, error)) (*core.ExecutionResult, error) {
 	// todo: Pending state is only known by the miner
 	/*
 		if blockNrOrHash.BlockNumber != nil && *blockNrOrHash.BlockNumber == rpc.PendingBlockNumber {
@@ -35,10 +31,7 @@ func DoCall(ctx context.Context, args ethapi.CallArgs, tx kv.Tx, blockNrOrHash r
 			return state, block.Header(), nil
 		}
 	*/
-	blockNumber, hash, err := rpchelper.GetCanonicalBlockNumber(blockNrOrHash, tx, filters) // DoCall cannot be executed on non-canonical blocks
-	if err != nil {
-		return nil, err
-	}
+	blockNumber := block.NumberU64()
 	var stateReader state.StateReader
 	if num, ok := blockNrOrHash.Number(); ok && num == rpc.LatestBlockNumber {
 		cacheView, err := stateCache.View(ctx, tx)
@@ -51,10 +44,7 @@ func DoCall(ctx context.Context, args ethapi.CallArgs, tx kv.Tx, blockNrOrHash r
 	}
 	state := state.New(stateReader)
 
-	header := rawdb.ReadHeader(tx, hash, blockNumber)
-	if header == nil {
-		return nil, fmt.Errorf("block %d(%x) not found", blockNumber, hash)
-	}
+	header := block.Header()
 
 	// Override the fields of specified contracts before execution.
 	if overrides != nil {
-- 
GitLab