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(katana-rpc): event idx not respecting cursor's block idx #2578

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 24, 2024

resolves #2574

Summary by CodeRabbit

  • Documentation

    • Enhanced clarity of comments and documentation for event fetching functions.
    • Updated comments for the PartialCursor struct to improve readability.
    • Provided detailed descriptions of parameters and functionality in the fetch_tx_events function.
  • Refactor

    • Refined logic for processing transactions in fetch_pending_events and fetch_events_at_blocks functions to improve cursor handling.

Copy link

coderabbitai bot commented Oct 24, 2024

Walkthrough

Ohayo, sensei! This pull request introduces enhancements to the events.rs file, focusing on improving comment clarity and refining the logic in event fetching functions. Key updates include clearer comments for the PartialCursor struct and adjustments in the fetch_pending_events, fetch_events_at_blocks, and fetch_tx_events functions to better handle cursor logic. These changes aim to ensure that the event fetching process is well-documented and the code is easier to understand.

Changes

File Path Change Summary
crates/katana/rpc/rpc/src/utils/events.rs Updated comments for clarity; refined logic in fetch_pending_events, fetch_events_at_blocks, and fetch_tx_events functions; modified function signatures (no parameter changes).

Assessment against linked issues

Objective Addressed Explanation
Improve event syncing issues in torii (#2574) The changes do not address the syncing issue directly.

Possibly related PRs

  • refactor(katana): remove events trace log #2570: This PR involves changes to event logging, which may relate to the event fetching logic and cursor handling improvements in the main PR, as both deal with event management within the Katana framework.

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

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

@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

🧹 Outside diff range and nitpick comments (2)
crates/katana/rpc/rpc/src/utils/events.rs (2)

279-295: Ohayo! The documentation is much clearer now, sensei!

The new documentation nicely explains the function's purpose and parameters. However, consider adding information about possible error cases to make it even more complete.

Add error cases documentation:

 /// Returns a cursor if it couldn't include all the events of the current transaction because
 /// the buffer is already full. Otherwise, if it is able to include all the transactions,
 /// returns None.
+///
+/// # Errors
+///
+/// Returns `Error` if:
+/// * The provider fails to retrieve transaction data
+/// * The cursor is invalid

Line range hint 322-332: Ohayo! Consider a small optimization, sensei!

The event index tracking logic is correct, but we could optimize the memory usage by avoiding the intermediate Vec collection when we know the exact capacity needed.

Consider this optimization:

-        .collect::<Vec<_>>();
+        .collect::<Vec<_>>() {
+            let mut filtered = Vec::with_capacity(total_can_take);
+            filtered.extend(iter);
+            filtered
+        };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 615e9fd and b7dbc0d.

📒 Files selected for processing (1)
  • crates/katana/rpc/rpc/src/utils/events.rs (6 hunks)
🔇 Additional comments (3)
crates/katana/rpc/rpc/src/utils/events.rs (3)

73-73: Ohayo! Nice documentation improvement, sensei!

The updated comment better clarifies that the PartialCursor points to a specific event within the context of a transaction, which helps prevent confusion about its scope.


Line range hint 1-370: Ohayo! Let's verify the complete fix, sensei!

The changes look solid and properly address the syncing issues mentioned in #2574. To ensure the fix is complete, we should verify:

  1. The cursor properly maintains state across block boundaries
  2. Edge cases are handled correctly when events span multiple blocks

Let's verify the complete fix:


180-198: Ohayo! This fix looks solid, sensei!

The improved cursor logic correctly handles event index determination by:

  1. Properly checking if we're at the cursor's exact position (block and transaction)
  2. Correctly handling the case where the cursor points to an event index that's either:
    • Less than total events (continue processing from that index)
    • Equal/Greater than total events (skip to next transaction)

This change directly addresses the core issue where event idx wasn't respecting the cursor's block idx.

Let's verify the fix with this script:

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 18.18182% with 27 lines in your changes missing coverage. Please review.

Project coverage is 69.47%. Comparing base (4930450) to head (b7dbc0d).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/rpc/rpc/src/utils/events.rs 18.18% 27 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2578      +/-   ##
==========================================
- Coverage   69.58%   69.47%   -0.12%     
==========================================
  Files         401      401              
  Lines       50745    50817      +72     
==========================================
- Hits        35312    35306       -6     
- Misses      15433    15511      +78     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kariy kariy merged commit 17f2564 into main Oct 24, 2024
13 of 15 checks passed
@kariy kariy deleted the katana/fix-event-index-not-respecting-block-cusor branch October 24, 2024 16:08
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.

[katana/torii] Issues with syncing on torii launch
1 participant