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

feat: add systems to manifest #2642

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Nov 6, 2024

A system is any function found in a dojo contract that is exposed in the ABI with the state mutability as external.
Event if Dojo per se doesn't modify the storage of the contract, it's required that the user explicitely identify the systems with ref self.

Also add selectors of resources in the manifest.

Summary by CodeRabbit

  • New Features

    • Introduced new entrypoints field in multiple data structures to enhance functionality related to world and contract management.
    • Added new functions to improve system identification from ABI entries and batch processing capabilities.
    • Expanded the manifest_dev.json to include new entrypoints and updated contract definitions.
  • Bug Fixes

    • Updated existing data structures to ensure proper initialization of new fields without altering existing functionality.
  • Documentation

    • Enhanced documentation to reflect the new entrypoints and updated contract and world definitions.

A system is any function found in a dojo contract that is exposed in the ABI
with the state mutability as external.
Event if Dojo per se doesn't modify the storage of the contract,
it's required that the user explicitely identify the systems with
ref self.
Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

Ohayo, sensei! This pull request introduces several modifications across multiple files, primarily enhancing the Manifest, WorldLocal, and ABI handling structures. New fields such as entrypoints and selector have been added to various structs, improving data representation for contracts and models. The WorldLocal struct now includes an entrypoints vector, and the manifest_dev.json file has been significantly updated with new functions and structures in its ABI section. These changes aim to improve the management and functionality of contracts and world resources.

Changes

File Path Change Summary
crates/dojo/world/src/diff/manifest.rs - Added pub entrypoints: Vec<String> to WorldContract.
- Added pub selector: Felt to DojoContract, DojoModel, and DojoEvent.
- Updated Manifest::new to populate new fields from diff.world_info and resource.
crates/dojo/world/src/diff/mod.rs - Added pub entrypoints: Vec<String> to WorldStatusInfo.
- Updated WorldDiff to initialize entrypoints from the local world in from_local and new methods.
crates/dojo/world/src/local/artifact_to_local.rs - Added fn systems_from_abi(abi: &[AbiEntry]) -> Vec<String>.
- Updated WorldLocal::from_directory to collect systems from ABI entries into world_entrypoints.
crates/dojo/world/src/local/mod.rs - Added pub entrypoints: Vec<String> to WorldLocal.
- Updated Default implementation to initialize entrypoints as an empty vector.
examples/simple/manifest_dev.json - Updated class_hash and address for world and contracts.
- Added new entrypoints for world.
- Introduced new structs and functions in ABI, including entities and set_entities.
- Added new systems in contracts.

Possibly related issues

Possibly related PRs


🪧 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 (5)
crates/dojo/world/src/local/mod.rs (1)

70-70: The default implementation is well-crafted, sensei!

The empty vector initialization is appropriate. However, consider adding a capacity hint if you know the typical number of entrypoints to optimize allocations.

-            entrypoints: vec![],
+            entrypoints: Vec::with_capacity(10), // Adjust capacity based on typical usage
crates/dojo/world/src/local/artifact_to_local.rs (2)

234-252: Consider adding documentation for system identification criteria, sensei!

The implementation is elegant and handles nested ABI structures well. However, it would benefit from documentation explaining:

  • What qualifies as a system
  • Why external state mutability is the key criteria
  • Examples of typical system functions

Add documentation like this:

+/// Extracts system functions from ABI entries.
+/// 
+/// A system is any function that:
+/// - Has external state mutability
+/// - Is exposed in the contract's ABI
+/// 
+/// # Arguments
+/// * `abi` - Slice of ABI entries to process
+/// 
+/// # Returns
+/// Vector of system function names
 fn systems_from_abi(abi: &[AbiEntry]) -> Vec<String> {

306-351: Consider making the tests more maintainable, sensei!

While the tests provide good coverage, the hardcoded list of expected systems in test_load_world_from_directory might be fragile to maintain. Consider:

  1. Moving the expected systems list to a constant or test fixture
  2. Adding assertions that verify system properties rather than exact names
  3. Adding test cases for edge cases (empty ABI, no external functions)

Example approach:

#[test]
fn test_load_world_from_directory() {
    // ... existing setup ...
    
    // Verify essential properties instead of exact list
    assert!(!world.entrypoints.is_empty());
    assert!(world.entrypoints.contains(&"upgrade".to_string()));
    assert!(world.entrypoints.iter().all(|s| !s.is_empty()));
}
crates/dojo/world/src/diff/mod.rs (1)

40-41: Ohayo sensei! The new field looks good, but could use better documentation.

The field declaration is well-structured, but consider adding more descriptive documentation to explain what constitutes an entrypoint and its significance in the world status.

     /// The status of the world.
     pub status: WorldStatus,
-    /// The entrypoints of the world.
+    /// The entrypoints of the world, representing external functions exposed in the ABI
+    /// that can be called to interact with the world contract.
     pub entrypoints: Vec<String>,
examples/simple/manifest_dev.json (1)

Line range hint 109-233: Excellent addition of batch operation support!

The ABI has been enhanced with new struct definitions and functions that enable efficient batch operations:

  • emit_events for batch event emission
  • entities for batch entity retrieval
  • set_entities for batch entity updates
  • delete_entities for batch entity deletion

These additions will significantly improve performance for bulk operations.

Consider documenting the performance characteristics and recommended batch sizes for these operations in the technical documentation.

Also applies to: 444-604

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7bf9be3 and b2463b7.

⛔ Files ignored due to path filters (2)
  • spawn-and-move-db.tar.gz is excluded by !**/*.gz
  • types-test-db.tar.gz is excluded by !**/*.gz
📒 Files selected for processing (5)
  • crates/dojo/world/src/diff/manifest.rs (11 hunks)
  • crates/dojo/world/src/diff/mod.rs (3 hunks)
  • crates/dojo/world/src/local/artifact_to_local.rs (7 hunks)
  • crates/dojo/world/src/local/mod.rs (2 hunks)
  • examples/simple/manifest_dev.json (16 hunks)
🔇 Additional comments (13)
crates/dojo/world/src/local/mod.rs (1)

39-41: Ohayo! The entrypoints field addition looks solid, sensei!

The field type and documentation clearly express the purpose of storing transaction-targetable world entrypoints.

crates/dojo/world/src/diff/manifest.rs (4)

36-37: Ohayo! The entrypoints field addition looks good, sensei!

The addition of entrypoints to WorldContract and its initialization in Manifest::new aligns well with the PR objectives of exposing systems in the manifest.

Also applies to: 116-116


58-60: Clean and consistent selector field additions across resource types!

The addition of the selector field with UfeHex serialization is well-implemented across all resource types (Contract, Model, Event). This enhancement properly supports the manifest's resource identification capabilities.

Also applies to: 76-78, 92-94


Line range hint 162-173: Clean implementation of selector initialization across conversion functions!

The selector initialization is consistently implemented across all resource conversion functions, maintaining proper error handling and matching the manifest structure requirements.

Also applies to: 190-201, 217-228


162-162: Verify the dojo_selector() implementation.

The conversion functions consistently use resource.dojo_selector() for selector initialization. Let's verify its implementation to ensure correct selector generation.

Also applies to: 173-173, 190-190, 201-201, 217-217, 228-228

✅ Verification successful

Implementation of dojo_selector() is consistent and well-structured

The verification shows that dojo_selector() is properly implemented across all resource types:

  • Common resources use naming::compute_selector_from_names(&self.namespace, &self.name)
  • Namespace resources use naming::compute_bytearray_hash(&name) as a special case
  • Contract/Model/Event resources delegate to their common implementation
  • ResourceDiff correctly forwards to the local resource implementation

The selector initialization in the conversion functions is correctly using this implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for dojo_selector implementation
rg -A 5 "fn dojo_selector"

Length of output: 3585

crates/dojo/world/src/local/artifact_to_local.rs (2)

10-10: Ohayo! Import looks good, sensei!

The addition of StateMutability is well-placed and necessary for identifying external systems from ABI entries.


34-34: Implementation aligns well with PR objectives, sensei!

The changes effectively collect and store systems from both world and contract ABIs. The separation between world entrypoints and contract systems is clean and well-structured.

Let's verify the contract systems are properly collected:

Also applies to: 60-60, 66-66, 83-83, 168-168

✅ Verification successful

Contract systems are properly collected and handled, sensei!

The verification shows that systems are correctly extracted from both world and contract ABIs through the systems_from_abi function. The implementation:

  • Extracts systems from external functions in the ABI
  • Properly handles both world entrypoints and contract systems
  • Correctly processes contract resources with their respective namespaces

The code at line 34 initializing world_entrypoints is part of a well-structured flow where:

  1. World ABI systems are collected into world_entrypoints
  2. Contract systems are separately collected and handled with proper namespace association
  3. Both are integrated into the final WorldLocal structure
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that contract systems are properly collected from ABI
# Expected: Find instances where systems are extracted from contract ABIs

rg -A 3 "ResourceType::Contract.*systems.*clone" crates/dojo/world/src/

Length of output: 73


Script:

#!/bin/bash
# Let's try a broader search for contract systems handling
rg -A 5 "ResourceType::Contract" crates/dojo/world/src/

# Also search for systems collection in the artifact_to_local file
rg -A 5 "systems_from_abi" crates/dojo/world/src/local/artifact_to_local.rs

# Check the struct definition and implementation
rg -A 10 "impl WorldLocal" crates/dojo/world/src/local/

Length of output: 7399

crates/dojo/world/src/diff/mod.rs (2)

80-80: LGTM! Proper initialization from local world.

The entrypoints are correctly preserved from the local world during the NotDeployed status initialization.


117-117: Consider handling entrypoint differences between local and remote.

Currently, we always use local entrypoints even when the world is synced with remote. Consider if we should compare local and remote entrypoints to detect changes, similar to how we handle other resource differences.

Let's check if there are any remote entrypoint handling patterns in the codebase:

examples/simple/manifest_dev.json (4)

3-29: Ohayo sensei! The world section changes look good!

The world section has been properly updated with new class hash, address, and a comprehensive list of entrypoints that cover all essential world management functions.


Line range hint 1246-2111: Well-structured contract definitions with explicit system declarations!

The contracts are properly defined with:

  • Unique selectors for each contract
  • Explicit listing of available systems
  • Consistent inclusion of the upgrade system
  • Additional systems (system_1 through system_4) for ns-c1 and ns2-c1 contracts

This aligns perfectly with the PR objective of explicitly identifying systems in the manifest.


2117-2125: Please verify the empty model members.

Both models have empty members arrays. While this might be intentional, it's worth verifying if this is the expected state.

#!/bin/bash
# Description: Check if empty model members are expected
# Look for model definitions or references in the codebase

# Search for model definitions
echo "Searching for model definitions..."
rg -l "struct.*M\s*{" --type cairo

# Search for model member references
echo "Searching for model member references..."
rg -l "M\s*{\s*\w+\s*:" --type cairo

2131-2139: Please verify the empty event members.

Both events have empty members arrays. While this might be intentional, it's worth verifying if this is the expected state.

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.17%. Comparing base (7bf9be3) to head (b2463b7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2642      +/-   ##
==========================================
+ Coverage   57.07%   57.17%   +0.09%     
==========================================
  Files         399      399              
  Lines       49661    49731      +70     
==========================================
+ Hits        28346    28434      +88     
+ Misses      21315    21297      -18     

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

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