Improve logging for eth_call & eth_estimateGas JSON-RPC endpoints - #873
Conversation
WalkthroughDefaults Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant API as API (Call)
participant L as Logger
participant E as EVM Backend
C->>API: eth_call(args, stateOverrides, blockOverrides, blockTag)
API->>API: Default blockTag/blockNumberOrHash → "latest"
API->>API: Validate args (short-form)
alt invalid
API-->>C: validation error
else valid
API->>API: Marshal args/stateOverrides/blockOverrides → JSON
alt marshal error
API-->>C: typed error via handleError
else ok
API->>L: Log structured RawJSON {args, stateOverrides, blockOverrides, blockTag}
API->>E: Resolve height & execute call
E-->>API: result / error
API-->>C: result / error
end
end
sequenceDiagram
autonumber
participant C as Client
participant API as API (EstimateGas)
participant L as Logger
participant E as EVM Backend
C->>API: eth_estimateGas(args, stateOverrides, blockTag)
API->>API: Default blockTag/blockNumberOrHash → "latest"
API->>API: Validate args (short-form)
alt invalid
API-->>C: validation error
else valid
API->>API: Marshal args/stateOverrides → JSON
alt marshal error
API-->>C: typed error via handleError
else ok
API->>L: Log structured RawJSON {args, stateOverrides, blockTag}
API->>E: Resolve height & estimate gas
E-->>API: estimate / error
API-->>C: estimate / error
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (6)
api/api.go (6)
533-536: Use a local copy instead of taking the address of the package var.
Prevents any chance of shared-state mutation between concurrent requests.Apply:
- // Default to "latest" block tag - if blockNumberOrHash == nil { - blockNumberOrHash = &latestBlockNumberOrHash - } + // Default to "latest" block tag + if blockNumberOrHash == nil { + defaultTag := latestBlockNumberOrHash + blockNumberOrHash = &defaultTag + }
538-552: Return marshaling errors with endpoint context (and blockTag) for better diagnostics.
Right now these paths useb.logger, losing endpoint context. Keep logs consistent with the rest of the method.Apply:
- if err != nil { - return handleError[hexutil.Bytes](err, b.logger, b.collector) - } + if err != nil { + return handleError[hexutil.Bytes]( + err, + b.logger.With().Str("endpoint", EthCall).Str("blockTag", blockNumberOrHash.String()).Logger(), + b.collector, + ) + } @@ - if err != nil { - return handleError[hexutil.Bytes](err, b.logger, b.collector) - } + if err != nil { + return handleError[hexutil.Bytes]( + err, + b.logger.With().Str("endpoint", EthCall).Str("blockTag", blockNumberOrHash.String()).Logger(), + b.collector, + ) + } @@ - if err != nil { - return handleError[hexutil.Bytes](err, b.logger, b.collector) - } + if err != nil { + return handleError[hexutil.Bytes]( + err, + b.logger.With().Str("endpoint", EthCall).Str("blockTag", blockNumberOrHash.String()).Logger(), + b.collector, + ) + }
553-559: Log the block tag via String(), not fmt on the pointer.
fmt.Sprintf("%v", *ptr)can produce less clear output.String()yields canonical form.Apply:
- RawJSON("args", txArgs). - Str("blockTag", fmt.Sprintf("%v", blockNumberOrHash)). + RawJSON("args", txArgs). + Str("blockTag", blockNumberOrHash.String()).
715-718: Repeat the safe-local-copy pattern for EstimateGas.
Same reasoning as in Call.Apply:
- // Default to "latest" block tag - if blockNumberOrHash == nil { - blockNumberOrHash = &latestBlockNumberOrHash - } + // Default to "latest" block tag + if blockNumberOrHash == nil { + defaultTag := latestBlockNumberOrHash + blockNumberOrHash = &defaultTag + }
720-729: Return marshaling errors with endpoint context in EstimateGas too.
Mirror the Call improvements for consistent diagnostics.Apply:
- if err != nil { - return handleError[hexutil.Uint64](err, b.logger, b.collector) - } + if err != nil { + return handleError[hexutil.Uint64]( + err, + b.logger.With().Str("endpoint", EthEstimateGas).Str("blockTag", blockNumberOrHash.String()).Logger(), + b.collector, + ) + } @@ - if err != nil { - return handleError[hexutil.Uint64](err, b.logger, b.collector) - } + if err != nil { + return handleError[hexutil.Uint64]( + err, + b.logger.With().Str("endpoint", EthEstimateGas).Str("blockTag", blockNumberOrHash.String()).Logger(), + b.collector, + ) + }
730-735: Use String() for the block tag in logs.
Matches Call and avoids pointer formatting.Apply:
- RawJSON("args", txArgs). - Str("blockTag", fmt.Sprintf("%v", blockNumberOrHash)). + RawJSON("args", txArgs). + Str("blockTag", blockNumberOrHash.String()).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
api/api.go(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
api/api.go (2)
api/rpc_calls.go (2)
EthCall(18-18)EthEstimateGas(21-21)api/debug.go (1)
d(134-252)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test
🔇 Additional comments (4)
api/api.go (4)
5-5: Import for JSON marshaling looks good.
Used by new RawJSON logging; no issues.
565-565: Validate via short form: LGTM.
Concise and consistent with surrounding code.
741-741: Args.Validate short form: LGTM.
Keeps style consistent and readable.
34-34: Ignore pointer‐mutation warning forlatestBlockNumberOrHash. TheresolveBlockTagimplementation never writes through its*rpc.BlockNumberOrHashargument, so sharing the package‐level sentinel by address does not introduce mutation or race risks.Likely an incorrect or invalid review comment.
6ac7a9c to
7b39866
Compare
7b39866 to
3b0ecdf
Compare
Closes: #862
Description
After some effort to investigate a production issue, regarding
eth_call, I realized that for errors, we only log the givenargs. This is not enough information, when trying to replicate a issue, either locally, or in production. We should log all other parameters, such as state overrides, block overrides, and the given block height/hash.For contributor use:
masterbranchFiles changedin the Github PR explorerSummary by CodeRabbit
Bug Fixes
Chores