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

refactor(torii): entity update without being set before #3072

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Feb 27, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved record updates to safely handle scenarios when keys are missing.
    • Now provides clear warning messages when an update is attempted on a record that hasn’t been initialized.
  • Documentation

    • Enhanced internal guidance to clarify conditions under which updates occur.
  • Refactor

    • Simplified function signatures and removed unnecessary type aliases for better clarity and maintainability.
    • Introduced conditional checks to improve the handling of entity keys during updates.
  • Chores

    • Updated the ERC1155Token contract's class_hash and address to reflect recent changes in deployment or configuration.

Copy link

coderabbitai bot commented Feb 27, 2025

Ohayo sensei, here’s the detailed summary:

Walkthrough

The changes refine the handling of entity updates across several modules. In the gRPC service, the process_entity_update method now checks if entity.keys is empty and initializes an empty vector if so; otherwise, it processes the keys. In the SQLite executor, a warning is logged when an update is attempted with an empty keys vector, and the construction of OptimisticEntity is adjusted to occur after this check. The set_entity_model and set_entity methods have simplified function signatures, removing unnecessary type aliases. No changes affect public declarations.

Changes

File Path Change Summary
crates/torii/grpc/.../entity.rs Updated process_entity_update to conditionally set the keys vector as empty when entity.keys is empty; otherwise, it trims, splits, and processes the keys into a vector of Felt values. Updated comments for clarity.
crates/torii/sqlite/.../mod.rs Introduced a warning log when an update is attempted with an empty keys vector. Adjusted the control flow to log a warning and then construct an OptimisticEntity using std::mem::transmute.
crates/torii/sqlite/.../lib.rs Removed type aliases and simplified function signatures in set_entity_model and set_entity methods; updated internal logic to streamline handling of entity IDs and models.

Possibly related PRs

  • refactor(torii-grpc): empty hashed keys in subscription match all entities #2154: The changes in the main PR regarding the handling of empty keys in the process_entity_update method are related to the modifications in the retrieved PR that also address conditions for empty keys in the Service implementation, specifically in the context of entity updates.
  • fix(torii-grpc): event processing subscription #2975: The changes in the main PR regarding the handling of empty keys in the process_entity_update method are related to the filtering logic introduced in the process_event method of the retrieved PR, as both modifications aim to enhance robustness by excluding empty values from processing.
  • opt-fix(torii-core): fix and optimize partial updates #2427: The changes in the main PR, which enhance key handling in the process_entity_update method, are related to the modifications in the retrieved PR that streamline key management in the set_entity method, as both involve improvements to how entity keys are processed during updates.

Suggested reviewers

  • glihm

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ca068d9 and 5ab6d03.

📒 Files selected for processing (2)
  • crates/torii/sqlite/src/lib.rs (4 hunks)
  • examples/spawn-and-move/manifest_dev.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/torii/sqlite/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
examples/spawn-and-move/manifest_dev.json (2)

3771-3772: Ohayo sensei: Confirm Updated ERC1155Token Class Hash

The class_hash for the ERC1155Token instance "Rewards" has been updated to "0x342e7234ef0066eaf28438eb8e2013a711548ee1b8f4b286f6e2dad44fc5a0b". Please double-check that this value aligns with the intended deployment configuration and is referenced consistently across the system.


3774-3774: Ohayo sensei: Verify Updated ERC1155Token Address

The new address for the "Rewards" contract is "0x357e29a60b3c5b809695dc8b2e0d43f07be8e7654dd1b7378989dd6c51bb798". Make sure this address is accurate per the latest deployment records and that all interactions with this contract are updated accordingly.


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

🧹 Nitpick comments (2)
crates/torii/sqlite/src/executor/mod.rs (1)

454-460: Ohayo! Warning message could be clearer about what's actually happening.

The warning message says the entity update is "ignored", but the code still proceeds with publishing the entity through SimpleBroker and adding it to the publish_queue. This mismatch between the warning message and actual behavior could cause confusion.

if entity_updated.keys.is_empty() {
-    warn!(target: LOG_TARGET, "Entity update ignored. An entity must be set with StoreSetRecord before it can be updated with StoreUpdateRecord or StoreUpdateMember.");
+    warn!(target: LOG_TARGET, "Entity update has empty keys. An entity must be set with StoreSetRecord before it can be updated with StoreUpdateRecord or StoreUpdateMember.");
}
crates/torii/grpc/src/server/subscriptions/entity.rs (1)

117-129: Wonderful improvement in handling empty keys, sensei!

The conditional check for empty keys improves robustness by preventing unnecessary parsing attempts. This addresses the case where an entity is updated without being set before.

There's a formatting issue that's causing the CI pipeline to fail. Please fix the indentation of your comments:

-        // keys is empty when an entity is updated with StoreUpdateRecord or Member but the entity has never been set before.
-        // In that case, we dont know the keys
+        // Keys is empty when an entity is updated with StoreUpdateRecord or Member but 
+        // the entity has never been set before. In that case, we don't know the keys.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aafa666 and 0dbc6a4.

📒 Files selected for processing (2)
  • crates/torii/grpc/src/server/subscriptions/entity.rs (1 hunks)
  • crates/torii/sqlite/src/executor/mod.rs (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: ci
crates/torii/grpc/src/server/subscriptions/entity.rs

[error] 114-114: Rust formatting check failed. Please run 'rustfmt' to format the code.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

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

Project coverage is 57.36%. Comparing base (aafa666) to head (5ab6d03).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/grpc/src/server/subscriptions/mod.rs 0.00% 4 Missing ⚠️
...ates/torii/grpc/src/server/subscriptions/entity.rs 0.00% 1 Missing ⚠️
crates/torii/sqlite/src/executor/mod.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3072      +/-   ##
==========================================
- Coverage   57.38%   57.36%   -0.03%     
==========================================
  Files         440      440              
  Lines       59963    59942      -21     
==========================================
- Hits        34411    34386      -25     
- Misses      25552    25556       +4     

☔ 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

🧹 Nitpick comments (1)
crates/torii/grpc/src/server/subscriptions/mod.rs (1)

41-44: Early return for empty clause_model is a solid improvement!

Ohayo sensei! I like this addition of an early return when a clause_model is empty. It properly handles the scenario where an empty model clause should be considered a match, consistent with the "match all" philosophy used elsewhere in the code (like with empty namespaces or "*" wildcards).

Adding a brief comment would help future maintainers understand the reasoning:

 if clause_model.is_empty() {
+    // Empty model clause is treated as a wildcard that matches everything
     return true;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ce53b91 and ca068d9.

📒 Files selected for processing (1)
  • crates/torii/grpc/src/server/subscriptions/mod.rs (1 hunks)

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.

1 participant