From 8983128d24c67deb409bd7faa926651e8f55fe68 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Mon, 4 Sep 2023 12:42:08 +0700 Subject: [PATCH] Restore genesis reads code - remote rpc case. Remove ctx parameter from baseApi func (tx already has internal ctx) (#8122) --- go.mod | 4 +-- go.sum | 7 ++--- turbo/jsonrpc/debug_api.go | 12 ++++----- turbo/jsonrpc/erigon_receipts.go | 4 +-- turbo/jsonrpc/eth_api.go | 31 ++++++++++++----------- turbo/jsonrpc/eth_block.go | 12 ++++----- turbo/jsonrpc/eth_call.go | 6 ++--- turbo/jsonrpc/eth_callMany.go | 2 +- turbo/jsonrpc/eth_receipts.go | 6 ++--- turbo/jsonrpc/eth_system.go | 2 +- turbo/jsonrpc/eth_txs.go | 16 ++++++------ turbo/jsonrpc/eth_uncles.go | 8 +++--- turbo/jsonrpc/get_chain_config_test.go | 16 ++++-------- turbo/jsonrpc/otterscan_api.go | 4 +-- turbo/jsonrpc/otterscan_generic_tracer.go | 2 +- turbo/jsonrpc/trace_adhoc.go | 12 ++++----- turbo/jsonrpc/trace_filtering.go | 8 +++--- turbo/jsonrpc/tracing.go | 10 ++++---- 18 files changed, 79 insertions(+), 83 deletions(-) diff --git a/go.mod b/go.mod index 74c96c45734..143236b3ad0 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/erigontech/mdbx-go v0.27.14 - github.com/ledgerwatch/erigon-lib v0.0.0-20230901170341-82448e2edeae + github.com/ledgerwatch/erigon-lib v0.0.0-20230904034409-568d783b0d85 github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230818153427-cc16b83a89be github.com/ledgerwatch/log/v3 v3.9.0 github.com/ledgerwatch/secp256k1 v1.0.0 @@ -91,7 +91,7 @@ require ( golang.org/x/exp v0.0.0-20230711023510-fffb14384f22 golang.org/x/net v0.14.0 golang.org/x/sync v0.3.0 - golang.org/x/sys v0.11.0 + golang.org/x/sys v0.12.0 golang.org/x/time v0.3.0 google.golang.org/grpc v1.57.0 google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 diff --git a/go.sum b/go.sum index cde1240d795..818e58ce5ba 100644 --- a/go.sum +++ b/go.sum @@ -497,8 +497,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-20230901170341-82448e2edeae h1:S5OnGA5Jrs/y2zZUv2j9DBnVxBF1yylb34ufUUxG2go= -github.com/ledgerwatch/erigon-lib v0.0.0-20230901170341-82448e2edeae/go.mod h1:wWs9yVYGm1mDFb+Qnh7Qun1MIX6cP5vp4PAfOjnvm+g= +github.com/ledgerwatch/erigon-lib v0.0.0-20230904034409-568d783b0d85 h1:PvSsOmri3fLl9BfvcuslVcaQDXBTJkzs56t1xj1nnis= +github.com/ledgerwatch/erigon-lib v0.0.0-20230904034409-568d783b0d85/go.mod h1:VLDj7l088dUzwBBSORGy5GGdUPM8XhLNMURmm1F1QMA= github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230818153427-cc16b83a89be h1:6/4MXkk5AoKUHivIpCokHOX/WV9L7tXgURp1k8KfmSM= github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230818153427-cc16b83a89be/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk= @@ -1129,8 +1129,9 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= diff --git a/turbo/jsonrpc/debug_api.go b/turbo/jsonrpc/debug_api.go index 0105aea187f..ab91c40a0a8 100644 --- a/turbo/jsonrpc/debug_api.go +++ b/turbo/jsonrpc/debug_api.go @@ -82,7 +82,7 @@ func (api *PrivateDebugAPIImpl) StorageRangeAt(ctx context.Context, blockHash co return storageRangeAtV3(tx.(kv.TemporalTx), contractAddress, keyStart, minTxNum+txIndex, maxResult) } - block, err := api.blockByHashWithSenders(ctx, tx, blockHash) + block, err := api.blockByHashWithSenders(tx, blockHash) if err != nil { return StorageRangeResult{}, err } @@ -123,7 +123,7 @@ func (api *PrivateDebugAPIImpl) AccountRange(ctx context.Context, blockNrOrHash } } else if hash, ok := blockNrOrHash.Hash(); ok { - block, err1 := api.blockByHashWithSenders(ctx, tx, hash) + block, err1 := api.blockByHashWithSenders(tx, hash) if err1 != nil { return state.IteratorDump{}, err1 } @@ -243,7 +243,7 @@ func (api *PrivateDebugAPIImpl) GetModifiedAccountsByHash(ctx context.Context, s } defer tx.Rollback() - startBlock, err := api.blockByHashWithSenders(ctx, tx, startHash) + startBlock, err := api.blockByHashWithSenders(tx, startHash) if err != nil { return nil, err } @@ -254,7 +254,7 @@ func (api *PrivateDebugAPIImpl) GetModifiedAccountsByHash(ctx context.Context, s endNum := startNum + 1 // allows for single parameter calls if endHash != nil { - endBlock, err := api.blockByHashWithSenders(ctx, tx, *endHash) + endBlock, err := api.blockByHashWithSenders(tx, *endHash) if err != nil { return nil, err } @@ -337,7 +337,7 @@ func (api *PrivateDebugAPIImpl) AccountAt(ctx context.Context, blockHash common. } engine := api.engine() - block, err := api.blockByHashWithSenders(ctx, tx, blockHash) + block, err := api.blockByHashWithSenders(tx, blockHash) if err != nil { return nil, err } @@ -393,7 +393,7 @@ func (api *PrivateDebugAPIImpl) GetRawBlock(ctx context.Context, blockNrOrHash r if err != nil { return nil, err } - block, err := api.blockWithSenders(ctx, tx, h, n) + block, err := api.blockWithSenders(tx, h, n) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/erigon_receipts.go b/turbo/jsonrpc/erigon_receipts.go index a3c77818852..71d8bcba794 100644 --- a/turbo/jsonrpc/erigon_receipts.go +++ b/turbo/jsonrpc/erigon_receipts.go @@ -33,7 +33,7 @@ func (api *ErigonImpl) GetLogsByHash(ctx context.Context, hash common.Hash) ([][ return nil, err } - block, err := api.blockByHashWithSenders(ctx, tx, hash) + block, err := api.blockByHashWithSenders(tx, hash) if err != nil { return nil, err } @@ -381,7 +381,7 @@ func (api *ErigonImpl) GetBlockReceiptsByBlockHash(ctx context.Context, cannonic if err != nil { return nil, err } - block, err := api.blockWithSenders(ctx, tx, cannonicalBlockHash, blockNum) + block, err := api.blockWithSenders(tx, cannonicalBlockHash, blockNum) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_api.go b/turbo/jsonrpc/eth_api.go index 9030d489938..518918e19bf 100644 --- a/turbo/jsonrpc/eth_api.go +++ b/turbo/jsonrpc/eth_api.go @@ -153,19 +153,19 @@ func (api *BaseAPI) genesis(tx kv.Tx) (*types.Block, error) { return genesis, err } -func (api *BaseAPI) txnLookup(ctx context.Context, tx kv.Tx, txnHash common.Hash) (uint64, bool, error) { - return api._txnReader.TxnLookup(ctx, tx, txnHash) +func (api *BaseAPI) txnLookup(tx kv.Tx, txnHash common.Hash) (uint64, bool, error) { + return api._txnReader.TxnLookup(context.Background(), tx, txnHash) } -func (api *BaseAPI) blockByNumberWithSenders(ctx context.Context, tx kv.Tx, number uint64) (*types.Block, error) { - hash, hashErr := api._blockReader.CanonicalHash(ctx, tx, number) +func (api *BaseAPI) blockByNumberWithSenders(tx kv.Tx, number uint64) (*types.Block, error) { + hash, hashErr := api._blockReader.CanonicalHash(context.Background(), tx, number) if hashErr != nil { return nil, hashErr } - return api.blockWithSenders(ctx, tx, hash, number) + return api.blockWithSenders(tx, hash, number) } -func (api *BaseAPI) blockByHashWithSenders(ctx context.Context, tx kv.Tx, hash common.Hash) (*types.Block, error) { +func (api *BaseAPI) blockByHashWithSenders(tx kv.Tx, hash common.Hash) (*types.Block, error) { if api.blocksLRU != nil { if it, ok := api.blocksLRU.Get(hash); ok && it != nil { return it, nil @@ -176,16 +176,16 @@ func (api *BaseAPI) blockByHashWithSenders(ctx context.Context, tx kv.Tx, hash c return nil, nil } - return api.blockWithSenders(ctx, tx, hash, *number) + return api.blockWithSenders(tx, hash, *number) } -func (api *BaseAPI) blockWithSenders(ctx context.Context, tx kv.Tx, hash common.Hash, number uint64) (*types.Block, error) { +func (api *BaseAPI) blockWithSenders(tx kv.Tx, hash common.Hash, number uint64) (*types.Block, error) { if api.blocksLRU != nil { if it, ok := api.blocksLRU.Get(hash); ok && it != nil { return it, nil } } - block, _, err := api._blockReader.BlockWithSenders(ctx, tx, hash, number) + block, _, err := api._blockReader.BlockWithSenders(context.Background(), tx, hash, number) if err != nil { return nil, err } @@ -228,14 +228,14 @@ func (api *BaseAPI) chainConfigWithGenesis(tx kv.Tx) (*chain.Config, *types.Bloc return cc, genesisBlock, nil } - hash, err := rawdb.ReadCanonicalHash(tx, 0) + genesisBlock, err := api.blockByRPCNumber(0, tx) if err != nil { return nil, nil, err } - if err != nil { - return nil, nil, err + if genesisBlock == nil { + return nil, nil, fmt.Errorf("genesis block not found in database") } - cc, err = rawdb.ReadChainConfig(tx, hash) + cc, err = rawdb.ReadChainConfig(tx, genesisBlock.Hash()) if err != nil { return nil, nil, err } @@ -250,13 +250,14 @@ func (api *BaseAPI) pendingBlock() *types.Block { return api.filters.LastPendingBlock() } -func (api *BaseAPI) blockByRPCNumber(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Block, error) { +func (api *BaseAPI) blockByRPCNumber(number rpc.BlockNumber, tx kv.Tx) (*types.Block, error) { n, h, _, err := rpchelper.GetBlockNumber(rpc.BlockNumberOrHashWithNumber(number), tx, api.filters) if err != nil { return nil, err } - block, err := api.blockWithSenders(ctx, tx, h, n) + // it's ok to use context.Background(), because in "Remote RPCDaemon" `tx` already contains internal ctx + block, err := api.blockWithSenders(tx, h, n) return block, err } diff --git a/turbo/jsonrpc/eth_block.go b/turbo/jsonrpc/eth_block.go index 1e1bb36e2b8..23f5fdb1910 100644 --- a/turbo/jsonrpc/eth_block.go +++ b/turbo/jsonrpc/eth_block.go @@ -46,14 +46,14 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat var txs types.Transactions for _, txHash := range txHashes { - blockNum, ok, err := api.txnLookup(ctx, tx, txHash) + blockNum, ok, err := api.txnLookup(tx, txHash) if err != nil { return nil, err } if !ok { return nil, nil } - block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) + block, err := api.blockByNumberWithSenders(tx, blockNum) if err != nil { return nil, err } @@ -261,7 +261,7 @@ func (api *APIImpl) GetBlockByHash(ctx context.Context, numberOrHash rpc.BlockNu additionalFields := make(map[string]interface{}) - block, err := api.blockByHashWithSenders(ctx, tx, hash) + block, err := api.blockByHashWithSenders(tx, hash) if err != nil { return nil, err } @@ -313,7 +313,7 @@ func (api *APIImpl) GetBlockTransactionCountByNumber(ctx context.Context, blockN defer tx.Rollback() if blockNr == rpc.PendingBlockNumber { - b, err := api.blockByRPCNumber(ctx, blockNr, tx) + b, err := api.blockByRPCNumber(blockNr, tx) if err != nil { return nil, err } @@ -372,7 +372,7 @@ func (api *APIImpl) GetBlockTransactionCountByHash(ctx context.Context, blockHas func (api *APIImpl) blockByNumber(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Block, error) { if number != rpc.PendingBlockNumber { - return api.blockByRPCNumber(ctx, number, tx) + return api.blockByRPCNumber(number, tx) } if block := api.pendingBlock(); block != nil { @@ -387,5 +387,5 @@ func (api *APIImpl) blockByNumber(ctx context.Context, number rpc.BlockNumber, t return block, nil } - return api.blockByRPCNumber(ctx, number, tx) + return api.blockByRPCNumber(number, tx) } diff --git a/turbo/jsonrpc/eth_call.go b/turbo/jsonrpc/eth_call.go index 4efff9c1d98..ac66c1efd91 100644 --- a/turbo/jsonrpc/eth_call.go +++ b/turbo/jsonrpc/eth_call.go @@ -59,7 +59,7 @@ func (api *APIImpl) Call(ctx context.Context, args ethapi2.CallArgs, blockNrOrHa if err != nil { return nil, err } - block, err := api.blockWithSenders(ctx, tx, hash, blockNumber) + block, err := api.blockWithSenders(tx, hash, blockNumber) if err != nil { return nil, err } @@ -234,7 +234,7 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs // try and get the block from the lru cache first then try DB before failing block := api.tryBlockFromLru(latestCanHash) if block == nil { - block, err = api.blockWithSenders(ctx, dbtx, latestCanHash, latestCanBlockNumber) + block, err = api.blockWithSenders(dbtx, latestCanHash, latestCanBlockNumber) if err != nil { return 0, err } @@ -449,7 +449,7 @@ func (api *APIImpl) CreateAccessList(ctx context.Context, args ethapi2.CallArgs, if err != nil { return nil, err } - block, err := api.blockWithSenders(ctx, tx, hash, blockNumber) + block, err := api.blockWithSenders(tx, hash, blockNumber) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_callMany.go b/turbo/jsonrpc/eth_callMany.go index e8df8118f7a..ccf3c7ad442 100644 --- a/turbo/jsonrpc/eth_callMany.go +++ b/turbo/jsonrpc/eth_callMany.go @@ -111,7 +111,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont return nil, err } - block, err := api.blockWithSenders(ctx, tx, hash, blockNum) + block, err := api.blockWithSenders(tx, hash, blockNum) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_receipts.go b/turbo/jsonrpc/eth_receipts.go index d374815c3d2..cd8ec361c50 100644 --- a/turbo/jsonrpc/eth_receipts.go +++ b/turbo/jsonrpc/eth_receipts.go @@ -590,7 +590,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha var blockNum uint64 var ok bool - blockNum, ok, err = api.txnLookup(ctx, tx, txnHash) + blockNum, ok, err = api.txnLookup(tx, txnHash) if err != nil { return nil, err } @@ -618,7 +618,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha blockNum = *blockNumPtr } - block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) + block, err := api.blockByNumberWithSenders(tx, blockNum) if err != nil { return nil, err } @@ -679,7 +679,7 @@ func (api *APIImpl) GetBlockReceipts(ctx context.Context, numberOrHash rpc.Block if err != nil { return nil, err } - block, err := api.blockWithSenders(ctx, tx, blockHash, blockNum) + block, err := api.blockWithSenders(tx, blockHash, blockNum) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_system.go b/turbo/jsonrpc/eth_system.go index c67c189f5d9..e0f59067f4e 100644 --- a/turbo/jsonrpc/eth_system.go +++ b/turbo/jsonrpc/eth_system.go @@ -215,7 +215,7 @@ func (b *GasPriceOracleBackend) HeaderByNumber(ctx context.Context, number rpc.B return header, nil } func (b *GasPriceOracleBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { - return b.baseApi.blockByRPCNumber(ctx, number, b.tx) + return b.baseApi.blockByRPCNumber(number, b.tx) } func (b *GasPriceOracleBackend) ChainConfig() *chain.Config { return b.cc diff --git a/turbo/jsonrpc/eth_txs.go b/turbo/jsonrpc/eth_txs.go index 29c4ce93440..d2086c1b38c 100644 --- a/turbo/jsonrpc/eth_txs.go +++ b/turbo/jsonrpc/eth_txs.go @@ -32,7 +32,7 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has } // https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByHash - blockNum, ok, err := api.txnLookup(ctx, tx, txnHash) + blockNum, ok, err := api.txnLookup(tx, txnHash) if err != nil { return nil, err } @@ -45,7 +45,7 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has fmt.Printf("Found block num %d, ok %t\n", blockNum, ok) } if ok { - block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) + block, err := api.blockByNumberWithSenders(tx, blockNum) if err != nil { return nil, err } @@ -118,14 +118,14 @@ func (api *APIImpl) GetRawTransactionByHash(ctx context.Context, hash common.Has defer tx.Rollback() // https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByHash - blockNum, ok, err := api.txnLookup(ctx, tx, hash) + blockNum, ok, err := api.txnLookup(tx, hash) if err != nil { return nil, err } if !ok { return nil, nil } - block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) + block, err := api.blockByNumberWithSenders(tx, blockNum) if err != nil { return nil, err } @@ -170,7 +170,7 @@ func (api *APIImpl) GetTransactionByBlockHashAndIndex(ctx context.Context, block } // https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByBlockHashAndIndex - block, err := api.blockByHashWithSenders(ctx, tx, blockHash) + block, err := api.blockByHashWithSenders(tx, blockHash) if err != nil { return nil, err } @@ -205,7 +205,7 @@ func (api *APIImpl) GetRawTransactionByBlockHashAndIndex(ctx context.Context, bl defer tx.Rollback() // https://infura.io/docs/ethereum/json-rpc/eth-getRawTransactionByBlockHashAndIndex - block, err := api.blockByHashWithSenders(ctx, tx, blockHash) + block, err := api.blockByHashWithSenders(tx, blockHash) if err != nil { return nil, err } @@ -234,7 +234,7 @@ func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blo return nil, err } - block, err := api.blockWithSenders(ctx, tx, hash, blockNum) + block, err := api.blockWithSenders(tx, hash, blockNum) if err != nil { return nil, err } @@ -269,7 +269,7 @@ func (api *APIImpl) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, defer tx.Rollback() // https://infura.io/docs/ethereum/json-rpc/eth-getRawTransactionByBlockNumberAndIndex - block, err := api.blockByRPCNumber(ctx, blockNr, tx) + block, err := api.blockByRPCNumber(blockNr, tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_uncles.go b/turbo/jsonrpc/eth_uncles.go index e9532cb7e39..b5a75666a75 100644 --- a/turbo/jsonrpc/eth_uncles.go +++ b/turbo/jsonrpc/eth_uncles.go @@ -26,7 +26,7 @@ func (api *APIImpl) GetUncleByBlockNumberAndIndex(ctx context.Context, number rp if err != nil { return nil, err } - block, err := api.blockWithSenders(ctx, tx, hash, blockNum) + block, err := api.blockWithSenders(tx, hash, blockNum) if err != nil { return nil, err } @@ -57,7 +57,7 @@ func (api *APIImpl) GetUncleByBlockHashAndIndex(ctx context.Context, hash common } defer tx.Rollback() - block, err := api.blockByHashWithSenders(ctx, tx, hash) + block, err := api.blockByHashWithSenders(tx, hash) if err != nil { return nil, err } @@ -97,7 +97,7 @@ func (api *APIImpl) GetUncleCountByBlockNumber(ctx context.Context, number rpc.B return &n, err } - block, err := api.blockWithSenders(ctx, tx, blockHash, blockNum) + block, err := api.blockWithSenders(tx, blockHash, blockNum) if err != nil { return nil, err } @@ -122,7 +122,7 @@ func (api *APIImpl) GetUncleCountByBlockHash(ctx context.Context, hash common.Ha return nil, nil // not error, see https://github.com/ledgerwatch/erigon/issues/1645 } - block, err := api.blockWithSenders(ctx, tx, hash, *number) + block, err := api.blockWithSenders(tx, hash, *number) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/get_chain_config_test.go b/turbo/jsonrpc/get_chain_config_test.go index f1934b495ff..af406fe70d5 100644 --- a/turbo/jsonrpc/get_chain_config_test.go +++ b/turbo/jsonrpc/get_chain_config_test.go @@ -2,20 +2,15 @@ package jsonrpc import ( "context" + "github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest" "testing" - - "github.com/ledgerwatch/erigon-lib/common/datadir" - "github.com/ledgerwatch/erigon/core" - "github.com/ledgerwatch/erigon/core/state/temporal" - "github.com/ledgerwatch/log/v3" ) func TestGetChainConfig(t *testing.T) { - _, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil) - config, _, err := core.CommitGenesisBlock(db, core.MainnetGenesisBlock(), "", log.New()) - if err != nil { - t.Fatalf("setting up genensis block: %v", err) - } + m, _, _ := rpcdaemontest.CreateTestSentry(t) + db := m.DB + api := newBaseApiForTest(m) + config := m.ChainConfig tx, txErr := db.BeginRo(context.Background()) if txErr != nil { @@ -23,7 +18,6 @@ func TestGetChainConfig(t *testing.T) { } defer tx.Rollback() - api := &BaseAPI{} config1, err1 := api.chainConfig(tx) if err1 != nil { t.Fatalf("reading chain config: %v", err1) diff --git a/turbo/jsonrpc/otterscan_api.go b/turbo/jsonrpc/otterscan_api.go index 43573b5f49e..b6b9f2757f2 100644 --- a/turbo/jsonrpc/otterscan_api.go +++ b/turbo/jsonrpc/otterscan_api.go @@ -75,7 +75,7 @@ func (api *OtterscanAPIImpl) GetApiLevel() uint8 { // TODO: dedup from eth_txs.go#GetTransactionByHash func (api *OtterscanAPIImpl) getTransactionByHash(ctx context.Context, tx kv.Tx, hash common.Hash) (types.Transaction, *types.Block, common.Hash, uint64, uint64, error) { // https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByHash - blockNum, ok, err := api.txnLookup(ctx, tx, hash) + blockNum, ok, err := api.txnLookup(tx, hash) if err != nil { return nil, nil, common.Hash{}, 0, 0, err } @@ -83,7 +83,7 @@ func (api *OtterscanAPIImpl) getTransactionByHash(ctx context.Context, tx kv.Tx, return nil, nil, common.Hash{}, 0, 0, nil } - block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) + block, err := api.blockByNumberWithSenders(tx, blockNum) if err != nil { return nil, nil, common.Hash{}, 0, 0, err } diff --git a/turbo/jsonrpc/otterscan_generic_tracer.go b/turbo/jsonrpc/otterscan_generic_tracer.go index dc62e52ae99..7309f258457 100644 --- a/turbo/jsonrpc/otterscan_generic_tracer.go +++ b/turbo/jsonrpc/otterscan_generic_tracer.go @@ -72,7 +72,7 @@ func (api *OtterscanAPIImpl) genericTracer(dbtx kv.Tx, ctx context.Context, bloc return h } engine := api.engine() - block, err := api.blockByNumberWithSenders(ctx, dbtx, blockNum) + block, err := api.blockByNumberWithSenders(dbtx, blockNum) if err != nil { return err } diff --git a/turbo/jsonrpc/trace_adhoc.go b/turbo/jsonrpc/trace_adhoc.go index ea181400b33..b47da577b36 100644 --- a/turbo/jsonrpc/trace_adhoc.go +++ b/turbo/jsonrpc/trace_adhoc.go @@ -726,7 +726,7 @@ func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash libcommon return nil, err } - blockNum, ok, err := api.txnLookup(ctx, tx, txHash) + blockNum, ok, err := api.txnLookup(tx, txHash) if err != nil { return nil, err } @@ -744,7 +744,7 @@ func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash libcommon } blockNum = *blockNumPtr } - block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) + block, err := api.blockByNumberWithSenders(tx, blockNum) if err != nil { return nil, err } @@ -821,7 +821,7 @@ func (api *TraceAPIImpl) ReplayBlockTransactions(ctx context.Context, blockNrOrH } // Extract transactions from block - block, bErr := api.blockWithSenders(ctx, tx, blockHash, blockNumber) + block, bErr := api.blockWithSenders(tx, blockHash, blockNumber) if bErr != nil { return nil, bErr } @@ -903,7 +903,7 @@ func (api *TraceAPIImpl) Call(ctx context.Context, args TraceCallParam, traceTyp ibs := state.New(stateReader) - block, err := api.blockWithSenders(ctx, tx, hash, blockNumber) + block, err := api.blockWithSenders(tx, hash, blockNumber) if err != nil { return nil, err } @@ -1065,7 +1065,7 @@ func (api *TraceAPIImpl) CallMany(ctx context.Context, calls json.RawMessage, pa } // TODO: can read here only parent header - parentBlock, err := api.blockWithSenders(ctx, dbtx, hash, blockNumber) + parentBlock, err := api.blockWithSenders(dbtx, hash, blockNumber) if err != nil { return nil, err } @@ -1119,7 +1119,7 @@ func (api *TraceAPIImpl) doCallMany(ctx context.Context, dbtx kv.Tx, msgs []type ibs := state.New(cachedReader) // TODO: can read here only parent header - parentBlock, err := api.blockWithSenders(ctx, dbtx, hash, blockNumber) + parentBlock, err := api.blockWithSenders(dbtx, hash, blockNumber) if err != nil { return nil, nil, err } diff --git a/turbo/jsonrpc/trace_filtering.go b/turbo/jsonrpc/trace_filtering.go index df31a3c9b4e..fea909acad9 100644 --- a/turbo/jsonrpc/trace_filtering.go +++ b/turbo/jsonrpc/trace_filtering.go @@ -48,7 +48,7 @@ func (api *TraceAPIImpl) Transaction(ctx context.Context, txHash common.Hash, ga return nil, err } - blockNumber, ok, err := api.txnLookup(ctx, tx, txHash) + blockNumber, ok, err := api.txnLookup(tx, txHash) if err != nil { return nil, err } @@ -66,7 +66,7 @@ func (api *TraceAPIImpl) Transaction(ctx context.Context, txHash common.Hash, ga } blockNumber = *blockNumPtr } - block, err := api.blockByNumberWithSenders(ctx, tx, blockNumber) + block, err := api.blockByNumberWithSenders(tx, blockNumber) if err != nil { return nil, err } @@ -168,7 +168,7 @@ func (api *TraceAPIImpl) Block(ctx context.Context, blockNr rpc.BlockNumber, gas bn := hexutil.Uint64(blockNum) // Extract transactions from block - block, bErr := api.blockWithSenders(ctx, tx, hash, blockNum) + block, bErr := api.blockWithSenders(tx, hash, blockNum) if bErr != nil { return nil, bErr } @@ -388,7 +388,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, gas for it.HasNext() { b := it.Next() // Extract transactions from block - block, bErr := api.blockByNumberWithSenders(ctx, dbtx, b) + block, bErr := api.blockByNumberWithSenders(dbtx, b) if bErr != nil { if first { first = false diff --git a/turbo/jsonrpc/tracing.go b/turbo/jsonrpc/tracing.go index b9c9ec5fcc2..ead8a094f95 100644 --- a/turbo/jsonrpc/tracing.go +++ b/turbo/jsonrpc/tracing.go @@ -52,9 +52,9 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp hashOk bool ) if number, numberOk = blockNrOrHash.Number(); numberOk { - block, err = api.blockByRPCNumber(ctx, number, tx) + block, err = api.blockByRPCNumber(number, tx) } else if hash, hashOk = blockNrOrHash.Hash(); hashOk { - block, err = api.blockByHashWithSenders(ctx, tx, hash) + block, err = api.blockByHashWithSenders(tx, hash) } else { return fmt.Errorf("invalid arguments; neither block nor hash specified") } @@ -181,7 +181,7 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo return err } // Retrieve the transaction and assemble its EVM context - blockNum, ok, err := api.txnLookup(ctx, tx, hash) + blockNum, ok, err := api.txnLookup(tx, hash) if err != nil { stream.WriteNil() return err @@ -211,7 +211,7 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo } blockNum = *blockNumPtr } - block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) + block, err := api.blockByNumberWithSenders(tx, blockNum) if err != nil { stream.WriteNil() return err @@ -371,7 +371,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun return err } - block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) + block, err := api.blockByNumberWithSenders(tx, blockNum) if err != nil { stream.WriteNil() return err