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-client): cleanup & remove rpc #3019

Merged
merged 2 commits into from
Feb 14, 2025

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Feb 13, 2025

Summary by CodeRabbit

  • Refactor
    • Streamlined client initialization for improved efficiency.
    • Updated metadata retrieval to use asynchronous, real-time data fetching that ensures users receive the latest information.
    • Removed legacy methods to simplify system interactions and enhance overall performance.
    • Eliminated unnecessary fields to reduce complexity in the client structure.

@Larkooo Larkooo changed the title refactor(torii-client): remove rpc refactor(torii-client): cleanup & remove rpc Feb 13, 2025
Copy link

coderabbitai bot commented Feb 13, 2025

Ohayo sensei!

Walkthrough

This pull request updates the client module in the Torii crate. It removes the world_reader dependency and refactors metadata handling by converting it from a state-based field guarded by a lock into an asynchronous method that fetches metadata via the gRPC client. The new method is streamlined by removing the rpc_url parameter and directly initializing the gRPC client, shifting from a JSON-RPC to a gRPC-based approach.

Changes

File(s) Change Summary
crates/torii/.../client/mod.rs - Removed the world_reader field from Client
- Updated metadata handling: changed from an Arc<RwLock<WorldMetadata>> field to an async metadata() method returning Result<WorldMetadata, Error>
- Modified the new method by removing the rpc_url parameter and streamlining gRPC client initialization
- Updated metadata method to acquire a write lock and asynchronously retrieve data from the gRPC client

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant G as gRPC Client
    C->>C: Call metadata() (acquire write lock)
    C->>G: Request updated metadata asynchronously
    G-->>C: Return WorldMetadata or Error
Loading

Possibly related PRs

Suggested reviewers

  • glihm

🪧 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. (Beta)
  • @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: 1

🧹 Nitpick comments (2)
crates/torii/client/src/client/mod.rs (2)

8-8: Ohayo sensei! Nice switch to tokio::sync::RwLock.
Switching from alternative locks to tokio::sync::RwLock is a valid move for asynchronous contexts. Just be mindful of whether you really need distinct read/write phases or if a simpler Mutex suffices.


69-72: Ohayo sensei! Consider using a read lock for metadata fetching.
Right now, you acquire a write lock to call metadata(). If metadata() doesn’t mutate the WorldClient, you might use a read lock, allowing multiple concurrent metadata reads. Otherwise, this is a clean migration away from storing cached metadata.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ac52ea6 and aebeca0.

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

24-24: Ohayo sensei! Good call on unifying your error handling.
Bringing in the local Error type keeps everything consistent and easier to maintain.


42-46: Ohayo sensei! Verify that the torii_url is a valid gRPC endpoint.
You’re now constructing the WorldClient with torii_url and removing JSON-RPC. This is great for streamlining, but consider adding validation or logging if an invalid URL is passed.

/// The grpc client.
inner: AsyncRwLock<torii_grpc::client::WorldClient>,
inner: RwLock<torii_grpc::client::WorldClient>,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ohayo sensei! Ensure references to the removed world_reader field are cleaned up.
Excellent approach to storing WorldClient in a RwLock. However, referencing self.world_reader.address around line 216 looks like a leftover. This will cause a compile error now that world_reader is gone.

As a follow-up fix outside the changed lines, consider updating the code to reference the new client’s address field (assuming one exists). For instance:

- subscribe_indexer(contract_address.unwrap_or(self.world_reader.address))
+ subscribe_indexer(contract_address.unwrap_or(grpc_client.world_address))

Committable suggestion skipped: line range outside the PR's diff.

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/client/src/client/mod.rs (1)

62-65: Ohayo sensei! Consider using read lock for metadata fetch!

While the change to fetch metadata directly is good, using a write lock (write().await) might be unnecessary since we're only reading data. Consider using read().await instead for better concurrency.

-        let mut grpc_client = self.inner.write().await;
+        let grpc_client = self.inner.read().await;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aebeca0 and 0eb1737.

📒 Files selected for processing (1)
  • crates/torii/client/src/client/mod.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: docs
  • GitHub Check: build
  • GitHub Check: ensure-wasm
🔇 Additional comments (4)
crates/torii/client/src/client/mod.rs (4)

8-8: Ohayo sensei! LGTM on the import simplification!

The direct import of RwLock improves code readability by avoiding unnecessary type aliases.


30-30: Ohayo sensei! Clean struct refactoring!

The field type change aligns with the import simplification, and the removal of world_reader successfully achieves the PR's objective of removing RPC.


37-41: Ohayo sensei! Excellent initialization simplification!

The removal of rpc_url parameter and direct gRPC client initialization aligns perfectly with the PR's objective of removing RPC dependencies.


208-208: Ohayo sensei! Good fallback handling!

The change to use unwrap_or_default() is a safe and clean way to handle the default case after removing world_reader.

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

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

Project coverage is 56.25%. Comparing base (ac52ea6) to head (0eb1737).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/client/src/client/mod.rs 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3019      +/-   ##
==========================================
+ Coverage   56.24%   56.25%   +0.01%     
==========================================
  Files         436      436              
  Lines       58829    58813      -16     
==========================================
- Hits        33087    33086       -1     
+ Misses      25742    25727      -15     

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

@Larkooo Larkooo enabled auto-merge (squash) February 14, 2025 04:06
@Larkooo Larkooo merged commit 0a186fa into dojoengine:main Feb 14, 2025
14 of 15 checks passed
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