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: avoid model classhash conflicts when some models have a same name #2457

Merged
merged 1 commit into from
Sep 22, 2024

Conversation

remybar
Copy link
Contributor

@remybar remybar commented Sep 20, 2024

Related to #2349.

Replaced the PR #2406 as @glihm noticed that model name conflicts came from classhash conflicts.

This is due to the fact that all model contract functions call dojo::model::Model<> and so, two model contract with a same model name but in 2 different namespaces produce the same code and so, the same classhash.

This PR just replaces some calls to dojo::model::Model<> by directly returning the hardcoded value, as it is done in dojo::model::Model<>.

Summary by CodeRabbit

  • New Features

    • Simplified model implementations by replacing method calls with static values for various attributes, enhancing performance and reliability.
  • Bug Fixes

    • Updated transaction hashes in manifest files to reflect new values, ensuring accurate transaction tracking.
  • Documentation

    • Updated manifest files to maintain consistency and clarity in deployment configurations.

Copy link

coderabbitai bot commented Sep 20, 2024

Walkthrough

Ohayo, sensei! The changes in this pull request focus on the dojo-lang crate, specifically modifying the DojoModelImpl implementation for various models. The updates replace dynamic method calls with static string literals and constants for several functions, simplifying the model implementations. Additionally, the transaction hash in two manifest files has been updated to reflect a new value, while other fields remain unchanged.

Changes

Files Change Summary
crates/dojo-lang/src/model.rs Updated DojoModelImpl methods to return static values instead of dynamic method calls for name, namespace, tag, version, selector, name_hash, and namespace_hash.
crates/dojo-lang/src/plugin_test_data/model Similar updates to multiple models, returning hardcoded values for name, namespace, tag, version, selector, name_hash, and namespace_hash.
examples/spawn-and-move/manifests/dev/deployment/manifest.json Modified transaction_hash from "0x506e4efa5fa9ce5808a482b7076db8ca707a013bafaebf089206f28cd5f6bb6" to "0x4c8e0d28e32c21f29f33ff68e245b65fcc91763abf53f284cce8c2274ff6115".
examples/spawn-and-move/manifests/dev/deployment/manifest.toml Updated transaction_hash from "0x506e4efa5fa9ce5808a482b7076db8ca707a013bafaebf089206f28cd5f6bb6" to "0x4c8e0d28e32c21f29f33ff68e245b65fcc91763abf53f284cce8c2274ff6115".

Possibly related PRs

  • fix(sozo): update Controller dependencies #2303: The changes in this PR involve updating dependencies related to the Controller, which may interact with the DojoModelImpl modifications in the main PR, particularly if the Controller relies on the models being updated to return static values instead of dynamic method calls.

Suggested labels

sozo


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 82a23a5 and d4051cb.

Files selected for processing (4)
  • crates/dojo-lang/src/model.rs (1 hunks)
  • crates/dojo-lang/src/plugin_test_data/model (20 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/manifest.json (1 hunks)
  • examples/spawn-and-move/manifests/dev/deployment/manifest.toml (1 hunks)
Additional comments not posted (22)
crates/dojo-lang/src/plugin_test_data/model (13)

791-791: Ohayo sensei! The changes to bad_model_multiple_versions look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 795-795, 799-799, 803-803, 807-807, 811-811, 815-815


1619-1619: Ohayo sensei! The changes to bad_model_bad_version_type look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 1623-1623, 1627-1627, 1631-1631, 1635-1635, 1639-1639, 1643-1643


2447-2447: Ohayo sensei! The changes to bad_model_no_version_value look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 2451-2451, 2455-2455, 2459-2459, 2463-2463, 2467-2467, 2471-2471


3275-3275: Ohayo sensei! The changes to bad_model_unexpected_arg_with_value look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 3279-3279, 3283-3283, 3287-3287, 3291-3291, 3295-3295, 3299-3299


4103-4103: Ohayo sensei! The changes to bad_model_unexpected_arg look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 4107-4107, 4111-4111, 4115-4115, 4119-4119, 4123-4123, 4127-4127


4931-4931: Ohayo sensei! The changes to bad_model_not_supported_version look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 4935-4935, 4939-4939, 4943-4943, 4947-4947, 4951-4951, 4955-4955


5759-5759: Ohayo sensei! The changes to modelv0 look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 5763-5763, 5767-5767, 5771-5771, 5775-5775, 5779-5779, 5783-5783


6587-6587: Ohayo sensei! The changes to model_with_bad_namespace_format look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 6591-6591, 6595-6595, 6599-6599, 6603-6603, 6607-6607, 6611-6611


7415-7415: Ohayo sensei! The changes to model_with_short_string_namespace look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 7419-7419, 7423-7423, 7427-7427, 7431-7431, 7435-7435, 7439-7439


8243-8243: Ohayo sensei! The changes to model_with_string_namespace look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 8247-8247, 8251-8251, 8255-8255, 8259-8259, 8263-8263, 8267-8267


9071-9071: Ohayo sensei! The changes to position look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 9075-9075, 9079-9079, 9083-9083, 9087-9087, 9091-9091, 9095-9095


9895-9895: Ohayo sensei! The changes to roles look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 9899-9899, 9903-9903, 9907-9907, 9911-9911, 9915-9915, 9919-9919


10651-10651: Ohayo sensei! The changes to only_key_model look good to me.

The hardcoded values align with the model's attributes and simplify the implementation. LGTM!

Also applies to: 10655-10655, 10659-10659, 10663-10663, 10667-10667, 10671-10671, 10675-10675

examples/spawn-and-move/manifests/dev/deployment/manifest.toml (1)

7-7: Ohayo sensei! LGTM, the updated transaction_hash looks good.

The change to the transaction_hash appears to be a routine update reflecting a new deployment transaction. As long as this matches the actual deployment transaction hash, it should be fine.

crates/dojo-lang/src/model.rs (7)

715-715: Ohayo sensei! The change looks good.

Returning a string literal for the model name instead of calling dojo::model::Model::<$type_name$>::name() aligns well with the PR objective to avoid model classhash conflicts.


719-719: Looks great sensei!

Returning a string literal for the model namespace instead of calling dojo::model::Model::<$type_name$>::namespace() is a good change that helps avoid model classhash conflicts as intended in this PR.


723-723: Ohayo! This change is spot on.

Using a string literal for the model tag instead of calling dojo::model::Model::<$type_name$>::tag() helps achieve the goal of avoiding model classhash conflicts. Well done sensei!


727-727: Ohayo sensei! This looks perfect.

Returning a constant for the model version instead of calling dojo::model::Model::<$type_name$>::version() is an excellent way to avoid model classhash conflicts as intended in this PR. Great job!


731-731: Ohayo! This change is right on the money.

Using a constant for the model selector instead of calling dojo::model::Model::<$type_name$>::selector() is a great approach to avoid model classhash conflicts. Nicely done sensei!


735-735: Ohayo sensei! This change looks spot on.

Returning a constant for the model name hash instead of calling dojo::model::Model::<$type_name$>::name_hash() is an effective way to avoid model classhash conflicts as intended in this PR. Excellent work!


739-739: Ohayo! This change is perfect sensei.

Using a constant for the model namespace hash instead of calling dojo::model::Model::<$type_name$>::namespace_hash() helps achieve the goal of avoiding model classhash conflicts. Great job!

examples/spawn-and-move/manifests/dev/deployment/manifest.json (1)

1238-1238: Ohayo sensei! The transaction_hash update looks good to me.

The transaction_hash field has been updated to reflect a new transaction hash value. This change is valid and can be safely merged.


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

codecov bot commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.30%. Comparing base (82a23a5) to head (d4051cb).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2457   +/-   ##
=======================================
  Coverage   68.29%   68.30%           
=======================================
  Files         365      365           
  Lines       48034    48034           
=======================================
+ Hits        32805    32809    +4     
+ Misses      15229    15225    -4     

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

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Thanks @remybar!

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