From fa1ce73cb2602998b1adeeb3cfaebdd2e97dc1d6 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 11:28:47 +0700 Subject: [PATCH 01/14] enable http for 1 request --- cmd/rpcdaemon/README.md | 67 ++++++++++++------- cmd/rpcdaemon/cli/config.go | 1 + cmd/rpcdaemon/cli/httpcfg/http_cfg.go | 3 +- cmd/utils/flags.go | 4 ++ erigon-lib/common/dbg/dbg_ctx.go | 23 +++++++ rpc/http.go | 4 ++ turbo/cli/default_flags.go | 1 + turbo/cli/flags.go | 1 + .../snapshotsync/freezeblocks/block_reader.go | 39 ++++++++++- 9 files changed, 116 insertions(+), 27 deletions(-) create mode 100644 erigon-lib/common/dbg/dbg_ctx.go diff --git a/cmd/rpcdaemon/README.md b/cmd/rpcdaemon/README.md index 79833756911..89f259e3ab1 100644 --- a/cmd/rpcdaemon/README.md +++ b/cmd/rpcdaemon/README.md @@ -1,21 +1,21 @@ - [Introduction](#introduction) - [Getting Started](#getting-started) - - [Running locally](#running-locally) - - [Running remotely](#running-remotely) - - [Healthcheck](#healthcheck) - - [Testing](#testing) + - [Running locally](#running-locally) + - [Running remotely](#running-remotely) + - [Healthcheck](#healthcheck) + - [Testing](#testing) - [FAQ](#faq) - - [Relations between prune options and rpc methods](#relations-between-prune-options-and-rpc-method) - - [RPC Implementation Status](#rpc-implementation-status) - - [Securing the communication between RPC daemon and Erigon instance via TLS and authentication](#securing-the-communication-between-rpc-daemon-and-erigon-instance-via-tls-and-authentication) - - [Ethstats](#ethstats) - - [Allowing only specific methods (Allowlist)](#allowing-only-specific-methods--allowlist-) - - [Trace transactions progress](#trace-transactions-progress) - - [Clients getting timeout, but server load is low](#clients-getting-timeout--but-server-load-is-low) - - [Server load too high](#server-load-too-high) - - [Faster Batch requests](#faster-batch-requests) + - [Relations between prune options and rpc methods](#relations-between-prune-options-and-rpc-method) + - [RPC Implementation Status](#rpc-implementation-status) + - [Securing the communication between RPC daemon and Erigon instance via TLS and authentication](#securing-the-communication-between-rpc-daemon-and-erigon-instance-via-tls-and-authentication) + - [Ethstats](#ethstats) + - [Allowing only specific methods (Allowlist)](#allowing-only-specific-methods--allowlist-) + - [Trace transactions progress](#trace-transactions-progress) + - [Clients getting timeout, but server load is low](#clients-getting-timeout--but-server-load-is-low) + - [Server load too high](#server-load-too-high) + - [Faster Batch requests](#faster-batch-requests) - [For Developers](#for-developers) - - [Code generation](#code-generation) + - [Code generation](#code-generation) ## Introduction @@ -72,7 +72,8 @@ it may scale well for some workloads that are heavy on the current state queries ### Healthcheck -There are 2 options for running healtchecks, POST request, or GET request with custom headers. Both options are available +There are 2 options for running healtchecks, POST request, or GET request with custom headers. Both options are +available at the `/health` endpoint. #### POST request @@ -172,6 +173,14 @@ Also, there are [extensive instructions for using Postman](https://github.com/ledgerwatch/erigon/wiki/Using-Postman-to-Test-TurboGeth-RPC) to test the RPC. +### Debugging + +Add `--rpc.dbg=true` flag, then can send header "dbg: true": + +``` +curl -X POST -H "dbg: true" -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id":1}' localhost:8545 +``` + ## FAQ ### Relations between prune options and RPC methods @@ -191,7 +200,8 @@ Some methods, if not found historical data in DB, can fallback to old blocks re- ### The --http.url flag -the `--http.url` flag is an optional flag which allows one to bind the HTTP server to a socket, for example, `tcp6://:8545` or `unix:///erigon_http.socket` +the `--http.url` flag is an optional flag which allows one to bind the HTTP server to a socket, for +example, `tcp6://:8545` or `unix:///erigon_http.socket` If the `--http.url` flag is set, then `--http.addr` and `--http.port` with both be ignored. @@ -201,11 +211,13 @@ note that this is NOT geth-style IPC. for that, read the next section, IPC endpo Erigon supports HTTPS, HTTP2, and H2C out of the box. H2C is served by the default HTTP handler. -To enable the HTTPS+HTTP2 server, add flag `--https.enabled`, along with providing flags `-https.cert="/path/to.cert"` and `--https.key=/path/to.key` +To enable the HTTPS+HTTP2 server, add flag `--https.enabled`, along with providing flags `-https.cert="/path/to.cert"` +and `--https.key=/path/to.key` By default, the HTTPS server will run on the HTTP port + 363. use flag `--https.port` to set the port -The HTTPS server will inherit all other configuration parameters from http, for instance, enabling the websocket server, cors domains, or enabled namespaces +The HTTPS server will inherit all other configuration parameters from http, for instance, enabling the websocket server, +cors domains, or enabled namespaces If the `--https.url` flag is set, then `--https.addr` and `--https.port` with both be ignored. @@ -226,7 +238,7 @@ Label "remote" means: `--private.api.addr` flag is required. The following table shows the current implementation status of Erigon's RPC daemon. | Command | Avail | Notes | -| ------------------------------------------ | ------- | ------------------------------------ | +|--------------------------------------------|---------|--------------------------------------| | admin_nodeInfo | Yes | | | admin_peers | Yes | | | admin_addPeer | Yes | | @@ -374,7 +386,7 @@ The following table shows the current implementation status of Erigon's RPC daem ### GraphQL | Command | Avail | Notes | -| --------------- | ----- | ----- | +|-----------------|-------|-------| | GetBlockDetails | Yes | | | GetChainID | Yes | | @@ -503,9 +515,15 @@ Then update your `app.json` for ethstats-client like that: "RPC_PORT": "8545", "LISTENING_PORT": "30303", "INSTANCE_NAME": "Erigon node", - "CONTACT_DETAILS": , + "CONTACT_DETAILS": , "WS_SERVER": "wss://ethstats.net/api", - "WS_SECRET": , + "WS_SECRET": , "VERBOSITY": 2 } } @@ -532,7 +550,10 @@ with `rpc.accessList` flag. ```json { - "allow": ["net_version", "web3_eth_getBlockByHash"] + "allow": [ + "net_version", + "web3_eth_getBlockByHash" + ] } ``` diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index 5da0583753e..13cf9a7b48d 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -95,6 +95,7 @@ func RootCommand() (*cobra.Command, *httpcfg.HttpCfg) { rootCmd.PersistentFlags().StringVar(&cfg.RpcAllowListFilePath, utils.RpcAccessListFlag.Name, "", "Specify granular (method-by-method) API allowlist") rootCmd.PersistentFlags().UintVar(&cfg.RpcBatchConcurrency, utils.RpcBatchConcurrencyFlag.Name, 2, utils.RpcBatchConcurrencyFlag.Usage) rootCmd.PersistentFlags().BoolVar(&cfg.RpcStreamingDisable, utils.RpcStreamingDisableFlag.Name, false, utils.RpcStreamingDisableFlag.Usage) + rootCmd.PersistentFlags().BoolVar(&cfg.DebugEnabled, utils.RpcDbgFlag.Name, false, utils.RpcDbgFlag.Usage) rootCmd.PersistentFlags().IntVar(&cfg.DBReadConcurrency, utils.DBReadConcurrencyFlag.Name, utils.DBReadConcurrencyFlag.Value, utils.DBReadConcurrencyFlag.Usage) rootCmd.PersistentFlags().BoolVar(&cfg.TraceCompatibility, "trace.compat", false, "Bug for bug compatibility with OE for trace_ routines") rootCmd.PersistentFlags().StringVar(&cfg.TxPoolApiAddr, "txpool.api.addr", "", "txpool api network address, for example: 127.0.0.1:9090 (default: use value of --private.api.addr)") diff --git a/cmd/rpcdaemon/cli/httpcfg/http_cfg.go b/cmd/rpcdaemon/cli/httpcfg/http_cfg.go index bab68cd4786..e3a4e65965a 100644 --- a/cmd/rpcdaemon/cli/httpcfg/http_cfg.go +++ b/cmd/rpcdaemon/cli/httpcfg/http_cfg.go @@ -10,7 +10,8 @@ import ( ) type HttpCfg struct { - Enabled bool + Enabled bool + DebugEnabled bool GraphQLEnabled bool WithDatadir bool // Erigon's database can be read by separated processes on same machine - in read-only mode - with full support of transactions. It will share same "OS PageCache" with Erigon process. diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 29b84f4f711..b59219f993c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -390,6 +390,10 @@ var ( Name: "rpc.streaming.disable", Usage: "Erigon has enabled json streaming for some heavy endpoints (like trace_*). It's a trade-off: greatly reduce amount of RAM (in some cases from 30GB to 30mb), but it produce invalid json format if error happened in the middle of streaming (because json is not streaming-friendly format)", } + RpcDbgFlag = cli.BoolFlag{ + Name: "rpc.dbg", + Usage: "Allow sending debug HTTP header - to print more detailed logs for given RPC. For security reasons - better debug it", + } RpcBatchLimit = cli.IntFlag{ Name: "rpc.batch.limit", Usage: "Maximum number of requests in a batch", diff --git a/erigon-lib/common/dbg/dbg_ctx.go b/erigon-lib/common/dbg/dbg_ctx.go new file mode 100644 index 00000000000..321dce564b3 --- /dev/null +++ b/erigon-lib/common/dbg/dbg_ctx.go @@ -0,0 +1,23 @@ +package dbg + +import ( + "context" +) + +type debugContextKey struct{} + +// Enabling detailed debugging logs for given context +func ToContext(ctx context.Context, val bool) context.Context { + return context.WithValue(ctx, debugContextKey{}, val) +} +func Enabled(ctx context.Context) bool { + t := ctx.Value(debugContextKey{}) + if t == nil { + return false + } + return t.(bool) +} + +// https://stackoverflow.com/a/3561399 -> https://www.rfc-editor.org/rfc/rfc6648 +// https://stackoverflow.com/a/65241869 -> https://www.odata.org/documentation/odata-version-3-0/abnf/ -> https://docs.oasis-open.org/odata/odata/v4.01/cs01/abnf/odata-abnf-construction-rules.txt +var HTTPHeader = "dbg" // curl --header "dbg: true" www.google.com diff --git a/rpc/http.go b/rpc/http.go index ab346d33feb..b5cb67b98e1 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -33,6 +33,7 @@ import ( "github.com/golang-jwt/jwt/v4" jsoniter "github.com/json-iterator/go" + "github.com/ledgerwatch/erigon-lib/common/dbg" "github.com/ledgerwatch/log/v3" ) @@ -245,6 +246,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { if origin := r.Header.Get("Origin"); origin != "" { ctx = context.WithValue(ctx, "Origin", origin) } + if v := r.Header.Get(dbg.HTTPHeader); v == "true" { + ctx = dbg.ToContext(ctx, true) + } w.Header().Set("content-type", contentType) codec := newHTTPServerConn(r, w) diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index 10b2e8bf8f9..8b8d883aa9a 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -71,6 +71,7 @@ var DefaultFlags = []cli.Flag{ &utils.StateCacheFlag, &utils.RpcBatchConcurrencyFlag, &utils.RpcStreamingDisableFlag, + &utils.RpcDbgFlag, &utils.DBReadConcurrencyFlag, &utils.RpcAccessListFlag, &utils.RpcTraceCompatFlag, diff --git a/turbo/cli/flags.go b/turbo/cli/flags.go index ead5dd18951..e97627632dd 100644 --- a/turbo/cli/flags.go +++ b/turbo/cli/flags.go @@ -448,6 +448,7 @@ func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logg return true }(), + DebugEnabled: ctx.Bool(utils.RpcDbgFlag.Name), HttpServerEnabled: ctx.Bool(utils.HTTPServerEnabledFlag.Name), Dirs: cfg.Dirs, diff --git a/turbo/snapshotsync/freezeblocks/block_reader.go b/turbo/snapshotsync/freezeblocks/block_reader.go index 17fa57fc8c2..ba68121d041 100644 --- a/turbo/snapshotsync/freezeblocks/block_reader.go +++ b/turbo/snapshotsync/freezeblocks/block_reader.go @@ -541,6 +541,12 @@ func (r *BlockReader) BlockWithSenders(ctx context.Context, tx kv.Getter, hash c return r.blockWithSenders(ctx, tx, hash, blockHeight, false) } func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash common.Hash, blockHeight uint64, forceCanonical bool) (block *types.Block, senders []common.Address, err error) { + var dbgPrefix string + dbgLogs := dbg.Enabled(ctx) + if dbgLogs { + dbgPrefix = fmt.Sprintf("[dbg] BlockReader.blockWithSenders(hash=%x,blk=%d,forceCanonical=%t) -> ", hash, blockHeight, forceCanonical) + } + maxBlockNumInFiles := r.sn.BlocksAvailable() if tx != nil && (maxBlockNumInFiles == 0 || blockHeight > maxBlockNumInFiles) { if forceCanonical { @@ -549,6 +555,9 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c return nil, nil, fmt.Errorf("requested non-canonical hash %x. canonical=%x", hash, canonicalHash) } if canonicalHash != hash { + if dbgLogs { + log.Info(dbgPrefix + fmt.Sprintf("this hash is not canonical now. current one is %x", canonicalHash)) + } return nil, nil, nil } } @@ -557,10 +566,16 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c if err != nil { return nil, nil, err } + if dbgLogs { + log.Info(dbgPrefix + fmt.Sprintf("found in db %t", block != nil)) + } return block, senders, nil } if r.sn == nil { + if dbgLogs { + log.Info(dbgPrefix + "no files") + } return } @@ -568,6 +583,9 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c defer view.Close() seg, ok := view.HeadersSegment(blockHeight) if !ok { + if dbgLogs { + log.Info(dbgPrefix + "no header files for this block num") + } return } @@ -577,6 +595,9 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c return nil, nil, err } if h == nil { + if dbgLogs { + log.Info(dbgPrefix + "got nil header from file") + } return } @@ -585,6 +606,9 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c var txsAmount uint32 bodySeg, ok := view.BodiesSegment(blockHeight) if !ok { + if dbgLogs { + log.Info(dbgPrefix + "no bodies file for this block num") + } return } b, baseTxnId, txsAmount, buf, err = r.bodyFromSnapshot(blockHeight, bodySeg, buf) @@ -592,11 +616,17 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c return nil, nil, err } if b == nil { + if dbgLogs { + log.Info(dbgPrefix + "got nil body from file") + } return } if txsAmount == 0 { block = types.NewBlockFromStorage(hash, h, nil, b.Uncles, b.Withdrawals) if len(senders) != block.Transactions().Len() { + if dbgLogs { + log.Info(dbgPrefix + fmt.Sprintf("found block with %d transactions, but %d senders", block.Transactions().Len(), len(senders))) + } return block, senders, nil // no senders is fine - will recover them on the fly } block.SendersToTxs(senders) @@ -605,6 +635,9 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c txnSeg, ok := view.TxsSegment(blockHeight) if !ok { + if dbgLogs { + log.Info(dbgPrefix + "no transactions file for this block num") + } return } var txs []types.Transaction @@ -612,11 +645,11 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c if err != nil { return nil, nil, err } - if !ok { - return - } block = types.NewBlockFromStorage(hash, h, txs, b.Uncles, b.Withdrawals) if len(senders) != block.Transactions().Len() { + if dbgLogs { + log.Info(dbgPrefix + fmt.Sprintf("found block with %d transactions, but %d senders", block.Transactions().Len(), len(senders))) + } return block, senders, nil // no senders is fine - will recover them on the fly } block.SendersToTxs(senders) From 37c0079ec78f02a49f0fa19d1d9816948b690449 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 11:54:29 +0700 Subject: [PATCH 02/14] enable http for 1 request --- cmd/rpcdaemon/README.md | 12 +++--------- cmd/rpcdaemon/cli/config.go | 8 ++++---- cmd/rpcdaemon/cli/httpcfg/http_cfg.go | 6 +++--- cmd/utils/flags.go | 10 +++++----- node/rpcstack.go | 2 +- rpc/http.go | 6 ++++-- rpc/server.go | 5 +++-- turbo/cli/default_flags.go | 2 +- turbo/cli/flags.go | 2 +- 9 files changed, 25 insertions(+), 28 deletions(-) diff --git a/cmd/rpcdaemon/README.md b/cmd/rpcdaemon/README.md index 89f259e3ab1..4629b79180b 100644 --- a/cmd/rpcdaemon/README.md +++ b/cmd/rpcdaemon/README.md @@ -175,7 +175,7 @@ to test the RPC. ### Debugging -Add `--rpc.dbg=true` flag, then can send header "dbg: true": +To print more detailed logs for 1 request - add `--rpc.dbg.single=true` flag. Then can send HTTP header `"dbg: true"`: ``` curl -X POST -H "dbg: true" -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id":1}' localhost:8545 @@ -515,15 +515,9 @@ Then update your `app.json` for ethstats-client like that: "RPC_PORT": "8545", "LISTENING_PORT": "30303", "INSTANCE_NAME": "Erigon node", - "CONTACT_DETAILS": , + "CONTACT_DETAILS": "", "WS_SERVER": "wss://ethstats.net/api", - "WS_SECRET": , + "WS_SECRET": "", "VERBOSITY": 2 } } diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index 13cf9a7b48d..8c9521390aa 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -95,7 +95,7 @@ func RootCommand() (*cobra.Command, *httpcfg.HttpCfg) { rootCmd.PersistentFlags().StringVar(&cfg.RpcAllowListFilePath, utils.RpcAccessListFlag.Name, "", "Specify granular (method-by-method) API allowlist") rootCmd.PersistentFlags().UintVar(&cfg.RpcBatchConcurrency, utils.RpcBatchConcurrencyFlag.Name, 2, utils.RpcBatchConcurrencyFlag.Usage) rootCmd.PersistentFlags().BoolVar(&cfg.RpcStreamingDisable, utils.RpcStreamingDisableFlag.Name, false, utils.RpcStreamingDisableFlag.Usage) - rootCmd.PersistentFlags().BoolVar(&cfg.DebugEnabled, utils.RpcDbgFlag.Name, false, utils.RpcDbgFlag.Usage) + rootCmd.PersistentFlags().BoolVar(&cfg.DebugSingleRequest, utils.HTTPDebugSingleFlag.Name, false, utils.HTTPDebugSingleFlag.Usage) rootCmd.PersistentFlags().IntVar(&cfg.DBReadConcurrency, utils.DBReadConcurrencyFlag.Name, utils.DBReadConcurrencyFlag.Value, utils.DBReadConcurrencyFlag.Usage) rootCmd.PersistentFlags().BoolVar(&cfg.TraceCompatibility, "trace.compat", false, "Bug for bug compatibility with OE for trace_ routines") rootCmd.PersistentFlags().StringVar(&cfg.TxPoolApiAddr, "txpool.api.addr", "", "txpool api network address, for example: 127.0.0.1:9090 (default: use value of --private.api.addr)") @@ -566,7 +566,7 @@ func StartRpcServerWithJwtAuthentication(ctx context.Context, cfg *httpcfg.HttpC func startRegularRpcServer(ctx context.Context, cfg *httpcfg.HttpCfg, rpcAPI []rpc.API, logger log.Logger) error { // register apis and create handler stack - srv := rpc.NewServer(cfg.RpcBatchConcurrency, cfg.TraceRequests, cfg.RpcStreamingDisable, logger, cfg.RPCSlowLogThreshold) + srv := rpc.NewServer(cfg.RpcBatchConcurrency, cfg.TraceRequests, cfg.DebugSingleRequest, cfg.RpcStreamingDisable, logger, cfg.RPCSlowLogThreshold) allowListForRPC, err := parseAllowListForRPC(cfg.RpcAllowListFilePath) if err != nil { @@ -749,7 +749,7 @@ type engineInfo struct { } func startAuthenticatedRpcServer(cfg *httpcfg.HttpCfg, rpcAPI []rpc.API, logger log.Logger) (*engineInfo, error) { - srv := rpc.NewServer(cfg.RpcBatchConcurrency, cfg.TraceRequests, cfg.RpcStreamingDisable, logger, cfg.RPCSlowLogThreshold) + srv := rpc.NewServer(cfg.RpcBatchConcurrency, cfg.TraceRequests, cfg.DebugSingleRequest, cfg.RpcStreamingDisable, logger, cfg.RPCSlowLogThreshold) engineListener, engineSrv, engineHttpEndpoint, err := createEngineListener(cfg, rpcAPI, logger) if err != nil { @@ -839,7 +839,7 @@ func createHandler(cfg *httpcfg.HttpCfg, apiList []rpc.API, httpHandler http.Han func createEngineListener(cfg *httpcfg.HttpCfg, engineApi []rpc.API, logger log.Logger) (*http.Server, *rpc.Server, string, error) { engineHttpEndpoint := fmt.Sprintf("tcp://%s:%d", cfg.AuthRpcHTTPListenAddress, cfg.AuthRpcPort) - engineSrv := rpc.NewServer(cfg.RpcBatchConcurrency, cfg.TraceRequests, true, logger, cfg.RPCSlowLogThreshold) + engineSrv := rpc.NewServer(cfg.RpcBatchConcurrency, cfg.TraceRequests, cfg.DebugSingleRequest, true, logger, cfg.RPCSlowLogThreshold) if err := node.RegisterApisFromWhitelist(engineApi, nil, engineSrv, true, logger); err != nil { return nil, nil, "", fmt.Errorf("could not start register RPC engine api: %w", err) diff --git a/cmd/rpcdaemon/cli/httpcfg/http_cfg.go b/cmd/rpcdaemon/cli/httpcfg/http_cfg.go index e3a4e65965a..8cf195890cf 100644 --- a/cmd/rpcdaemon/cli/httpcfg/http_cfg.go +++ b/cmd/rpcdaemon/cli/httpcfg/http_cfg.go @@ -10,8 +10,7 @@ import ( ) type HttpCfg struct { - Enabled bool - DebugEnabled bool + Enabled bool GraphQLEnabled bool WithDatadir bool // Erigon's database can be read by separated processes on same machine - in read-only mode - with full support of transactions. It will share same "OS PageCache" with Erigon process. @@ -68,7 +67,8 @@ type HttpCfg struct { SocketListenUrl string JWTSecretPath string // Engine API Authentication - TraceRequests bool // Always trace requests in INFO level + TraceRequests bool // Print requests to logs at INFO level + DebugSingleRequest bool // Print single-request-related debugging info to logs at INFO level HTTPTimeouts rpccfg.HTTPTimeouts AuthRpcTimeouts rpccfg.HTTPTimeouts EvmCallTimeout time.Duration diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index b59219f993c..ff41c69d201 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -390,10 +390,6 @@ var ( Name: "rpc.streaming.disable", Usage: "Erigon has enabled json streaming for some heavy endpoints (like trace_*). It's a trade-off: greatly reduce amount of RAM (in some cases from 30GB to 30mb), but it produce invalid json format if error happened in the middle of streaming (because json is not streaming-friendly format)", } - RpcDbgFlag = cli.BoolFlag{ - Name: "rpc.dbg", - Usage: "Allow sending debug HTTP header - to print more detailed logs for given RPC. For security reasons - better debug it", - } RpcBatchLimit = cli.IntFlag{ Name: "rpc.batch.limit", Usage: "Maximum number of requests in a batch", @@ -406,7 +402,11 @@ var ( } HTTPTraceFlag = cli.BoolFlag{ Name: "http.trace", - Usage: "Trace HTTP requests with INFO level", + Usage: "Print all HTTP requests to logs with INFO level", + } + HTTPDebugSingleFlag = cli.BoolFlag{ + Name: "http.dbg.single", + Usage: "Allow pass HTTP header 'dbg: true' to printt more detailed logs - how this request was executed", } DBReadConcurrencyFlag = cli.IntFlag{ Name: "db.read.concurrency", diff --git a/node/rpcstack.go b/node/rpcstack.go index 6bb42db6c59..da2ded52a33 100644 --- a/node/rpcstack.go +++ b/node/rpcstack.go @@ -265,7 +265,7 @@ func (h *httpServer) enableRPC(apis []rpc.API, config httpConfig, allowList rpc. } // Create RPC server and handler. - srv := rpc.NewServer(50, false /* traceRequests */, true, h.logger, 0) + srv := rpc.NewServer(50, false /* traceRequests */, false /* traceSingleRequest */, true, h.logger, 0) srv.SetAllowList(allowList) if err := RegisterApisFromWhitelist(apis, config.Modules, srv, false, h.logger); err != nil { return err diff --git a/rpc/http.go b/rpc/http.go index b5cb67b98e1..1dc541730f0 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -246,8 +246,10 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { if origin := r.Header.Get("Origin"); origin != "" { ctx = context.WithValue(ctx, "Origin", origin) } - if v := r.Header.Get(dbg.HTTPHeader); v == "true" { - ctx = dbg.ToContext(ctx, true) + if s.debugSingleRequest { + if v := r.Header.Get(dbg.HTTPHeader); v == "true" { + ctx = dbg.ToContext(ctx, true) + } } w.Header().Set("content-type", contentType) diff --git a/rpc/server.go b/rpc/server.go index 345422115bf..20ed7d4cd4c 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -54,15 +54,16 @@ type Server struct { batchConcurrency uint disableStreaming bool traceRequests bool // Whether to print requests at INFO level + debugSingleRequest bool // Whether to print requests at INFO level batchLimit int // Maximum number of requests in a batch logger log.Logger rpcSlowLogThreshold time.Duration } // NewServer creates a new server instance with no registered handlers. -func NewServer(batchConcurrency uint, traceRequests, disableStreaming bool, logger log.Logger, rpcSlowLogThreshold time.Duration) *Server { +func NewServer(batchConcurrency uint, traceRequests, debugSingleRequest, disableStreaming bool, logger log.Logger, rpcSlowLogThreshold time.Duration) *Server { server := &Server{services: serviceRegistry{logger: logger}, idgen: randomIDGenerator(), codecs: mapset.NewSet(), run: 1, batchConcurrency: batchConcurrency, - disableStreaming: disableStreaming, traceRequests: traceRequests, logger: logger, rpcSlowLogThreshold: rpcSlowLogThreshold} + disableStreaming: disableStreaming, traceRequests: traceRequests, debugSingleRequest: debugSingleRequest, logger: logger, rpcSlowLogThreshold: rpcSlowLogThreshold} // Register the default service providing meta information about the RPC service such // as the services and methods it offers. rpcService := &RPCService{server: server} diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index 8b8d883aa9a..2b1cd45a74e 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -68,10 +68,10 @@ var DefaultFlags = []cli.Flag{ &utils.WSEnabledFlag, &utils.WsCompressionFlag, &utils.HTTPTraceFlag, + &utils.HTTPDebugSingleFlag, &utils.StateCacheFlag, &utils.RpcBatchConcurrencyFlag, &utils.RpcStreamingDisableFlag, - &utils.RpcDbgFlag, &utils.DBReadConcurrencyFlag, &utils.RpcAccessListFlag, &utils.RpcTraceCompatFlag, diff --git a/turbo/cli/flags.go b/turbo/cli/flags.go index e97627632dd..40028af7c8d 100644 --- a/turbo/cli/flags.go +++ b/turbo/cli/flags.go @@ -448,7 +448,6 @@ func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logg return true }(), - DebugEnabled: ctx.Bool(utils.RpcDbgFlag.Name), HttpServerEnabled: ctx.Bool(utils.HTTPServerEnabledFlag.Name), Dirs: cfg.Dirs, @@ -463,6 +462,7 @@ func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logg AuthRpcPort: ctx.Int(utils.AuthRpcPort.Name), JWTSecretPath: jwtSecretPath, TraceRequests: ctx.Bool(utils.HTTPTraceFlag.Name), + DebugSingleRequest: ctx.Bool(utils.HTTPTraceSingleFlag.Name), HttpCORSDomain: libcommon.CliString2Array(ctx.String(utils.HTTPCORSDomainFlag.Name)), HttpVirtualHost: libcommon.CliString2Array(ctx.String(utils.HTTPVirtualHostsFlag.Name)), AuthRpcVirtualHost: libcommon.CliString2Array(ctx.String(utils.AuthRpcVirtualHostsFlag.Name)), From bc84b28d942ca38e39fb9355134479f045e99ef8 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 11:55:01 +0700 Subject: [PATCH 03/14] enable http for 1 request --- node/rpcstack.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/rpcstack.go b/node/rpcstack.go index da2ded52a33..3c9d4111d9a 100644 --- a/node/rpcstack.go +++ b/node/rpcstack.go @@ -298,7 +298,7 @@ func (h *httpServer) enableWS(apis []rpc.API, config wsConfig, allowList rpc.All } // Create RPC server and handler. - srv := rpc.NewServer(50, false /* traceRequests */, true, h.logger, 0) + srv := rpc.NewServer(50, false /* traceRequests */, false /* debugSingleRequest */, true, h.logger, 0) srv.SetAllowList(allowList) if err := RegisterApisFromWhitelist(apis, config.Modules, srv, false, h.logger); err != nil { return err From 946706d6465d566de1de2af4cd66463b948cac61 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 15:42:16 +0700 Subject: [PATCH 04/14] save --- erigon-lib/common/dbg/dbg_ctx.go | 10 +++---- rpc/http.go | 1 + rpc/server.go | 3 ++ turbo/jsonrpc/debug_api.go | 16 +++++------ turbo/jsonrpc/erigon_block.go | 3 +- turbo/jsonrpc/erigon_receipts.go | 8 +++--- turbo/jsonrpc/erigon_system.go | 3 +- turbo/jsonrpc/eth_accounts.go | 5 ++-- turbo/jsonrpc/eth_api.go | 28 +++++++++---------- turbo/jsonrpc/eth_block.go | 22 ++++++++------- turbo/jsonrpc/eth_call.go | 12 ++++---- turbo/jsonrpc/eth_callMany.go | 4 +-- turbo/jsonrpc/eth_receipts.go | 10 +++---- turbo/jsonrpc/eth_system.go | 13 +++++---- turbo/jsonrpc/eth_txs.go | 18 ++++++------ turbo/jsonrpc/eth_uncles.go | 9 +++--- turbo/jsonrpc/graphql_api.go | 4 +-- turbo/jsonrpc/otterscan_api.go | 12 ++++---- turbo/jsonrpc/otterscan_block_details.go | 3 +- turbo/jsonrpc/otterscan_contract_creator.go | 2 +- turbo/jsonrpc/otterscan_generic_tracer.go | 2 +- turbo/jsonrpc/otterscan_has_code.go | 2 +- turbo/jsonrpc/overlay_api.go | 8 +++--- turbo/jsonrpc/send_transaction.go | 2 +- turbo/jsonrpc/trace_adhoc.go | 18 ++++++------ turbo/jsonrpc/trace_filtering.go | 14 +++++----- turbo/jsonrpc/tracing.go | 14 +++++----- turbo/jsonrpc/txpool_api.go | 4 +-- .../snapshotsync/freezeblocks/block_reader.go | 6 ++++ 29 files changed, 137 insertions(+), 119 deletions(-) diff --git a/erigon-lib/common/dbg/dbg_ctx.go b/erigon-lib/common/dbg/dbg_ctx.go index 321dce564b3..f608dd4dc29 100644 --- a/erigon-lib/common/dbg/dbg_ctx.go +++ b/erigon-lib/common/dbg/dbg_ctx.go @@ -7,15 +7,15 @@ import ( type debugContextKey struct{} // Enabling detailed debugging logs for given context -func ToContext(ctx context.Context, val bool) context.Context { - return context.WithValue(ctx, debugContextKey{}, val) +func ToContext(ctx context.Context, v bool) context.Context { + return context.WithValue(ctx, debugContextKey{}, v) } func Enabled(ctx context.Context) bool { - t := ctx.Value(debugContextKey{}) - if t == nil { + v := ctx.Value(debugContextKey{}) + if v == nil { return false } - return t.(bool) + return v.(bool) } // https://stackoverflow.com/a/3561399 -> https://www.rfc-editor.org/rfc/rfc6648 diff --git a/rpc/http.go b/rpc/http.go index 1dc541730f0..4d2d45a4226 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -249,6 +249,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { if s.debugSingleRequest { if v := r.Header.Get(dbg.HTTPHeader); v == "true" { ctx = dbg.ToContext(ctx, true) + } } diff --git a/rpc/server.go b/rpc/server.go index 20ed7d4cd4c..07b20730494 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -25,6 +25,7 @@ import ( mapset "github.com/deckarep/golang-set" jsoniter "github.com/json-iterator/go" + "github.com/ledgerwatch/erigon-lib/common/dbg" "github.com/ledgerwatch/log/v3" ) @@ -120,6 +121,8 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec, stre return } + fmt.Printf("alex1: %t", dbg.Enabled(ctx)) + h := newHandler(ctx, codec, s.idgen, &s.services, s.methodAllowList, s.batchConcurrency, s.traceRequests, s.logger, s.rpcSlowLogThreshold) h.allowSubscribe = false defer h.close(io.EOF, nil) diff --git a/turbo/jsonrpc/debug_api.go b/turbo/jsonrpc/debug_api.go index 61646bbdc09..0a6dc67237c 100644 --- a/turbo/jsonrpc/debug_api.go +++ b/turbo/jsonrpc/debug_api.go @@ -68,7 +68,7 @@ func (api *PrivateDebugAPIImpl) StorageRangeAt(ctx context.Context, blockHash co } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return StorageRangeResult{}, err } @@ -83,7 +83,7 @@ func (api *PrivateDebugAPIImpl) StorageRangeAt(ctx context.Context, blockHash co return storageRangeAtV3(tx.(kv.TemporalTx), contractAddress, keyStart, minTxNum+txIndex, maxResult) } - block, err := api.blockByHashWithSenders(tx, blockHash) + block, err := api.blockByHashWithSenders(ctx, tx, blockHash) if err != nil { return StorageRangeResult{}, err } @@ -124,7 +124,7 @@ func (api *PrivateDebugAPIImpl) AccountRange(ctx context.Context, blockNrOrHash } } else if hash, ok := blockNrOrHash.Hash(); ok { - block, err1 := api.blockByHashWithSenders(tx, hash) + block, err1 := api.blockByHashWithSenders(ctx, tx, hash) if err1 != nil { return state.IteratorDump{}, err1 } @@ -244,7 +244,7 @@ func (api *PrivateDebugAPIImpl) GetModifiedAccountsByHash(ctx context.Context, s } defer tx.Rollback() - startBlock, err := api.blockByHashWithSenders(tx, startHash) + startBlock, err := api.blockByHashWithSenders(ctx, tx, startHash) if err != nil { return nil, err } @@ -255,7 +255,7 @@ func (api *PrivateDebugAPIImpl) GetModifiedAccountsByHash(ctx context.Context, s endNum := startNum + 1 // allows for single parameter calls if endHash != nil { - endBlock, err := api.blockByHashWithSenders(tx, *endHash) + endBlock, err := api.blockByHashWithSenders(ctx, tx, *endHash) if err != nil { return nil, err } @@ -332,13 +332,13 @@ func (api *PrivateDebugAPIImpl) AccountAt(ctx context.Context, blockHash common. return result, nil } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } engine := api.engine() - block, err := api.blockByHashWithSenders(tx, blockHash) + block, err := api.blockByHashWithSenders(ctx, tx, blockHash) if err != nil { return nil, err } @@ -394,7 +394,7 @@ func (api *PrivateDebugAPIImpl) GetRawBlock(ctx context.Context, blockNrOrHash r if err != nil { return nil, err } - block, err := api.blockWithSenders(tx, h, n) + block, err := api.blockWithSenders(ctx, tx, h, n) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/erigon_block.go b/turbo/jsonrpc/erigon_block.go index 879dbfd26fd..7fc3edc8a9a 100644 --- a/turbo/jsonrpc/erigon_block.go +++ b/turbo/jsonrpc/erigon_block.go @@ -5,9 +5,10 @@ import ( "context" "errors" "fmt" - "github.com/ledgerwatch/erigon-lib/common/hexutil" "sort" + "github.com/ledgerwatch/erigon-lib/common/hexutil" + "github.com/holiman/uint256" "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/hexutility" diff --git a/turbo/jsonrpc/erigon_receipts.go b/turbo/jsonrpc/erigon_receipts.go index 2aea175698e..17a3f99b23e 100644 --- a/turbo/jsonrpc/erigon_receipts.go +++ b/turbo/jsonrpc/erigon_receipts.go @@ -29,12 +29,12 @@ func (api *ErigonImpl) GetLogsByHash(ctx context.Context, hash common.Hash) ([][ } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } - block, err := api.blockByHashWithSenders(tx, hash) + block, err := api.blockByHashWithSenders(ctx, tx, hash) if err != nil { return nil, err } @@ -415,14 +415,14 @@ func (api *ErigonImpl) GetBlockReceiptsByBlockHash(ctx context.Context, cannonic if err != nil { return nil, err } - block, err := api.blockWithSenders(tx, cannonicalBlockHash, blockNum) + block, err := api.blockWithSenders(ctx, tx, cannonicalBlockHash, blockNum) if err != nil { return nil, err } if block == nil { return nil, nil } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/erigon_system.go b/turbo/jsonrpc/erigon_system.go index 54bcf65d4ac..ec1a4af1c68 100644 --- a/turbo/jsonrpc/erigon_system.go +++ b/turbo/jsonrpc/erigon_system.go @@ -3,6 +3,7 @@ package jsonrpc import ( "context" "errors" + "github.com/ledgerwatch/erigon-lib/common/hexutil" "github.com/ledgerwatch/erigon-lib/common" @@ -29,7 +30,7 @@ func (api *ErigonImpl) Forks(ctx context.Context) (Forks, error) { } defer tx.Rollback() - chainConfig, genesis, err := api.chainConfigWithGenesis(tx) + chainConfig, genesis, err := api.chainConfigWithGenesis(ctx, tx) if err != nil { return Forks{}, err } diff --git a/turbo/jsonrpc/eth_accounts.go b/turbo/jsonrpc/eth_accounts.go index dc3c41f5fcc..fd2f732ce74 100644 --- a/turbo/jsonrpc/eth_accounts.go +++ b/turbo/jsonrpc/eth_accounts.go @@ -3,9 +3,10 @@ package jsonrpc import ( "context" "fmt" - "github.com/ledgerwatch/erigon-lib/common/hexutil" "math/big" + "github.com/ledgerwatch/erigon-lib/common/hexutil" + libcommon "github.com/ledgerwatch/erigon-lib/common" "github.com/ledgerwatch/erigon-lib/common/hexutility" "github.com/ledgerwatch/erigon-lib/gointerfaces" @@ -81,7 +82,7 @@ func (api *APIImpl) GetCode(ctx context.Context, address libcommon.Address, bloc return nil, fmt.Errorf("getCode cannot open tx: %w", err1) } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, fmt.Errorf("read chain config: %v", err) } diff --git a/turbo/jsonrpc/eth_api.go b/turbo/jsonrpc/eth_api.go index 7754d0ba884..e7c6dbc5850 100644 --- a/turbo/jsonrpc/eth_api.go +++ b/turbo/jsonrpc/eth_api.go @@ -139,8 +139,8 @@ func NewBaseApi(f *rpchelper.Filters, stateCache kvcache.Cache, blockReader serv return &BaseAPI{filters: f, stateCache: stateCache, blocksLRU: blocksLRU, _blockReader: blockReader, _txnReader: blockReader, _agg: agg, evmCallTimeout: evmCallTimeout, _engine: engine, dirs: dirs} } -func (api *BaseAPI) chainConfig(tx kv.Tx) (*chain.Config, error) { - cfg, _, err := api.chainConfigWithGenesis(tx) +func (api *BaseAPI) chainConfig(ctx context.Context, tx kv.Tx) (*chain.Config, error) { + cfg, _, err := api.chainConfigWithGenesis(ctx, tx) return cfg, err } @@ -149,8 +149,8 @@ func (api *BaseAPI) engine() consensus.EngineReader { } // nolint:unused -func (api *BaseAPI) genesis(tx kv.Tx) (*types.Block, error) { - _, genesis, err := api.chainConfigWithGenesis(tx) +func (api *BaseAPI) genesis(ctx context.Context, tx kv.Tx) (*types.Block, error) { + _, genesis, err := api.chainConfigWithGenesis(ctx, tx) return genesis, err } @@ -158,15 +158,15 @@ func (api *BaseAPI) txnLookup(tx kv.Tx, txnHash common.Hash) (uint64, bool, erro return api._txnReader.TxnLookup(context.Background(), tx, txnHash) } -func (api *BaseAPI) blockByNumberWithSenders(tx kv.Tx, number uint64) (*types.Block, error) { +func (api *BaseAPI) blockByNumberWithSenders(ctx context.Context, 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(tx, hash, number) + return api.blockWithSenders(ctx, tx, hash, number) } -func (api *BaseAPI) blockByHashWithSenders(tx kv.Tx, hash common.Hash) (*types.Block, error) { +func (api *BaseAPI) blockByHashWithSenders(ctx context.Context, 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 @@ -177,16 +177,16 @@ func (api *BaseAPI) blockByHashWithSenders(tx kv.Tx, hash common.Hash) (*types.B return nil, nil } - return api.blockWithSenders(tx, hash, *number) + return api.blockWithSenders(ctx, tx, hash, *number) } -func (api *BaseAPI) blockWithSenders(tx kv.Tx, hash common.Hash, number uint64) (*types.Block, error) { +func (api *BaseAPI) blockWithSenders(ctx context.Context, 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(context.Background(), tx, hash, number) + block, _, err := api._blockReader.BlockWithSenders(ctx, tx, hash, number) if err != nil { return nil, err } @@ -223,13 +223,13 @@ func (api *BaseAPI) historyV3(tx kv.Tx) bool { return enabled } -func (api *BaseAPI) chainConfigWithGenesis(tx kv.Tx) (*chain.Config, *types.Block, error) { +func (api *BaseAPI) chainConfigWithGenesis(ctx context.Context, tx kv.Tx) (*chain.Config, *types.Block, error) { cc, genesisBlock := api._chainConfig.Load(), api._genesis.Load() if cc != nil && genesisBlock != nil { return cc, genesisBlock, nil } - genesisBlock, err := api.blockByRPCNumber(0, tx) + genesisBlock, err := api.blockByRPCNumber(ctx, 0, tx) if err != nil { return nil, nil, err } @@ -251,14 +251,14 @@ func (api *BaseAPI) pendingBlock() *types.Block { return api.filters.LastPendingBlock() } -func (api *BaseAPI) blockByRPCNumber(number rpc.BlockNumber, tx kv.Tx) (*types.Block, error) { +func (api *BaseAPI) blockByRPCNumber(ctx context.Context, 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 } // it's ok to use context.Background(), because in "Remote RPCDaemon" `tx` already contains internal ctx - block, err := api.blockWithSenders(tx, h, n) + block, err := api.blockWithSenders(ctx, tx, h, n) return block, err } diff --git a/turbo/jsonrpc/eth_block.go b/turbo/jsonrpc/eth_block.go index 71b44b5957a..3cbf7cdf9b4 100644 --- a/turbo/jsonrpc/eth_block.go +++ b/turbo/jsonrpc/eth_block.go @@ -6,6 +6,7 @@ import ( "math/big" "time" + "github.com/ledgerwatch/erigon-lib/common/dbg" "github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/erigon-lib/common" @@ -34,7 +35,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -54,7 +55,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat if !ok { return nil, nil } - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { return nil, err } @@ -196,6 +197,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat // GetBlockByNumber implements eth_getBlockByNumber. Returns information about a block given the block's number. func (api *APIImpl) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { + fmt.Printf("alex3: %t\n", dbg.Enabled(ctx)) tx, err := api.db.BeginRo(ctx) if err != nil { return nil, err @@ -217,7 +219,7 @@ func (api *APIImpl) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber additionalFields["totalDifficulty"] = (*hexutil.Big)(td) } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -261,7 +263,7 @@ func (api *APIImpl) GetBlockByHash(ctx context.Context, numberOrHash rpc.BlockNu additionalFields := make(map[string]interface{}) - block, err := api.blockByHashWithSenders(tx, hash) + block, err := api.blockByHashWithSenders(ctx, tx, hash) if err != nil { return nil, err } @@ -276,7 +278,7 @@ func (api *APIImpl) GetBlockByHash(ctx context.Context, numberOrHash rpc.BlockNu } additionalFields["totalDifficulty"] = (*hexutil.Big)(td) - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -314,7 +316,7 @@ func (api *APIImpl) GetBlockTransactionCountByNumber(ctx context.Context, blockN defer tx.Rollback() if blockNr == rpc.PendingBlockNumber { - b, err := api.blockByRPCNumber(blockNr, tx) + b, err := api.blockByRPCNumber(ctx, blockNr, tx) if err != nil { return nil, err } @@ -343,7 +345,7 @@ func (api *APIImpl) GetBlockTransactionCountByNumber(ctx context.Context, blockN return nil, err } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -384,7 +386,7 @@ func (api *APIImpl) GetBlockTransactionCountByHash(ctx context.Context, blockHas return nil, err } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -407,7 +409,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(number, tx) + return api.blockByRPCNumber(ctx, number, tx) } if block := api.pendingBlock(); block != nil { @@ -422,5 +424,5 @@ func (api *APIImpl) blockByNumber(ctx context.Context, number rpc.BlockNumber, t return block, nil } - return api.blockByRPCNumber(number, tx) + return api.blockByRPCNumber(ctx, number, tx) } diff --git a/turbo/jsonrpc/eth_call.go b/turbo/jsonrpc/eth_call.go index 84871efc594..de0566ed6c1 100644 --- a/turbo/jsonrpc/eth_call.go +++ b/turbo/jsonrpc/eth_call.go @@ -46,7 +46,7 @@ func (api *APIImpl) Call(ctx context.Context, args ethapi2.CallArgs, blockNrOrHa } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -60,7 +60,7 @@ func (api *APIImpl) Call(ctx context.Context, args ethapi2.CallArgs, blockNrOrHa if err != nil { return nil, err } - block, err := api.blockWithSenders(tx, hash, blockNumber) + block, err := api.blockWithSenders(ctx, tx, hash, blockNumber) if err != nil { return nil, err } @@ -221,7 +221,7 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs } gasCap = hi - chainConfig, err := api.chainConfig(dbtx) + chainConfig, err := api.chainConfig(ctx, dbtx) if err != nil { return 0, err } @@ -235,7 +235,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(dbtx, latestCanHash, latestCanBlockNumber) + block, err = api.blockWithSenders(ctx, dbtx, latestCanHash, latestCanBlockNumber) if err != nil { return 0, err } @@ -438,7 +438,7 @@ func (api *APIImpl) CreateAccessList(ctx context.Context, args ethapi2.CallArgs, } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -448,7 +448,7 @@ func (api *APIImpl) CreateAccessList(ctx context.Context, args ethapi2.CallArgs, if err != nil { return nil, err } - block, err := api.blockWithSenders(tx, hash, blockNumber) + block, err := api.blockWithSenders(ctx, tx, hash, blockNumber) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_callMany.go b/turbo/jsonrpc/eth_callMany.go index 540fc862069..c40f0ca68d6 100644 --- a/turbo/jsonrpc/eth_callMany.go +++ b/turbo/jsonrpc/eth_callMany.go @@ -86,7 +86,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -111,7 +111,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont return nil, err } - block, err := api.blockWithSenders(tx, hash, blockNum) + block, err := api.blockWithSenders(ctx, tx, hash, blockNum) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_receipts.go b/turbo/jsonrpc/eth_receipts.go index 94b88969fc5..53eb1112e25 100644 --- a/turbo/jsonrpc/eth_receipts.go +++ b/turbo/jsonrpc/eth_receipts.go @@ -404,7 +404,7 @@ func (api *APIImpl) getLogsV3(ctx context.Context, tx kv.TemporalTx, begin, end addrMap[v] = struct{}{} } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -607,7 +607,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha return nil, err } - cc, err := api.chainConfig(tx) + cc, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -623,7 +623,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha return nil, nil } - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { return nil, err } @@ -683,14 +683,14 @@ func (api *APIImpl) GetBlockReceipts(ctx context.Context, numberOrHash rpc.Block if err != nil { return nil, err } - block, err := api.blockWithSenders(tx, blockHash, blockNum) + block, err := api.blockWithSenders(ctx, tx, blockHash, blockNum) if err != nil { return nil, err } if block == nil { return nil, nil } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_system.go b/turbo/jsonrpc/eth_system.go index 470b7159341..865d316df0e 100644 --- a/turbo/jsonrpc/eth_system.go +++ b/turbo/jsonrpc/eth_system.go @@ -2,9 +2,10 @@ package jsonrpc import ( "context" - "github.com/ledgerwatch/erigon-lib/common/hexutil" "math/big" + "github.com/ledgerwatch/erigon-lib/common/hexutil" + "github.com/ledgerwatch/erigon-lib/chain" "github.com/ledgerwatch/erigon-lib/kv" @@ -82,7 +83,7 @@ func (api *APIImpl) ChainId(ctx context.Context) (hexutil.Uint64, error) { } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return 0, err } @@ -110,7 +111,7 @@ func (api *APIImpl) GasPrice(ctx context.Context) (*hexutil.Big, error) { return nil, err } defer tx.Rollback() - cc, err := api.chainConfig(tx) + cc, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -137,7 +138,7 @@ func (api *APIImpl) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, err return nil, err } defer tx.Rollback() - cc, err := api.chainConfig(tx) + cc, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -162,7 +163,7 @@ func (api *APIImpl) FeeHistory(ctx context.Context, blockCount rpc.DecimalOrHex, return nil, err } defer tx.Rollback() - cc, err := api.chainConfig(tx) + cc, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -215,7 +216,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(number, b.tx) + return b.baseApi.blockByRPCNumber(ctx, 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 f0756797bd6..9fa2fa30b1a 100644 --- a/turbo/jsonrpc/eth_txs.go +++ b/turbo/jsonrpc/eth_txs.go @@ -26,7 +26,7 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -44,7 +44,7 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has } } if ok { - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { return nil, err } @@ -124,7 +124,7 @@ func (api *APIImpl) GetRawTransactionByHash(ctx context.Context, hash common.Has if !ok { return nil, nil } - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { return nil, err } @@ -163,13 +163,13 @@ func (api *APIImpl) GetTransactionByBlockHashAndIndex(ctx context.Context, block return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } // https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByBlockHashAndIndex - block, err := api.blockByHashWithSenders(tx, blockHash) + block, err := api.blockByHashWithSenders(ctx, tx, blockHash) if err != nil { return nil, err } @@ -204,7 +204,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(tx, blockHash) + block, err := api.blockByHashWithSenders(ctx, tx, blockHash) if err != nil { return nil, err } @@ -222,7 +222,7 @@ func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blo return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -233,7 +233,7 @@ func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blo return nil, err } - block, err := api.blockWithSenders(tx, hash, blockNum) + block, err := api.blockWithSenders(ctx, tx, hash, blockNum) if err != nil { return nil, err } @@ -268,7 +268,7 @@ func (api *APIImpl) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, defer tx.Rollback() // https://infura.io/docs/ethereum/json-rpc/eth-getRawTransactionByBlockNumberAndIndex - block, err := api.blockByRPCNumber(blockNr, tx) + block, err := api.blockByRPCNumber(ctx, blockNr, tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_uncles.go b/turbo/jsonrpc/eth_uncles.go index 8d0acf589c9..526b2ecd206 100644 --- a/turbo/jsonrpc/eth_uncles.go +++ b/turbo/jsonrpc/eth_uncles.go @@ -2,6 +2,7 @@ package jsonrpc import ( "context" + "github.com/ledgerwatch/erigon-lib/common/hexutil" "github.com/ledgerwatch/erigon-lib/common" @@ -26,7 +27,7 @@ func (api *APIImpl) GetUncleByBlockNumberAndIndex(ctx context.Context, number rp if err != nil { return nil, err } - block, err := api.blockWithSenders(tx, hash, blockNum) + block, err := api.blockWithSenders(ctx, tx, hash, blockNum) if err != nil { return nil, err } @@ -57,7 +58,7 @@ func (api *APIImpl) GetUncleByBlockHashAndIndex(ctx context.Context, hash common } defer tx.Rollback() - block, err := api.blockByHashWithSenders(tx, hash) + block, err := api.blockByHashWithSenders(ctx, tx, hash) if err != nil { return nil, err } @@ -97,7 +98,7 @@ func (api *APIImpl) GetUncleCountByBlockNumber(ctx context.Context, number rpc.B return &n, err } - block, err := api.blockWithSenders(tx, blockHash, blockNum) + block, err := api.blockWithSenders(ctx, tx, blockHash, blockNum) if err != nil { return nil, err } @@ -122,7 +123,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(tx, hash, *number) + block, err := api.blockWithSenders(ctx, tx, hash, *number) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/graphql_api.go b/turbo/jsonrpc/graphql_api.go index 684ac492f0b..41e1d0b14ee 100644 --- a/turbo/jsonrpc/graphql_api.go +++ b/turbo/jsonrpc/graphql_api.go @@ -40,7 +40,7 @@ func (api *GraphQLAPIImpl) GetChainID(ctx context.Context) (*big.Int, error) { } defer tx.Rollback() - response, err := api.chainConfig(tx) + response, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -68,7 +68,7 @@ func (api *GraphQLAPIImpl) GetBlockDetails(ctx context.Context, blockNumber rpc. return nil, err } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/otterscan_api.go b/turbo/jsonrpc/otterscan_api.go index 834956a3220..cdfbccacc8d 100644 --- a/turbo/jsonrpc/otterscan_api.go +++ b/turbo/jsonrpc/otterscan_api.go @@ -84,7 +84,7 @@ func (api *OtterscanAPIImpl) getTransactionByHash(ctx context.Context, tx kv.Tx, return nil, nil, common.Hash{}, 0, 0, nil } - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { return nil, nil, common.Hash{}, 0, 0, err } @@ -124,7 +124,7 @@ func (api *OtterscanAPIImpl) runTracer(ctx context.Context, tx kv.Tx, hash commo return nil, fmt.Errorf("transaction %#x not found", hash) } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -201,7 +201,7 @@ func (api *OtterscanAPIImpl) SearchTransactionsBefore(ctx context.Context, addr } defer callToCursor.Close() - chainConfig, err := api.chainConfig(dbtx) + chainConfig, err := api.chainConfig(ctx, dbtx) if err != nil { return nil, err } @@ -258,7 +258,7 @@ func (api *OtterscanAPIImpl) SearchTransactionsBefore(ctx context.Context, addr } func (api *OtterscanAPIImpl) searchTransactionsBeforeV3(tx kv.TemporalTx, ctx context.Context, addr common.Address, fromBlockNum uint64, pageSize uint16) (*TransactionsWithReceipts, error) { - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -376,7 +376,7 @@ func (api *OtterscanAPIImpl) SearchTransactionsAfter(ctx context.Context, addr c } defer callToCursor.Close() - chainConfig, err := api.chainConfig(dbtx) + chainConfig, err := api.chainConfig(ctx, dbtx) if err != nil { return nil, err } @@ -576,7 +576,7 @@ func (api *OtterscanAPIImpl) GetBlockTransactions(ctx context.Context, number rp return nil, nil } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/otterscan_block_details.go b/turbo/jsonrpc/otterscan_block_details.go index 16401d5aa71..5f497983940 100644 --- a/turbo/jsonrpc/otterscan_block_details.go +++ b/turbo/jsonrpc/otterscan_block_details.go @@ -3,6 +3,7 @@ package jsonrpc import ( "context" "fmt" + "github.com/ledgerwatch/erigon-lib/common/hexutil" "github.com/ledgerwatch/erigon-lib/common" @@ -56,7 +57,7 @@ func (api *OtterscanAPIImpl) GetBlockDetailsByHash(ctx context.Context, hash com } func (api *OtterscanAPIImpl) getBlockDetailsImpl(ctx context.Context, tx kv.Tx, b *types.Block, number rpc.BlockNumber, senders []common.Address) (map[string]interface{}, error) { - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/otterscan_contract_creator.go b/turbo/jsonrpc/otterscan_contract_creator.go index 3cdd5386bcd..2edc12e004a 100644 --- a/turbo/jsonrpc/otterscan_contract_creator.go +++ b/turbo/jsonrpc/otterscan_contract_creator.go @@ -47,7 +47,7 @@ func (api *OtterscanAPIImpl) GetContractCreator(ctx context.Context, addr common return nil, nil } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/otterscan_generic_tracer.go b/turbo/jsonrpc/otterscan_generic_tracer.go index 182f07795a7..89a355ac2f4 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(dbtx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, dbtx, blockNum) if err != nil { return err } diff --git a/turbo/jsonrpc/otterscan_has_code.go b/turbo/jsonrpc/otterscan_has_code.go index e4af5b4189b..af442e8d000 100644 --- a/turbo/jsonrpc/otterscan_has_code.go +++ b/turbo/jsonrpc/otterscan_has_code.go @@ -21,7 +21,7 @@ func (api *OtterscanAPIImpl) HasCode(ctx context.Context, address common.Address if err != nil { return false, err } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return false, err } diff --git a/turbo/jsonrpc/overlay_api.go b/turbo/jsonrpc/overlay_api.go index a822f89ca2c..d21691035a7 100644 --- a/turbo/jsonrpc/overlay_api.go +++ b/turbo/jsonrpc/overlay_api.go @@ -88,7 +88,7 @@ func (api *OverlayAPIImpl) CallConstructor(ctx context.Context, address common.A return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -114,7 +114,7 @@ func (api *OverlayAPIImpl) CallConstructor(ctx context.Context, address common.A return nil, err } - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { return nil, err } @@ -268,7 +268,7 @@ func (api *OverlayAPIImpl) GetLogs(ctx context.Context, crit filters.FilterCrite return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -425,7 +425,7 @@ func (api *OverlayAPIImpl) replayBlock(ctx context.Context, blockNum uint64, sta return nil, err } - block, err := api.blockWithSenders(tx, hash, blockNum) + block, err := api.blockWithSenders(ctx, tx, hash, blockNum) if err != nil || block == nil { return nil, err } diff --git a/turbo/jsonrpc/send_transaction.go b/turbo/jsonrpc/send_transaction.go index 90dcaec332d..ce31d6aa456 100644 --- a/turbo/jsonrpc/send_transaction.go +++ b/turbo/jsonrpc/send_transaction.go @@ -40,7 +40,7 @@ func (api *APIImpl) SendRawTransaction(ctx context.Context, encodedTx hexutility defer tx.Rollback() - cc, err := api.chainConfig(tx) + cc, err := api.chainConfig(ctx, tx) if err != nil { return common.Hash{}, err } diff --git a/turbo/jsonrpc/trace_adhoc.go b/turbo/jsonrpc/trace_adhoc.go index 105df7b883d..dfae8cf3768 100644 --- a/turbo/jsonrpc/trace_adhoc.go +++ b/turbo/jsonrpc/trace_adhoc.go @@ -720,7 +720,7 @@ func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash libcommon return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -747,7 +747,7 @@ func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash libcommon isBorStateSyncTxn = true } - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { return nil, err } @@ -820,7 +820,7 @@ func (api *TraceAPIImpl) ReplayBlockTransactions(ctx context.Context, blockNrOrH return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -831,7 +831,7 @@ func (api *TraceAPIImpl) ReplayBlockTransactions(ctx context.Context, blockNrOrH } // Extract transactions from block - block, bErr := api.blockWithSenders(tx, blockHash, blockNumber) + block, bErr := api.blockWithSenders(ctx, tx, blockHash, blockNumber) if bErr != nil { return nil, bErr } @@ -889,7 +889,7 @@ func (api *TraceAPIImpl) Call(ctx context.Context, args TraceCallParam, traceTyp } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -912,7 +912,7 @@ func (api *TraceAPIImpl) Call(ctx context.Context, args TraceCallParam, traceTyp ibs := state.New(stateReader) - block, err := api.blockWithSenders(tx, hash, blockNumber) + block, err := api.blockWithSenders(ctx, tx, hash, blockNumber) if err != nil { return nil, err } @@ -1074,7 +1074,7 @@ func (api *TraceAPIImpl) CallMany(ctx context.Context, calls json.RawMessage, pa } // TODO: can read here only parent header - parentBlock, err := api.blockWithSenders(dbtx, hash, blockNumber) + parentBlock, err := api.blockWithSenders(ctx, dbtx, hash, blockNumber) if err != nil { return nil, err } @@ -1103,7 +1103,7 @@ func (api *TraceAPIImpl) CallMany(ctx context.Context, calls json.RawMessage, pa func (api *TraceAPIImpl) doCallMany(ctx context.Context, dbtx kv.Tx, msgs []types.Message, callParams []TraceCallParam, parentNrOrHash *rpc.BlockNumberOrHash, header *types.Header, gasBailout bool, txIndexNeeded int, ) ([]*TraceCallResult, *state.IntraBlockState, error) { - chainConfig, err := api.chainConfig(dbtx) + chainConfig, err := api.chainConfig(ctx, dbtx) if err != nil { return nil, nil, err } @@ -1128,7 +1128,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(dbtx, hash, blockNumber) + parentBlock, err := api.blockWithSenders(ctx, 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 19b5bb594ba..4251942ab5b 100644 --- a/turbo/jsonrpc/trace_filtering.go +++ b/turbo/jsonrpc/trace_filtering.go @@ -42,7 +42,7 @@ func (api *TraceAPIImpl) Transaction(ctx context.Context, txHash common.Hash, ga return nil, err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -69,7 +69,7 @@ func (api *TraceAPIImpl) Transaction(ctx context.Context, txHash common.Hash, ga isBorStateSyncTxn = true } - block, err := api.blockByNumberWithSenders(tx, blockNumber) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNumber) if err != nil { return nil, err } @@ -179,7 +179,7 @@ func (api *TraceAPIImpl) Block(ctx context.Context, blockNr rpc.BlockNumber, gas bn := hexutil.Uint64(blockNum) // Extract transactions from block - block, bErr := api.blockWithSenders(tx, hash, blockNum) + block, bErr := api.blockWithSenders(ctx, tx, hash, blockNum) if bErr != nil { return nil, bErr } @@ -187,7 +187,7 @@ func (api *TraceAPIImpl) Block(ctx context.Context, blockNr rpc.BlockNumber, gas return nil, fmt.Errorf("could not find block %d", uint64(bn)) } - cfg, err := api.chainConfig(tx) + cfg, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -373,7 +373,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, gas return err } - chainConfig, err := api.chainConfig(dbtx) + chainConfig, err := api.chainConfig(ctx, dbtx) if err != nil { return err } @@ -398,7 +398,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(dbtx, b) + block, bErr := api.blockByNumberWithSenders(ctx, dbtx, b) if bErr != nil { if first { first = false @@ -545,7 +545,7 @@ func (api *TraceAPIImpl) filterV3(ctx context.Context, dbtx kv.TemporalTx, fromB return err } - chainConfig, err := api.chainConfig(dbtx) + chainConfig, err := api.chainConfig(ctx, dbtx) if err != nil { return err } diff --git a/turbo/jsonrpc/tracing.go b/turbo/jsonrpc/tracing.go index 50aac434a94..42ab68041e3 100644 --- a/turbo/jsonrpc/tracing.go +++ b/turbo/jsonrpc/tracing.go @@ -49,7 +49,7 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp stream.WriteNil() return err } - block, err := api.blockWithSenders(tx, hash, blockNumber) + block, err := api.blockWithSenders(ctx, tx, hash, blockNumber) if err != nil { stream.WriteNil() return err @@ -76,7 +76,7 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp config.BorTraceEnabled = &disabled } - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { stream.WriteNil() return err @@ -201,7 +201,7 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo return err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { stream.WriteNil() return err @@ -244,7 +244,7 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo return err } - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { stream.WriteNil() return err @@ -307,7 +307,7 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA } defer dbtx.Rollback() - chainConfig, err := api.chainConfig(dbtx) + chainConfig, err := api.chainConfig(ctx, dbtx) if err != nil { return fmt.Errorf("read chain config: %v", err) } @@ -387,7 +387,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun return err } defer tx.Rollback() - chainConfig, err := api.chainConfig(tx) + chainConfig, err := api.chainConfig(ctx, tx) if err != nil { stream.WriteNil() return err @@ -421,7 +421,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun return err } - block, err := api.blockByNumberWithSenders(tx, blockNum) + block, err := api.blockByNumberWithSenders(ctx, tx, blockNum) if err != nil { stream.WriteNil() return err diff --git a/turbo/jsonrpc/txpool_api.go b/turbo/jsonrpc/txpool_api.go index 96ff0435cad..aaf91175f3f 100644 --- a/turbo/jsonrpc/txpool_api.go +++ b/turbo/jsonrpc/txpool_api.go @@ -82,7 +82,7 @@ func (api *TxPoolAPIImpl) Content(ctx context.Context) (map[string]map[string]ma return nil, err } defer tx.Rollback() - cc, err := api.chainConfig(tx) + cc, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } @@ -158,7 +158,7 @@ func (api *TxPoolAPIImpl) ContentFrom(ctx context.Context, addr libcommon.Addres return nil, err } defer tx.Rollback() - cc, err := api.chainConfig(tx) + cc, err := api.chainConfig(ctx, tx) if err != nil { return nil, err } diff --git a/turbo/snapshotsync/freezeblocks/block_reader.go b/turbo/snapshotsync/freezeblocks/block_reader.go index ba68121d041..25c004b0c74 100644 --- a/turbo/snapshotsync/freezeblocks/block_reader.go +++ b/turbo/snapshotsync/freezeblocks/block_reader.go @@ -548,8 +548,11 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c } maxBlockNumInFiles := r.sn.BlocksAvailable() + fmt.Printf("b0: %d\n", blockHeight) if tx != nil && (maxBlockNumInFiles == 0 || blockHeight > maxBlockNumInFiles) { + fmt.Printf("b1: %d\n", blockHeight) if forceCanonical { + fmt.Printf("b2: %d\n", blockHeight) canonicalHash, err := rawdb.ReadCanonicalHash(tx, blockHeight) if err != nil { return nil, nil, fmt.Errorf("requested non-canonical hash %x. canonical=%x", hash, canonicalHash) @@ -562,6 +565,7 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c } } + fmt.Printf("b21: %d\n", blockHeight) block, senders, err = rawdb.ReadBlockWithSenders(tx, hash, blockHeight) if err != nil { return nil, nil, err @@ -569,8 +573,10 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c if dbgLogs { log.Info(dbgPrefix + fmt.Sprintf("found in db %t", block != nil)) } + fmt.Printf("b22: %d,%t,%t\n", blockHeight, block == nil, dbgLogs) return block, senders, nil } + fmt.Printf("b3: %d\n", blockHeight) if r.sn == nil { if dbgLogs { From 3fed8c4dd35c4bd0ef06fe7939eee0061a79fb82 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 15:43:59 +0700 Subject: [PATCH 05/14] save --- rpc/server.go | 3 --- turbo/jsonrpc/eth_block.go | 2 -- turbo/snapshotsync/freezeblocks/block_reader.go | 6 ------ 3 files changed, 11 deletions(-) diff --git a/rpc/server.go b/rpc/server.go index 07b20730494..20ed7d4cd4c 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -25,7 +25,6 @@ import ( mapset "github.com/deckarep/golang-set" jsoniter "github.com/json-iterator/go" - "github.com/ledgerwatch/erigon-lib/common/dbg" "github.com/ledgerwatch/log/v3" ) @@ -121,8 +120,6 @@ func (s *Server) serveSingleRequest(ctx context.Context, codec ServerCodec, stre return } - fmt.Printf("alex1: %t", dbg.Enabled(ctx)) - h := newHandler(ctx, codec, s.idgen, &s.services, s.methodAllowList, s.batchConcurrency, s.traceRequests, s.logger, s.rpcSlowLogThreshold) h.allowSubscribe = false defer h.close(io.EOF, nil) diff --git a/turbo/jsonrpc/eth_block.go b/turbo/jsonrpc/eth_block.go index 3cbf7cdf9b4..f3ea740f62b 100644 --- a/turbo/jsonrpc/eth_block.go +++ b/turbo/jsonrpc/eth_block.go @@ -6,7 +6,6 @@ import ( "math/big" "time" - "github.com/ledgerwatch/erigon-lib/common/dbg" "github.com/ledgerwatch/log/v3" "github.com/ledgerwatch/erigon-lib/common" @@ -197,7 +196,6 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat // GetBlockByNumber implements eth_getBlockByNumber. Returns information about a block given the block's number. func (api *APIImpl) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) { - fmt.Printf("alex3: %t\n", dbg.Enabled(ctx)) tx, err := api.db.BeginRo(ctx) if err != nil { return nil, err diff --git a/turbo/snapshotsync/freezeblocks/block_reader.go b/turbo/snapshotsync/freezeblocks/block_reader.go index 25c004b0c74..ba68121d041 100644 --- a/turbo/snapshotsync/freezeblocks/block_reader.go +++ b/turbo/snapshotsync/freezeblocks/block_reader.go @@ -548,11 +548,8 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c } maxBlockNumInFiles := r.sn.BlocksAvailable() - fmt.Printf("b0: %d\n", blockHeight) if tx != nil && (maxBlockNumInFiles == 0 || blockHeight > maxBlockNumInFiles) { - fmt.Printf("b1: %d\n", blockHeight) if forceCanonical { - fmt.Printf("b2: %d\n", blockHeight) canonicalHash, err := rawdb.ReadCanonicalHash(tx, blockHeight) if err != nil { return nil, nil, fmt.Errorf("requested non-canonical hash %x. canonical=%x", hash, canonicalHash) @@ -565,7 +562,6 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c } } - fmt.Printf("b21: %d\n", blockHeight) block, senders, err = rawdb.ReadBlockWithSenders(tx, hash, blockHeight) if err != nil { return nil, nil, err @@ -573,10 +569,8 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c if dbgLogs { log.Info(dbgPrefix + fmt.Sprintf("found in db %t", block != nil)) } - fmt.Printf("b22: %d,%t,%t\n", blockHeight, block == nil, dbgLogs) return block, senders, nil } - fmt.Printf("b3: %d\n", blockHeight) if r.sn == nil { if dbgLogs { From 11f34a7e4fb7a55f25c7b384d0ea7ac7dc34ce2a Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 15:44:39 +0700 Subject: [PATCH 06/14] save --- turbo/snapshotsync/freezeblocks/block_reader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turbo/snapshotsync/freezeblocks/block_reader.go b/turbo/snapshotsync/freezeblocks/block_reader.go index ba68121d041..7460ff287d0 100644 --- a/turbo/snapshotsync/freezeblocks/block_reader.go +++ b/turbo/snapshotsync/freezeblocks/block_reader.go @@ -567,7 +567,7 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c return nil, nil, err } if dbgLogs { - log.Info(dbgPrefix + fmt.Sprintf("found in db %t", block != nil)) + log.Info(dbgPrefix + fmt.Sprintf("found_in_db=%t", block != nil)) } return block, senders, nil } From 45b00067176b93142fa77ea7c339b46c1a2a44f0 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 15:46:36 +0700 Subject: [PATCH 07/14] save --- turbo/jsonrpc/erigon_block.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/turbo/jsonrpc/erigon_block.go b/turbo/jsonrpc/erigon_block.go index 7fc3edc8a9a..08f095349c0 100644 --- a/turbo/jsonrpc/erigon_block.go +++ b/turbo/jsonrpc/erigon_block.go @@ -104,7 +104,7 @@ func (api *ErigonImpl) GetBlockByTimestamp(ctx context.Context, timeStamp rpc.Ti firstHeaderTime := firstHeader.Time if currentHeaderTime <= uintTimestamp { - blockResponse, err := buildBlockResponse(api._blockReader, tx, highestNumber, fullTx) + blockResponse, err := buildBlockResponse(ctx, api._blockReader, tx, highestNumber, fullTx) if err != nil { return nil, err } @@ -113,7 +113,7 @@ func (api *ErigonImpl) GetBlockByTimestamp(ctx context.Context, timeStamp rpc.Ti } if firstHeaderTime >= uintTimestamp { - blockResponse, err := buildBlockResponse(api._blockReader, tx, 0, fullTx) + blockResponse, err := buildBlockResponse(ctx, api._blockReader, tx, 0, fullTx) if err != nil { return nil, err } @@ -157,7 +157,7 @@ func (api *ErigonImpl) GetBlockByTimestamp(ctx context.Context, timeStamp rpc.Ti resultingHeader = beforeHeader } - response, err := buildBlockResponse(api._blockReader, tx, uint64(blockNum), fullTx) + response, err := buildBlockResponse(ctx, api._blockReader, tx, uint64(blockNum), fullTx) if err != nil { return nil, err } @@ -165,7 +165,7 @@ func (api *ErigonImpl) GetBlockByTimestamp(ctx context.Context, timeStamp rpc.Ti return response, nil } -func buildBlockResponse(br services.FullBlockReader, db kv.Tx, blockNum uint64, fullTx bool) (map[string]interface{}, error) { +func buildBlockResponse(ctx context.Context, br services.FullBlockReader, db kv.Tx, blockNum uint64, fullTx bool) (map[string]interface{}, error) { header, err := br.HeaderByNumber(context.Background(), db, blockNum) if err != nil { return nil, err @@ -174,7 +174,7 @@ func buildBlockResponse(br services.FullBlockReader, db kv.Tx, blockNum uint64, return nil, nil } - block, _, err := br.BlockWithSenders(context.Background(), db, header.Hash(), blockNum) + block, _, err := br.BlockWithSenders(ctx, db, header.Hash(), blockNum) if err != nil { return nil, err } From 9cc528ec473ff30383be8b2adf566cdb8ad5ccc6 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 15:47:43 +0700 Subject: [PATCH 08/14] save --- turbo/jsonrpc/debug_api.go | 2 +- turbo/jsonrpc/erigon_block.go | 2 +- turbo/jsonrpc/eth_api.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/turbo/jsonrpc/debug_api.go b/turbo/jsonrpc/debug_api.go index 0a6dc67237c..d0624836ee6 100644 --- a/turbo/jsonrpc/debug_api.go +++ b/turbo/jsonrpc/debug_api.go @@ -374,7 +374,7 @@ func (api *PrivateDebugAPIImpl) GetRawHeader(ctx context.Context, blockNrOrHash if err != nil { return nil, err } - header, err := api._blockReader.Header(context.Background(), tx, h, n) + header, err := api._blockReader.Header(ctx, tx, h, n) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/erigon_block.go b/turbo/jsonrpc/erigon_block.go index 08f095349c0..7e4a1190665 100644 --- a/turbo/jsonrpc/erigon_block.go +++ b/turbo/jsonrpc/erigon_block.go @@ -166,7 +166,7 @@ func (api *ErigonImpl) GetBlockByTimestamp(ctx context.Context, timeStamp rpc.Ti } func buildBlockResponse(ctx context.Context, br services.FullBlockReader, db kv.Tx, blockNum uint64, fullTx bool) (map[string]interface{}, error) { - header, err := br.HeaderByNumber(context.Background(), db, blockNum) + header, err := br.HeaderByNumber(ctx, db, blockNum) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_api.go b/turbo/jsonrpc/eth_api.go index e7c6dbc5850..52f02b580b3 100644 --- a/turbo/jsonrpc/eth_api.go +++ b/turbo/jsonrpc/eth_api.go @@ -159,7 +159,7 @@ func (api *BaseAPI) txnLookup(tx kv.Tx, txnHash common.Hash) (uint64, bool, erro } func (api *BaseAPI) blockByNumberWithSenders(ctx context.Context, tx kv.Tx, number uint64) (*types.Block, error) { - hash, hashErr := api._blockReader.CanonicalHash(context.Background(), tx, number) + hash, hashErr := api._blockReader.CanonicalHash(ctx, tx, number) if hashErr != nil { return nil, hashErr } From 1c52144f7ab52dba5492f0048cb06b369022b63f Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 15:48:50 +0700 Subject: [PATCH 09/14] save --- turbo/jsonrpc/eth_api.go | 4 ++-- turbo/jsonrpc/eth_block.go | 2 +- turbo/jsonrpc/eth_call_test.go | 2 +- turbo/jsonrpc/eth_system.go | 2 +- turbo/jsonrpc/tracing.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/turbo/jsonrpc/eth_api.go b/turbo/jsonrpc/eth_api.go index 52f02b580b3..008edc671c0 100644 --- a/turbo/jsonrpc/eth_api.go +++ b/turbo/jsonrpc/eth_api.go @@ -262,12 +262,12 @@ func (api *BaseAPI) blockByRPCNumber(ctx context.Context, number rpc.BlockNumber return block, err } -func (api *BaseAPI) headerByRPCNumber(number rpc.BlockNumber, tx kv.Tx) (*types.Header, error) { +func (api *BaseAPI) headerByRPCNumber(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Header, error) { n, h, _, err := rpchelper.GetBlockNumber(rpc.BlockNumberOrHashWithNumber(number), tx, api.filters) if err != nil { return nil, err } - return api._blockReader.Header(context.Background(), tx, h, n) + return api._blockReader.Header(ctx, tx, h, n) } // checks the pruning state to see if we would hold information about this diff --git a/turbo/jsonrpc/eth_block.go b/turbo/jsonrpc/eth_block.go index f3ea740f62b..f610753239e 100644 --- a/turbo/jsonrpc/eth_block.go +++ b/turbo/jsonrpc/eth_block.go @@ -94,7 +94,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat } ibs := state.New(stateReader) - parent, _ := api.headerByRPCNumber(rpc.BlockNumber(stateBlockNumber), tx) + parent, _ := api.headerByRPCNumber(ctx, rpc.BlockNumber(stateBlockNumber), tx) if parent == nil { return nil, fmt.Errorf("block %d(%x) not found", stateBlockNumber, hash) } diff --git a/turbo/jsonrpc/eth_call_test.go b/turbo/jsonrpc/eth_call_test.go index 8040af8593b..c1fa83ef1cf 100644 --- a/turbo/jsonrpc/eth_call_test.go +++ b/turbo/jsonrpc/eth_call_test.go @@ -191,7 +191,7 @@ func TestGetProof(t *testing.T) { tx, err := m.DB.BeginRo(context.Background()) assert.NoError(t, err) defer tx.Rollback() - header, err := api.headerByRPCNumber(rpc.BlockNumber(tt.blockNum), tx) + header, err := api.headerByRPCNumber(context.Background(), rpc.BlockNumber(tt.blockNum), tx) require.NoError(t, err) require.Equal(t, tt.addr, proof.Address) diff --git a/turbo/jsonrpc/eth_system.go b/turbo/jsonrpc/eth_system.go index 865d316df0e..d4dd9c5f792 100644 --- a/turbo/jsonrpc/eth_system.go +++ b/turbo/jsonrpc/eth_system.go @@ -206,7 +206,7 @@ func NewGasPriceOracleBackend(tx kv.Tx, cc *chain.Config, baseApi *BaseAPI) *Gas } func (b *GasPriceOracleBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) { - header, err := b.baseApi.headerByRPCNumber(number, b.tx) + header, err := b.baseApi.headerByRPCNumber(ctx, number, b.tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/tracing.go b/turbo/jsonrpc/tracing.go index 42ab68041e3..84eef3ae750 100644 --- a/turbo/jsonrpc/tracing.go +++ b/turbo/jsonrpc/tracing.go @@ -332,7 +332,7 @@ func (api *PrivateDebugAPIImpl) TraceCall(ctx context.Context, args ethapi.CallA if err != nil { return fmt.Errorf("create state reader: %v", err) } - header, err := api._blockReader.Header(context.Background(), dbtx, hash, blockNumber) + header, err := api._blockReader.Header(ctx, dbtx, hash, blockNumber) if err != nil { return fmt.Errorf("could not fetch header %d(%x): %v", blockNumber, hash, err) } From a57626aaabe003e155a1371800e106666ea9405f Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 24 Apr 2024 15:50:21 +0700 Subject: [PATCH 10/14] save --- turbo/jsonrpc/eth_api.go | 4 ++-- turbo/jsonrpc/eth_block.go | 2 +- turbo/jsonrpc/eth_receipts.go | 2 +- turbo/jsonrpc/eth_txs.go | 4 ++-- turbo/jsonrpc/otterscan_api.go | 2 +- turbo/jsonrpc/overlay_api.go | 2 +- turbo/jsonrpc/trace_adhoc.go | 2 +- turbo/jsonrpc/trace_filtering.go | 2 +- turbo/jsonrpc/tracing.go | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/turbo/jsonrpc/eth_api.go b/turbo/jsonrpc/eth_api.go index 008edc671c0..e0ba2efd3fb 100644 --- a/turbo/jsonrpc/eth_api.go +++ b/turbo/jsonrpc/eth_api.go @@ -154,8 +154,8 @@ func (api *BaseAPI) genesis(ctx context.Context, tx kv.Tx) (*types.Block, error) return genesis, err } -func (api *BaseAPI) txnLookup(tx kv.Tx, txnHash common.Hash) (uint64, bool, error) { - return api._txnReader.TxnLookup(context.Background(), tx, txnHash) +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) blockByNumberWithSenders(ctx context.Context, tx kv.Tx, number uint64) (*types.Block, error) { diff --git a/turbo/jsonrpc/eth_block.go b/turbo/jsonrpc/eth_block.go index f610753239e..5c8994b8dbb 100644 --- a/turbo/jsonrpc/eth_block.go +++ b/turbo/jsonrpc/eth_block.go @@ -47,7 +47,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat var txs types.Transactions for _, txHash := range txHashes { - blockNum, ok, err := api.txnLookup(tx, txHash) + blockNum, ok, err := api.txnLookup(ctx, tx, txHash) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_receipts.go b/turbo/jsonrpc/eth_receipts.go index 53eb1112e25..2d56ae05d4d 100644 --- a/turbo/jsonrpc/eth_receipts.go +++ b/turbo/jsonrpc/eth_receipts.go @@ -602,7 +602,7 @@ func (api *APIImpl) GetTransactionReceipt(ctx context.Context, txnHash common.Ha var blockNum uint64 var ok bool - blockNum, ok, err = api.txnLookup(tx, txnHash) + blockNum, ok, err = api.txnLookup(ctx, tx, txnHash) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/eth_txs.go b/turbo/jsonrpc/eth_txs.go index 9fa2fa30b1a..31076839a5d 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(tx, txnHash) + blockNum, ok, err := api.txnLookup(ctx, tx, txnHash) if err != nil { return nil, err } @@ -117,7 +117,7 @@ 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(tx, hash) + blockNum, ok, err := api.txnLookup(ctx, tx, hash) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/otterscan_api.go b/turbo/jsonrpc/otterscan_api.go index cdfbccacc8d..4dd5d9a7519 100644 --- a/turbo/jsonrpc/otterscan_api.go +++ b/turbo/jsonrpc/otterscan_api.go @@ -76,7 +76,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(tx, hash) + blockNum, ok, err := api.txnLookup(ctx, tx, hash) if err != nil { return nil, nil, common.Hash{}, 0, 0, err } diff --git a/turbo/jsonrpc/overlay_api.go b/turbo/jsonrpc/overlay_api.go index d21691035a7..67ec8017211 100644 --- a/turbo/jsonrpc/overlay_api.go +++ b/turbo/jsonrpc/overlay_api.go @@ -100,7 +100,7 @@ func (api *OverlayAPIImpl) CallConstructor(ctx context.Context, address common.A return nil, err } - blockNum, ok, err := api.txnLookup(tx, creationData.Tx) + blockNum, ok, err := api.txnLookup(ctx, tx, creationData.Tx) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/trace_adhoc.go b/turbo/jsonrpc/trace_adhoc.go index dfae8cf3768..790344fb46b 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 } var isBorStateSyncTxn bool - blockNum, ok, err := api.txnLookup(tx, txHash) + blockNum, ok, err := api.txnLookup(ctx, tx, txHash) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/trace_filtering.go b/turbo/jsonrpc/trace_filtering.go index 4251942ab5b..04cff744a07 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 } var isBorStateSyncTxn bool - blockNumber, ok, err := api.txnLookup(tx, txHash) + blockNumber, ok, err := api.txnLookup(ctx, tx, txHash) if err != nil { return nil, err } diff --git a/turbo/jsonrpc/tracing.go b/turbo/jsonrpc/tracing.go index 84eef3ae750..4bcbc86a420 100644 --- a/turbo/jsonrpc/tracing.go +++ b/turbo/jsonrpc/tracing.go @@ -208,7 +208,7 @@ func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash commo } // Retrieve the transaction and assemble its EVM context var isBorStateSyncTxn bool - blockNum, ok, err := api.txnLookup(tx, hash) + blockNum, ok, err := api.txnLookup(ctx, tx, hash) if err != nil { stream.WriteNil() return err From 38aa4261b4483a6f5086ad49df1123d19e5940f4 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Thu, 25 Apr 2024 17:50:01 +0700 Subject: [PATCH 11/14] save --- turbo/cli/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turbo/cli/flags.go b/turbo/cli/flags.go index 40028af7c8d..b5fe038ff87 100644 --- a/turbo/cli/flags.go +++ b/turbo/cli/flags.go @@ -462,7 +462,7 @@ func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logg AuthRpcPort: ctx.Int(utils.AuthRpcPort.Name), JWTSecretPath: jwtSecretPath, TraceRequests: ctx.Bool(utils.HTTPTraceFlag.Name), - DebugSingleRequest: ctx.Bool(utils.HTTPTraceSingleFlag.Name), + DebugSingleRequest: ctx.Bool(utils.HTTPDebugSingleFlag.Name), HttpCORSDomain: libcommon.CliString2Array(ctx.String(utils.HTTPCORSDomainFlag.Name)), HttpVirtualHost: libcommon.CliString2Array(ctx.String(utils.HTTPVirtualHostsFlag.Name)), AuthRpcVirtualHost: libcommon.CliString2Array(ctx.String(utils.AuthRpcVirtualHostsFlag.Name)), From 2508e454a78dfffafd04956005ad4bdcaa669d7f Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Thu, 25 Apr 2024 19:04:04 +0700 Subject: [PATCH 12/14] Update erigon-lib/common/dbg/dbg_ctx.go Co-authored-by: battlmonstr --- erigon-lib/common/dbg/dbg_ctx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erigon-lib/common/dbg/dbg_ctx.go b/erigon-lib/common/dbg/dbg_ctx.go index f608dd4dc29..f9c996e4165 100644 --- a/erigon-lib/common/dbg/dbg_ctx.go +++ b/erigon-lib/common/dbg/dbg_ctx.go @@ -7,7 +7,7 @@ import ( type debugContextKey struct{} // Enabling detailed debugging logs for given context -func ToContext(ctx context.Context, v bool) context.Context { +func ContextWithDebug(ctx context.Context, v bool) context.Context { return context.WithValue(ctx, debugContextKey{}, v) } func Enabled(ctx context.Context) bool { From c381396e5c804d3f7d82268bd5d4629f65e26b1d Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Thu, 25 Apr 2024 19:06:18 +0700 Subject: [PATCH 13/14] save --- rpc/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/http.go b/rpc/http.go index 4d2d45a4226..ccb8981a286 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -248,7 +248,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if s.debugSingleRequest { if v := r.Header.Get(dbg.HTTPHeader); v == "true" { - ctx = dbg.ToContext(ctx, true) + ctx = dbg.ContextWithDebug(ctx, true) } } From ac2554f69f0c8ca4859d4cef44c8fc929b05f1fa Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Thu, 25 Apr 2024 19:08:59 +0700 Subject: [PATCH 14/14] save --- rpc/http_test.go | 2 +- rpc/server_test.go | 2 +- rpc/subscription_test.go | 2 +- rpc/testservice_test.go | 2 +- rpc/websocket_test.go | 2 +- turbo/jsonrpc/get_chain_config_test.go | 9 +++++---- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/rpc/http_test.go b/rpc/http_test.go index 28b7cfe51c7..899fd9cd93e 100644 --- a/rpc/http_test.go +++ b/rpc/http_test.go @@ -107,7 +107,7 @@ func TestHTTPRespBodyUnlimited(t *testing.T) { logger := log.New() const respLength = maxRequestContentLength * 3 - s := NewServer(50, false /* traceRequests */, true, logger, 100) + s := NewServer(50, false /* traceRequests */, false /* debugSingleRequests */, true, logger, 100) defer s.Stop() if err := s.RegisterName("test", largeRespService{respLength}); err != nil { t.Fatal(err) diff --git a/rpc/server_test.go b/rpc/server_test.go index 104dc1883a7..2eee071c656 100644 --- a/rpc/server_test.go +++ b/rpc/server_test.go @@ -34,7 +34,7 @@ import ( func TestServerRegisterName(t *testing.T) { logger := log.New() - server := NewServer(50, false /* traceRequests */, true, logger, 100) + server := NewServer(50, false /* traceRequests */, false /* debugSingleRequests */, true, logger, 100) service := new(testService) if err := server.RegisterName("test", service); err != nil { diff --git a/rpc/subscription_test.go b/rpc/subscription_test.go index 8f09b2aa258..dc92ec56bf1 100644 --- a/rpc/subscription_test.go +++ b/rpc/subscription_test.go @@ -56,7 +56,7 @@ func TestSubscriptions(t *testing.T) { subCount = len(namespaces) notificationCount = 3 - server = NewServer(50, false /* traceRequests */, true, logger, 100) + server = NewServer(50, false /* traceRequests */, false /* debugSingleRequests */, true, logger, 100) clientConn, serverConn = net.Pipe() out = json.NewEncoder(clientConn) in = json.NewDecoder(clientConn) diff --git a/rpc/testservice_test.go b/rpc/testservice_test.go index c5017489c82..1a39a77933e 100644 --- a/rpc/testservice_test.go +++ b/rpc/testservice_test.go @@ -28,7 +28,7 @@ import ( ) func newTestServer(logger log.Logger) *Server { - server := NewServer(50, false /* traceRequests */, true, logger, 100) + server := NewServer(50, false /* traceRequests */, false /* debugSingleRequests */, true, logger, 100) server.idgen = sequentialIDGenerator() if err := server.RegisterName("test", new(testService)); err != nil { panic(err) diff --git a/rpc/websocket_test.go b/rpc/websocket_test.go index 941a790b868..d7efebed775 100644 --- a/rpc/websocket_test.go +++ b/rpc/websocket_test.go @@ -168,7 +168,7 @@ func TestClientWebsocketPing(t *testing.T) { func TestClientWebsocketLargeMessage(t *testing.T) { logger := log.New() var ( - srv = NewServer(50, false /* traceRequests */, true, logger, 100) + srv = NewServer(50, false /* traceRequests */, false /* debugSingleRequests */, true, logger, 100) httpsrv = httptest.NewServer(srv.WebsocketHandler(nil, nil, false, logger)) wsURL = "ws:" + strings.TrimPrefix(httpsrv.URL, "http:") ) diff --git a/turbo/jsonrpc/get_chain_config_test.go b/turbo/jsonrpc/get_chain_config_test.go index af406fe70d5..c38df84004e 100644 --- a/turbo/jsonrpc/get_chain_config_test.go +++ b/turbo/jsonrpc/get_chain_config_test.go @@ -2,13 +2,14 @@ package jsonrpc import ( "context" - "github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest" "testing" + + "github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest" ) func TestGetChainConfig(t *testing.T) { m, _, _ := rpcdaemontest.CreateTestSentry(t) - db := m.DB + db, ctx := m.DB, m.Ctx api := newBaseApiForTest(m) config := m.ChainConfig @@ -18,14 +19,14 @@ func TestGetChainConfig(t *testing.T) { } defer tx.Rollback() - config1, err1 := api.chainConfig(tx) + config1, err1 := api.chainConfig(ctx, tx) if err1 != nil { t.Fatalf("reading chain config: %v", err1) } if config.String() != config1.String() { t.Fatalf("read different config: %s, expected %s", config1.String(), config.String()) } - config2, err2 := api.chainConfig(tx) + config2, err2 := api.chainConfig(ctx, tx) if err2 != nil { t.Fatalf("reading chain config: %v", err2) }