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: keys composite clause #2798

Merged
merged 4 commits into from
Dec 12, 2024
Merged

fix: keys composite clause #2798

merged 4 commits into from
Dec 12, 2024

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Dec 12, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced query capabilities for handling composite queries and SQL pattern construction.
    • Introduced a new configuration file for blockchain settings, including parameters for indexing and world block specifications.
    • Added a new field to specify the starting block number for indexing in the CLI options.
  • Bug Fixes

    • Improved error handling for invalid namespaced models.
    • Enhanced logging and logic for fetching entities and processing data.

Copy link

coderabbitai bot commented Dec 12, 2024

Walkthrough

Ohayo, sensei! This pull request introduces modifications across several files, primarily enhancing the functionality of the fetch_entities and build_keys_pattern functions in the mod.rs file of the crates/torii/grpc/src/server directory. Key updates include improved logging and error handling in fetch_entities, adjustments to regex pattern construction in build_keys_pattern, and the addition of a world_block field in various configurations to facilitate more flexible data processing. The overall structure remains intact while allowing for enhanced functionality and configurability.

Changes

File Path Change Summary
crates/torii/grpc/src/server/mod.rs - Enhanced fetch_entities with additional logging and modified logic for inserting entity IDs.
- Updated build_keys_pattern to prepend a forward slash to regex patterns for VariableLen.
- Improved build_composite_clause to include model checks in composite queries.
bin/torii/src/main.rs - Added world_block field to EngineConfig and updated error handling logic.
crates/torii/cli/src/options.rs - Introduced world_block field in IndexingOptions with default value and updated merge method.
crates/torii/core/src/engine.rs - Added world_block field to EngineConfig, updated default implementation, and modified fetch_data logic.
eternum.toml - Created new configuration file with parameters including world_address, rpc, and indexing settings.

Possibly related PRs

Suggested reviewers

  • glihm

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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 (1)
crates/torii/grpc/src/server/mod.rs (1)

1165-1176: Ohayo, sensei! Consider optimizing model checks in composite clauses

The current implementation uses group_concat and INSTR to check for the presence of model IDs in having_clauses. For large datasets, this might impact performance. Consider using EXISTS or additional JOIN clauses to improve query efficiency when filtering by models.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bcd581e and fcea536.

📒 Files selected for processing (1)
  • crates/torii/grpc/src/server/mod.rs (2 hunks)
🔇 Additional comments (1)
crates/torii/grpc/src/server/mod.rs (1)

1127-1127: Ohayo, sensei! The regex pattern correctly handles variable-length keys

The addition of "/({})*" to the keys_pattern ensures that when pattern_matching is set to VariableLen, the regex will match variable-length keys as intended.

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.

Project coverage is 55.74%. Comparing base (bcd581e) to head (22a2f8e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/grpc/src/server/mod.rs 0.00% 34 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2798      +/-   ##
==========================================
- Coverage   55.75%   55.74%   -0.02%     
==========================================
  Files         439      439              
  Lines       55522    55544      +22     
==========================================
+ Hits        30957    30962       +5     
- Misses      24565    24582      +17     

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

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 (1)
crates/torii/grpc/src/server/mod.rs (1)

1177-1179: Consider enhancing the error message for invalid model format.

The error message for invalid namespaced models could be more descriptive to help users understand the expected format.

-        .ok_or(QueryError::InvalidNamespacedModel(model.clone()))?;
+        .ok_or_else(|| QueryError::InvalidNamespacedModel(
+            format!("Invalid model format '{}'. Expected format: 'namespace-model'", model)
+        ))?;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcea536 and 4e51dbe.

📒 Files selected for processing (1)
  • crates/torii/grpc/src/server/mod.rs (3 hunks)
🔇 Additional comments (3)
crates/torii/grpc/src/server/mod.rs (3)

745-763: Ohayo sensei! Clean and well-structured SQL query construction.

The SQL query construction logic elegantly handles both having and non-having clause cases, with proper table aliasing and efficient counting strategies.


1136-1136: Ohayo sensei! Proper path separator handling in regex pattern.

The addition of the forward slash before the KEY_PATTERN ensures correct path separation in variable length matching scenarios.


1174-1186: Ohayo sensei! Solid implementation of model checks in Keys clause.

The addition of model checks through INSTR conditions in the having clause ensures proper validation of model existence.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22a2f8e and 90da3be.

📒 Files selected for processing (5)
  • bin/torii/src/main.rs (1 hunks)
  • crates/torii/cli/src/options.rs (3 hunks)
  • crates/torii/core/src/engine.rs (3 hunks)
  • crates/torii/grpc/src/server/mod.rs (7 hunks)
  • eternum.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • eternum.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/torii/grpc/src/server/mod.rs
🔇 Additional comments (5)
bin/torii/src/main.rs (1)

167-167: Ohayo! LGTM - Clean integration of world_block configuration.

The change correctly propagates the world block configuration from CLI arguments to the engine configuration.

crates/torii/cli/src/options.rs (2)

160-172: Ohayo! Clean implementation of world_block configuration.

The implementation is well-documented and includes proper default values.

Also applies to: 186-186


226-228: LGTM - Proper merge behavior.

The merge function correctly updates world_block only when the current value is 0, maintaining proper override behavior.

crates/torii/core/src/engine.rs (2)

151-151: Ohayo! Clean addition of world_block to engine configuration.

The configuration and default implementation are consistent with the CLI options.

Also applies to: 163-163


328-328: ⚠️ Potential issue

Verify the indexing behavior with non-zero world_block.

The change modifies the starting point for data fetching. This is a significant change that could affect the consistency of indexed data.

Consider adding validation to ensure that setting a non-zero world_block doesn't break data consistency, especially for:

  1. State that depends on sequential block processing
  2. Cumulative calculations that require complete history
  3. Token balances that need accurate historical data

Comment on lines 163 to 165
/// Warning: In the current implementation, this will break the indexing of tokens, if any.
/// Since the tokens require the chain to be indexed from the beginning, to ensure correct
/// balance updates.
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Warning: Token indexing requires sequential block processing, sensei!

Based on the search results and the warning comment, starting indexing from a non-zero block can indeed break token balance tracking. This is because token balance updates need to be processed sequentially from the beginning to maintain accurate state.

Key points:

  • Token indexing requires processing from genesis to maintain correct balance updates
  • Setting a non-zero world_block will skip earlier transactions that may affect token balances
  • This can lead to incorrect token balance states
🔗 Analysis chain

Verify the impact on token indexing, sensei!

The documentation warns about potential issues with token indexing when setting a non-zero world_block. Let's verify this limitation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for token-related indexing logic that might be affected
# Look for token balance update logic
rg -A 5 "balance.*update" 

# Look for token transfer event processors
ast-grep --pattern 'class $_ {
  $$$
  process($_, $_, $block_number, $_, $_, $_, $_) {
    $$$
  }
  $$$
}'

Length of output: 66855


Script:

#!/bin/bash
# Let's check for token balance indexing logic and block number dependencies
# Search for token balance updates with block number context
rg -A 5 "balance.*block.*number"

# Look for token indexing or state update logic
rg -A 5 "token.*index|state.*update"

# Search for block number validation or requirements
rg -A 5 "block.*require|block.*valid"

# Check for any token-related storage operations
rg -A 5 "Storage.*token|token.*storage"

Length of output: 65691


Script:

#!/bin/bash
# Let's check for token indexing and block number dependencies in the codebase
# Search for token indexing implementation
rg -A 5 "index.*token|token.*index"

# Look for block number usage in token-related code
rg -A 5 "block.*number.*token|token.*block"

# Check for any token state management code
rg -A 5 "token.*state|state.*token"

# Search specifically in the torii codebase for token indexing
fd -t f . crates/torii | xargs rg -A 5 "token.*index|index.*token"

Length of output: 69333

@Larkooo Larkooo enabled auto-merge (squash) December 12, 2024 05:02
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus left a comment

Choose a reason for hiding this comment

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

lgtm

@Larkooo Larkooo merged commit 91c76d9 into dojoengine:main Dec 12, 2024
24 of 26 checks passed
kariy pushed a commit that referenced this pull request Dec 13, 2024
* fix: keys composite clause

* count

* c

* f
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