Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(evm): debug calls with custom tracer and tracer options #2031

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

onikonychev
Copy link
Contributor

@onikonychev onikonychev commented Sep 11, 2024

Can handle debug_traceBlockByNumber (as well as traceTransaction / traceCall) with a tracer and traceConfig options like this:

curl --location 'http://127.0.0.1:8545' \
--header 'Content-Type: application/json' \
--data '{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "debug_traceBlockByNumber",
    "params": [
        "0x2B",
        {
            "tracer": "callTracer",
            "timeout": "3000s",
            "tracerConfig": { "onlyTopCall": false }
        }
        ]
}' | jq

@onikonychev onikonychev requested a review from a team as a code owner September 11, 2024 13:17
Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

The changes introduce enhancements to the Ethereum Virtual Machine (EVM) functionality, including modifications to tracing configurations and improvements in debugging tests. A new TracerConfig message type is added to the protocol, replacing the previous JSON string format. The handling of tracer configurations in the application and tests is updated to utilize structured objects, improving clarity and maintainability. Additionally, the changelog is updated to document these changes, providing better traceability for users.

Changes

Files Change Summary
CHANGELOG.md Added entry for pull request #2031 related to EVM debug calls with custom tracer and options.
app/app.go Added import statement for github.com/ethereum/go-ethereum/eth/tracers/native to initialize geth tracers.
e2e/evm/test/debug_queries.test.ts Enhanced debug query tests with additional parameters and updated expectations for trace results; unskipped a test.
proto/eth/evm/v1/evm.proto Introduced TracerConfig message and modified TraceConfig to use structured configuration instead of JSON string.
x/evm/keeper/grpc_query.go Updated methods to handle TracerConfig instead of JSON string, enhancing the processing of tracing configurations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant EVM
    participant Tracer

    User->>App: Initiate Debug Call
    App->>EVM: Request Debug Trace
    EVM->>Tracer: Use TracerConfig
    Tracer-->>EVM: Return Trace Result
    EVM-->>App: Send Trace Data
    App-->>User: Display Trace Data
Loading

🐇 In the realm of code where the EVM hops,
New traces and tests make our debugging stop!
With structured configs, oh what a delight,
Our tracing is clearer, our futures look bright!
So let’s celebrate changes, both big and small,
For the joy of the rabbit is shared by us all! 🥕


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 64beba7 and df44162.

Files ignored due to path filters (1)
  • x/evm/evm.pb.go is excluded by !**/*.pb.go
Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • app/app.go (1 hunks)
  • e2e/evm/test/debug_queries.test.ts (4 hunks)
  • proto/eth/evm/v1/evm.proto (2 hunks)
  • x/evm/keeper/grpc_query.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
Additional context used
GitHub Check: break-check
proto/eth/evm/v1/evm.proto

[failure] 182-182:
Field "13" with name "tracer_config" on message "TraceConfig" changed cardinality from "optional with implicit presence" to "optional with explicit presence".


[failure] 182-182:
Field "13" with name "tracer_config" on message "TraceConfig" changed option "json_name" from "tracerJsonConfig" to "tracerConfig".


[failure] 182-182:
Field "13" with name "tracer_config" on message "TraceConfig" changed type from "string" to "message".


[failure] 182-182:
Field "13" on message "TraceConfig" changed name from "tracer_json_config" to "tracer_config".

Additional comments not posted (9)
e2e/evm/test/debug_queries.test.ts (5)

35-39: LGTM!

The changes to the debug_traceBlockByNumber test case are approved. The additional parameters in the provider.send call improve the tracing functionality by allowing for more detailed configurations during the debugging process.


48-52: LGTM!

The changes to the debug_traceBlockByHash test case are approved. The additional parameters in the provider.send call improve the tracing functionality by allowing for more detailed configurations during the debugging process.


57-65: LGTM!

The changes to the debug_traceTransaction test case are approved. The additional parameters in the provider.send call improve the tracing functionality by allowing for more detailed configurations during the debugging process. It's great to see that the test case is now actively tested rather than marked as a TODO.


80-84: LGTM!

The changes to the debug_traceCall test case are approved. The additional parameters in the provider.send call improve the tracing functionality by allowing for more detailed configurations during the debugging process.


113-119: LGTM!

The changes to the expectTrace function are approved. The new property checks improve the validation of the trace result by checking for the completeness and correctness of the trace data returned from the debugging queries.

proto/eth/evm/v1/evm.proto (1)

149-151: LGTM!

The TracerConfig message is well-defined and serves a clear purpose of storing Geth-specific tracer configuration.

app/app.go (1)

55-57: LGTM! The import statement is used to initialize the geth native tracers.

The blank identifier _ is used to import the github.com/ethereum/go-ethereum/eth/tracers/native package solely for its side effects, i.e., to ensure that the init() function of the package is called during the initialization of the application.

This is a common pattern in Go to force the initialization of a package without actually using any of its exported identifiers in the code.

The inclusion of this import suggests that the application is integrating Ethereum's native tracing capabilities, which can provide detailed execution traces of Ethereum transactions and smart contracts.

x/evm/keeper/grpc_query.go (2)

531-533: Approve switching to a structured tracer configuration object.

The change to use a structured object for the tracer configuration instead of a JSON string improves the clarity and robustness of the code.


687-687: Handle the error from marshaling the tracer configuration.

Ignoring the error from marshaling the TraceConfig.TracerConfig could lead to unexpected behavior if there's an error. Consider handling the error, for example:

-tracerConfig, _ = json.Marshal(req.TraceConfig.TracerConfig)
+tracerConfig, err = json.Marshal(req.TraceConfig.TracerConfig)
+if err != nil {
+    return nil, grpcstatus.Error(grpccodes.Internal, err.Error())
+}

Comment on lines +181 to +182
// tracer_config configures the tracer options
TracerConfig tracer_config = 13 [ (gogoproto.jsontag) = "tracerConfig" ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change: tracer_json_config field replaced with tracer_config.

The tracer_json_config field of type string at tag 13 has been replaced with a new field tracer_config of type TracerConfig at the same tag. This is a breaking change that improves type safety and clarity but requires updates to the code that sets or reads this field.

Please consider the following recommendations:

  1. Update the documentation to highlight this breaking change.
  2. Add a release note about this breaking change.

Do you need any assistance in updating the code that sets or reads this field? I'd be happy to help!

Tools
GitHub Check: break-check

[failure] 182-182:
Field "13" with name "tracer_config" on message "TraceConfig" changed cardinality from "optional with implicit presence" to "optional with explicit presence".


[failure] 182-182:
Field "13" with name "tracer_config" on message "TraceConfig" changed option "json_name" from "tracerJsonConfig" to "tracerConfig".


[failure] 182-182:
Field "13" with name "tracer_config" on message "TraceConfig" changed type from "string" to "message".


[failure] 182-182:
Field "13" on message "TraceConfig" changed name from "tracer_json_config" to "tracer_config".

// ignore error. default to no traceConfig
_ = json.Unmarshal([]byte(req.TraceConfig.TracerJsonConfig), &tracerConfig)
tracerConfig, _ = json.Marshal(req.TraceConfig.TracerConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle the error from marshaling the tracer configuration.

Ignoring the error from marshaling the TracerConfig could lead to unexpected behavior if there's an error. Consider handling the error, for example:

-tracerConfig, _ = json.Marshal(req.TraceConfig.TracerConfig)
+tracerConfig, err = json.Marshal(req.TraceConfig.TracerConfig)
+if err != nil {
+    return nil, grpcstatus.Error(grpccodes.Internal, err.Error())
+}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tracerConfig, _ = json.Marshal(req.TraceConfig.TracerConfig)
tracerConfig, err = json.Marshal(req.TraceConfig.TracerConfig)
if err != nil {
return nil, grpcstatus.Error(grpccodes.Internal, err.Error())
}

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 66.26%. Comparing base (64beba7) to head (df44162).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
x/evm/keeper/grpc_query.go 25.00% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2031      +/-   ##
==========================================
- Coverage   66.26%   66.26%   -0.01%     
==========================================
  Files         265      265              
  Lines       16746    16749       +3     
==========================================
+ Hits        11097    11098       +1     
- Misses       4810     4811       +1     
- Partials      839      840       +1     
Files with missing lines Coverage Δ
app/app.go 56.20% <ø> (ø)
x/evm/keeper/grpc_query.go 82.30% <25.00%> (-0.37%) ⬇️

@Unique-Divine Unique-Divine merged commit 6ba79bb into main Sep 12, 2024
18 of 19 checks passed
@Unique-Divine Unique-Divine deleted the fix/evm-debug branch September 12, 2024 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants