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

Index field on receipt logs does not return correct value for blocks with multiple transactions & logs #462

Merged
merged 3 commits into from
Aug 26, 2024

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Aug 21, 2024

Closes: #461

Description

The Index field should be relative to the entire block, and not scoped to the receipt that emitted the log.


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 test capabilities for batch transactions with logs in the Ethereum context.
    • Introduced comprehensive tests for validating batch transaction retrieval and associated logs.
  • Bug Fixes

    • Clarified comments in the codebase to improve documentation and readability.
  • Chores

    • Updated project dependencies to improve functionality related to testing and data comparisons.
  • Tests

    • Added new tests for batch transactions and log validation.
    • Simplified existing test files by removing unused imports.

@m-Peter m-Peter added the Bugfix label Aug 21, 2024
@m-Peter m-Peter added this to the Flow-EVM-M2 milestone Aug 21, 2024
@m-Peter m-Peter self-assigned this Aug 21, 2024
Copy link
Contributor

coderabbitai bot commented Aug 21, 2024

Walkthrough

The updates enhance the handling of log indices in the blockchain by ensuring that the logIndex reflects the correct position of logs within a block, rather than being limited to a receipt's scope. This improves the clarity and accuracy of log retrieval across multiple transactions. Additionally, new tests validate batch transaction handling and log retrieval, bolstering the overall robustness of the codebase.

Changes

Files Change Summary
models/events.go Updated documentation for logIndex in NewCadenceEvents for clarity without altering logic.
storage/.../receipts.go Introduced logIndex to track logs' positions across blocks, ensuring consistent indexing and setting Removed field to false.
storage/index_testsuite.go Added log indexing logic in TestStoreReceipt for tracking log indices across receipts.
tests/e2e_web3js_test.go Enhanced TestWeb3_E2E to batch run transactions and validate logs. New global variables for bytecode and ABI added.
tests/web3js/..._test.js Created eth_batch_tx_logs_test.js for testing batch transaction log retrieval. Removed unused web3 import in eth_logs_filtering_test.js.
tests/go.mod Added indirect dependencies for improved testing and comparison functionalities.

Sequence Diagram(s)

sequenceDiagram
    participant B as Blockchain
    participant T as Transaction Handler
    participant R as Receipt Handler
    participant L as Log Processor

    T->>B: Submit Batch Transactions
    B-->>T: Confirm Transactions
    T->>R: Retrieve Receipts
    R-->>T: Return Receipts
    T->>L: Process Logs
    L-->>T: Return Logs with Correct Indices
    T->>B: Validate Transaction Execution
Loading

Assessment against linked issues

Objective Addressed Explanation
Index field on receipt logs does not return correct value for blocks with multiple transactions & logs (#[461])

🐰 In the meadow, the logs now align,
With indices clear, each number will shine.
No more confusion, as we hop and play,
Transactions in batches lead the way!
So raise your paws, let's cheer with delight,
For clearer code makes our future bright! 🌼✨


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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between daa037a and 9f4d25b.

Files selected for processing (7)
  • models/events.go (1 hunks)
  • storage/index_testsuite.go (1 hunks)
  • storage/pebble/receipts.go (1 hunks)
  • tests/e2e_web3js_test.go (2 hunks)
  • tests/go.mod (2 hunks)
  • tests/web3js/eth_batch_tx_logs_test.js (1 hunks)
  • tests/web3js/eth_logs_filtering_test.js (1 hunks)
Files skipped from review due to trivial changes (2)
  • models/events.go
  • tests/web3js/eth_logs_filtering_test.js
Additional comments not posted (5)
tests/web3js/eth_batch_tx_logs_test.js (1)

5-39: Comprehensive test coverage for batch transactions and logs.

The test logic and assertions provide thorough validation of batch transaction handling and log retrieval.

storage/pebble/receipts.go (1)

146-157: Changes align with PR objectives.

The introduction of logIndex ensures accurate log indexing within a block. Setting Removed to false is a good practice for consistency.

tests/e2e_web3js_test.go (1)

125-187: Comprehensive and well-structured tests for batch transactions with logs.

The tests enhance coverage for batch transactions and log emission, using embedded resources effectively.

tests/go.mod (1)

84-84: Dependencies added successfully.

The additions of github.com/google/go-cmp v0.6.0 and gotest.tools v2.2.0+incompatible as indirect dependencies enhance comparison operations and testing capabilities.

Also applies to: 236-236

storage/index_testsuite.go (1)

188-195: Log indexing logic implemented correctly.

The new logic for indexing logs within a block is implemented correctly and aligns with the PR objectives.

However, ensure that related functions correctly handle the updated log indexing.

Run the following script to verify the usage of log indexing in related functions:

tests/web3js/eth_batch_tx_logs_test.js Show resolved Hide resolved
@m-Peter m-Peter force-pushed the fix-log-index-calculation branch from 9f4d25b to e9c90fa Compare August 21, 2024 14:25
@m-Peter m-Peter force-pushed the fix-log-index-calculation branch from e9c90fa to 339bd37 Compare August 21, 2024 14:27
l.Index = uint(i)
l.Index = logIndex
l.Removed = false
logIndex++
Copy link
Contributor

Choose a reason for hiding this comment

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

damn, nice find

Copy link
Contributor

@sideninja sideninja left a comment

Choose a reason for hiding this comment

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

Amazing!

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9f4d25b and 13a76db.

Files selected for processing (7)
  • models/events.go (1 hunks)
  • storage/index_testsuite.go (1 hunks)
  • storage/pebble/receipts.go (1 hunks)
  • tests/e2e_web3js_test.go (2 hunks)
  • tests/go.mod (2 hunks)
  • tests/web3js/eth_batch_tx_logs_test.js (1 hunks)
  • tests/web3js/eth_logs_filtering_test.js (1 hunks)
Files skipped from review due to trivial changes (2)
  • models/events.go
  • tests/web3js/eth_logs_filtering_test.js
Files skipped from review as they are similar to previous changes (4)
  • storage/index_testsuite.go
  • storage/pebble/receipts.go
  • tests/go.mod
  • tests/web3js/eth_batch_tx_logs_test.js
Additional comments not posted (3)
tests/e2e_web3js_test.go (3)

4-4: LGTM!

The embed package is correctly imported.

The code changes are approved.


17-23: LGTM!

The storageByteCode and storageABI variables are correctly declared and embedded.

The code changes are approved.


125-188: LGTM!

The batch run transactions with logs test case is comprehensive and correctly implemented. It covers the deployment of a contract and subsequent contract calls that emit logs. The test case ensures that each transaction executes successfully.

The code changes are approved.

@sideninja sideninja merged commit 78fe801 into main Aug 26, 2024
2 checks passed
@m-Peter m-Peter deleted the fix-log-index-calculation branch September 5, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Index field on receipt logs does not return correct value for blocks with multiple transactions & logs
2 participants