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

Support withLog tracer config key for callTracer #711

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Dec 18, 2024

Closes: #710

Description


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Enhanced logging functionality for transaction results, allowing for better traceability.
    • Updated test cases to capture logs during tracing and validate new contract methods.
  • Bug Fixes

    • Improved error handling and logging in tracing processes to address potential issues with configuration matching.
  • Tests

    • Expanded test cases to validate changes in contract methods and ensure accurate tracing of logs and transaction behavior.

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

This pull request introduces enhancements to the tracing and logging capabilities across multiple components of the EVM system. The changes focus on improving log capture during transaction tracing, specifically enabling the ability to return logs when the withLog configuration is set. Modifications span the debug API, block executor, and test suite, with a consistent goal of providing more comprehensive transaction trace information.

Changes

File Change Summary
api/debug.go - Updated TraceCall method to capture and log transaction results
- Enhanced isDefaultCallTracer function with whitespace trimming comment
services/evm/executor.go - Added log processing loop in Run method to support external tracers
tests/web3js/debug_traces_test.js - Updated test cases with withLog and onlyTopCall configurations
- Modified contract method signatures to test new tracing capabilities

Assessment against linked issues

Objective Addressed Explanation
Call tracer should return logs when withLog is enabled [#710]

Possibly related PRs

  • Fix error handling for transaction traces #560: This PR modifies error handling in the TraceBlockByNumber and TraceBlockByHash functions in api/debug.go, which is directly related to the changes made in the main PR that also focuses on enhancing error handling in the DebugAPI struct methods.
  • extract trace block common logic #608: This PR introduces modifications to the TraceTransaction, TraceBlockByNumber, and TraceBlockByHash methods in api/debug.go, which are also part of the changes in the main PR, indicating a direct connection in the handling of tracing logic.
  • Add support for debug trace APIs #291: This PR adds new methods to the DebugAPI struct in api/debug.go, which is relevant as the main PR also modifies existing methods within the same struct, focusing on enhancing logging and error handling capabilities.

Suggested labels

Improvement

Suggested reviewers

  • peterargue
  • sideninja
  • zhangchiqing

Poem

🐰 Tracing logs with rabbit's might,
Through EVM's complex digital flight,
Configs set, secrets unfurl,
Each transaction's tale we'll swirl,
Debugging magic takes its height! 🔍


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

@m-Peter m-Peter force-pushed the feature/local-tx-reexecution branch from 2121836 to a746c82 Compare December 18, 2024 11:30
@m-Peter m-Peter force-pushed the mpeter/support-call-tracer-with-logs branch from ac8a8c8 to 9f7ca96 Compare December 18, 2024 13:02
Base automatically changed from feature/local-tx-reexecution to main December 19, 2024 09:12
@m-Peter m-Peter force-pushed the mpeter/support-call-tracer-with-logs branch from 9f7ca96 to 4846135 Compare December 19, 2024 14:18
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: 0

🧹 Nitpick comments (4)
tests/web3js/debug_traces_test.js (2)

25-26: Prefer stable naming or comments explaining these new tracer settings.

By setting "withLog" to true and "onlyTopCall" to false, the call tracer will capture logs and delve into nested calls. This can produce more verbose results, which may be intended. If performance concerns arise, consider documenting or gating these settings.


569-570: Logs disabled for deeper calls.

Setting "withLog" to false but "onlyTopCall" to false disables log capture yet still explores subcalls. If the intent is to skip logs entirely, ensure clarity in documentation about handling deeper calls.

services/evm/executor.go (1)

109-113: Send transaction logs to tracer for external handling.

You’ve added logic to pass each log in “res.Logs” to the tracer. This is crucial for capturing on-chain events. If logs can be large or numerous, monitor the potential performance impact, and consider batching or streaming if needed.

api/debug.go (1)

244-249: Push logs captured from DryCall to the tracer’s OnLog method.

This block ensures that logs from a simulated (DryCall) transaction are made visible to the tracer. Validate that only relevant events are included—especially if calls are expanded or partial logs are needed for performance reasons.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4ce4cc and 4846135.

📒 Files selected for processing (3)
  • api/debug.go (2 hunks)
  • services/evm/executor.go (1 hunks)
  • tests/web3js/debug_traces_test.js (12 hunks)
🔇 Additional comments (14)
tests/web3js/debug_traces_test.js (12)

74-74: Confirm correctness of the new method name.

The function is now “storeWithLog(100n)” instead of the old “store”. Ensure that dependencies and references to the old method are updated throughout the codebase, especially on the contract side.


96-97: Validate updated gas usage assertions.

Gas and gasUsed have changed to "0x6f9a" and "0x6e3f" respectively. Confirm that these new expected values reflect actual execution costs and are not incidental or prone to fluctuation.


131-131: Verify the updated balance in prestate tracer.

The expected “0x4098ea” balance should align with the actual transaction logic. Confirm that this matches any discount, fee, or updated logic in the contract or the test environment.


135-135: Check consistency for newly reported nonce.

The updated state includes nonce = 2. Ensure prior transactions and the final expected state transitions all align with this incremented nonce.


149-149: Confirm 4-byte tracer outputs.

The tracer output “{ '0x6babb224-32': 1 }” indicates a traced signature. Verify that this is indeed the correct mapping for the storeWithLog or sum method signature.


165-183: Enhanced log checking for the transaction trace.

Multiple lines here assert correct logs, contract address, input data, and the transaction hash. Confirm that the log’s data and topics (lines 175-181) match the contract event signature for storeWithLog(100n).


189-189: Confirm consistency of new transaction hash.

The transaction “0x828d174e…” is expected to produce outcomes distinct from the first transaction. Ensure the test environment consistently differentiates these two traces.


196-196: Review updated “value” field in logs.

The test sets “value” to 0x4098ea. Confirm that this aligns with the contract’s logic and any newly introduced transaction costs or adjustments.


216-234: Consolidated log trace validation.

Similar to line 165, these lines confirm the event logs for the same transaction in debug_traceBlockByHash. Ensure consistency between traceBlockByNumber and traceBlockByHash results for this log set.


240-247: Verify new transaction hash and minted value.

The second transaction "0x828d174e..." is assigned a minted or transferred value of 0x4098ea. Validate that the block’s final state matches these expected changes, especially if any fees or additional logic are triggered.


606-613: Reintroducing log capture for subcalls.

Switching back to "withLog: true" while "onlyTopCall: false" allows capturing all logs from nested calls. Confirm the extra data doesn’t cause performance degradation in production.


615-657: New sum(500, 100) call trace.

This final block tests the newly introduced “sum” functionality and verifies logs. Ensure the contract properly emits the log with correct data in “data: '0x000000000000000...00000258'” and the computed total (0x258 = 600).

api/debug.go (2)

232-232: Dry-call integration point.

You’re capturing the transaction result from “DryCall” to apply exposure to tracers. Ensure any future changes to “DryCall” signature or returned data structure remain backward-compatible with existing instrumentation code.


488-490: Whitespace trimming for default tracer config.

This addresses configuration mismatch caused by spacing. If user-supplied JSON includes newlines or other whitespace variations, trimming ensures consistent comparisons to “replayer.TracerConfig”. This minor detail prevents subtle configuration bugs.

@m-Peter m-Peter force-pushed the mpeter/support-call-tracer-with-logs branch from 4846135 to d86fa3d Compare December 19, 2024 16:58
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: 0

🧹 Nitpick comments (2)
tests/web3js/debug_traces_test.js (2)

Line range hint 315-358: Consider adding negative test cases

While the positive test case for withLog: true is good, consider adding test cases for:

  • withLog: false to verify logs are not included
  • Invalid configurations to verify error handling

608-658: Enhance test coverage for the new sum method

The test case for the sum method looks good, but consider adding:

  1. Edge cases (e.g., large numbers, zero values)
  2. Error cases (e.g., overflow scenarios)

Example test cases to add:

// Test edge cases
callData = deployed.contract.methods.sum(Number.MAX_SAFE_INTEGER, 1).encodeABI()
// Test zero values
callData = deployed.contract.methods.sum(0, 0).encodeABI()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4846135 and d86fa3d.

📒 Files selected for processing (3)
  • api/debug.go (2 hunks)
  • services/evm/executor.go (1 hunks)
  • tests/web3js/debug_traces_test.js (13 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • services/evm/executor.go
  • api/debug.go
🔇 Additional comments (3)
tests/web3js/debug_traces_test.js (3)

25-26: LGTM: Proper configuration of withLog and onlyTopCall

The configuration aligns with the PR objective to support the withLog tracer config key.


642-655: Verify the log data format for the sum event

The test asserts a specific format for the sum event log:

  • Data field contains the sum result
  • Topics include the event signature and two indexed parameters
    Please verify this matches the contract's event definition.
✅ Verification successful

The log format matches the contract's event definition

The test's log format correctly matches the Calculated event definition from the contract:

  • Event signature in first topic (0x76efea...)
  • Three indexed parameters in the remaining topics:
    • sender (address)
    • numA (uint256)
    • numB (uint256)
  • Non-indexed sum parameter in the data field
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find the sum event definition
ast-grep --pattern 'event $name(address indexed sender, uint256 indexed a, uint256 indexed b, uint256 sum) {
  $$$
}'

Length of output: 119


Script:

#!/bin/bash
# Let's try a different pattern to find event definitions related to sum
ast-grep --pattern 'event $name($$$) $$$'

# Also search for Solidity files that might contain the event definition
fd -e sol

# Search for files containing "sum" and "event" keywords
rg -l "event.*sum|sum.*event"

Length of output: 251


Script:

#!/bin/bash
# Let's examine the storage.sol file which seems to contain the event definition
cat tests/fixtures/storage.sol

# Also check the test file for context
rg -A 5 -B 5 "event.*sum|sum.*event" tests/fixtures/storage.sol

Length of output: 3579


173-184: Verify the log event signature and topics

The test asserts the presence of logs with specific topics. Please verify:

  1. The event signature hash matches the contract's event definition
  2. The indexed parameters are correctly ordered in the topics array
✅ Verification successful

The previous command didn't yield results because the pattern wasn't matching Solidity event definitions correctly. Let's try searching for event definitions in Solidity files and examine the test file to understand the context better. This will help us verify the event signature and topics alignment.


The test file shows that we're dealing with a storage contract, and we need to verify the event signature and topics. Let's examine the contract implementation to find the event definition and verify the signature matches.


From examining the test file and contract code, I can now generate the final response. The test is verifying a log event from the storeWithLog function in the Storage contract, which emits a NewStore event.

Event signature and topics are correctly implemented

The event signature and topics in the test match the contract's event definition:

  1. Event signature hash 0x043cc306157a91d747b36aba0e235bbbc5771d75aba162f6e5540767d22673c6 corresponds to NewStore(address indexed caller, uint256 indexed value)
  2. Topics are correctly ordered:
    • Topic[0]: Event signature hash
    • Topic[1]: Indexed parameter caller (address)
    • Topic[2]: Indexed parameter value (uint256)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find the event definition in the contract
ast-grep --pattern 'event $name($$$) {
  $$$
}'

Length of output: 49


Script:

#!/bin/bash
# Search for event definitions in Solidity files
rg -t sol "event.*\(" --no-filename

# Search for test file content to understand the context
cat tests/web3js/debug_traces_test.js

Length of output: 22116


Script:

#!/bin/bash
# Let's find the contract implementation to verify the event signature
fd -t f "storage" --exec cat {}

Length of output: 40519

@m-Peter m-Peter merged commit 2b10491 into main Dec 20, 2024
2 checks passed
@m-Peter m-Peter deleted the mpeter/support-call-tracer-with-logs branch December 20, 2024 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Call tracer should return logs when the withLog config is enabled
3 participants