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): cli args & rpc options #3094

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

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Mar 11, 2025

Summary by CodeRabbit

  • Style
    • Made minor formatting improvements for enhanced code clarity and maintainability. These adjustments have no impact on functionality or user experience.
    • Updated argument annotations in RpcOptions and SqlOptions for improved clarity and consistency in naming conventions.
  • New Features
    • Restructured argument configuration for improved organization, enhancing the way properties are accessed within the application.

Copy link

coderabbitai bot commented Mar 11, 2025

Ohayo, sensei!

Walkthrough

This pull request introduces significant changes to the ToriiArgs and RpcOptions structures within the args.rs and options.rs files, respectively. The rpc field in ToriiArgs has been updated from a Url type to a RpcOptions type, leading to the removal of previous URL handling logic. Additionally, the long attributes in RpcOptions and SqlOptions have been standardized to enhance clarity. The Runner implementation has also been updated to reflect the new structure of the argument configuration.

Changes

File(s) Change Summary
crates/torii/cli/src/args.rs Updated ToriiArgs struct to change rpc from Url to RpcOptions, removed old URL handling logic, and modified ToriiArgsConfig accordingly.
crates/torii/cli/src/options.rs Updated long attributes in RpcOptions and SqlOptions structs for improved clarity and consistency.
crates/torii/runner/src/lib.rs Modified property access in Runner to reflect new structure of args, accessing rpc and sql properties more specifically.

Possibly related PRs

Suggested reviewers

  • Sensei glihm
  • Sensei kariy

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between d6a0334 and 2faaa9d.

📒 Files selected for processing (2)
  • crates/torii/cli/src/args.rs (6 hunks)
  • crates/torii/runner/src/lib.rs (3 hunks)
🔇 Additional comments (9)
crates/torii/runner/src/lib.rs (4)

98-98: Structure reorganization looks sharp!

Ohayo! The refactoring to access db_dir through self.args.sql.db_dir instead of directly from self.args provides much better organization by grouping SQL-related options together.


137-137: Clean URL access through the new RpcOptions structure

Nice refactoring, sensei! Accessing the URL through self.args.rpc.url instead of directly from self.args.rpc aligns perfectly with the RpcOptions structure changes.


195-195: Proper relocation of events_chunk_size configuration

Well-thought reorganization! Moving events_chunk_size from the indexing namespace to the rpc namespace makes more logical sense since it's primarily related to RPC operations.


199-199: Logical placement of strict_model_reader parameter

Ohayo! The relocation of strict_model_reader to self.args.rpc.strict_model_reader improves code organization by placing this configuration with its related RPC settings.

crates/torii/cli/src/args.rs (5)

40-42: Excellent structure refinement with flattened RpcOptions

Ohayo, sensei! This refactoring from a simple Url type to a flattened RpcOptions type provides much better organization of related configurations. The #[command(flatten)] attribute ensures a clean CLI interface while maintaining a logical structure in the code.


93-95: Updated config file handling for new RpcOptions type

Nice adjustment to the config file handling logic! Comparing against RpcOptions::default() instead of a URL maintains the same behavior while working with the new structure.


125-125: Consistent type update in ToriiArgsConfig

Looking good, sensei! The change from Option<Url> to Option<RpcOptions> in the config struct maintains consistency with the changes to the main args structure.


155-155: Updated default comparison for TryFrom implementation

Ohayo! The default check update in the TryFrom implementation ensures the config conversion process continues to work correctly with the new structure.


227-228: Properly adjusted test assertions

Well done on updating all the test assertions to reflect the new structure! The tests now correctly validate that the configuration is loaded and passed through both CLI arguments and config files.

Also applies to: 292-293, 296-297


🪧 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 comments (1)
crates/torii/cli/src/args.rs (1)

175-326: 💡 Verification agent

🧩 Analysis chain

Tests might need updating for new RPC options structure

Ohayo, sensei! I noticed that the test cases still contain direct assertions against rpc as a URL (like line 228). These tests might need to be updated to work with the new RpcOptions structure instead.


🏁 Script executed:

#!/bin/bash
# Check if the tests in args.rs still compile after the changes
cd crates/torii/cli
cargo test --lib args::test::test_cli_precedence -- --nocapture || echo "Test might need updating to match the new RpcOptions structure"

Length of output: 318


Ohayo, sensei! Please update the tests for the new RPC options structure.

It appears that in crates/torii/cli/src/args.rs (particularly in the test_cli_precedence test), the assertions are still directly comparing the rpc field as a URL. Since the latest changes introduced the new RpcOptions structure, these tests need to be updated accordingly. For example:

  • Instead of asserting with Url::parse("http://0.0.0.0:6060"), the test should now verify the corresponding value within the new RpcOptions format.

Let's update the tests so that they reflect the structure and behavior of RpcOptions.

🧹 Nitpick comments (1)
crates/torii/cli/src/options.rs (1)

132-133: Consider formatting the default implementation for better readability

Ohayo, sensei! The current single-line implementation of Default for RpcOptions is a bit cramped. For consistency with other Default implementations in this file (like RelayOptions, IndexingOptions, etc.), consider using a multi-line format:

-    fn default() -> Self {
-        Self { strict_model_reader: false, events_chunk_size: DEFAULT_EVENTS_CHUNK_SIZE, url: Url::parse(DEFAULT_RPC_URL).unwrap() }
+    fn default() -> Self {
+        Self {
+            strict_model_reader: false,
+            events_chunk_size: DEFAULT_EVENTS_CHUNK_SIZE,
+            url: Url::parse(DEFAULT_RPC_URL).unwrap(),
+        }
+    }

This makes the code more readable and consistent with the rest of the codebase.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ac8712c and 0d8f67b.

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

41-44: LGTM: Good refactoring of RPC options

Ohayo! The extraction of RPC-related options into a dedicated struct looks clean and maintainable, sensei. This change improves code organization by grouping related configuration options together.


95-97: LGTM: Consistent handling of RPC options in config file

The implementation correctly handles merging RPC options from the config file. Good job, sensei!


127-127: LGTM: Config structure updated properly

The ToriiArgsConfig struct has been correctly updated to use the new RpcOptions type.


157-157: LGTM: Consistent implementation in TryFrom

The conversion logic properly handles the new RPC options structure.

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 (3)
crates/torii/cli/src/options.rs (3)

109-128: Ohayo sensei, consider improving the help text for strict_model_reader.
Although the field is self-explanatory, you might want to give a direct usage example for clarity.

For example:

- help = "Whether or not to read models from the block number they were registered in."
+ help = "If true, models start reading at their registration block. If false, models are read from the latest block."

130-134: Ohayo sensei, handle the parse error gracefully.
Currently, calling .unwrap() on Url::parse(DEFAULT_RPC_URL) risks a panic if the constant ever changes or is malformed.

- url: Url::parse(DEFAULT_RPC_URL).unwrap()
+ url: Url::parse(DEFAULT_RPC_URL).expect("Invalid default RPC URL")

417-426: Ohayo sensei, the naming might be confusing for db_dir.
The doc suggests a file path, but the field name implies a directory. Consider renaming if it genuinely references a file.

- pub db_dir: Option<PathBuf>,
+ pub db_file: Option<PathBuf>,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d8f67b and d6a0334.

📒 Files selected for processing (3)
  • crates/torii/cli/src/options.rs (4 hunks)
  • crates/torii/cli/src/options.rs (1 hunks)
  • crates/torii/cli/src/options.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/torii/cli/src/options.rs
  • crates/torii/cli/src/options.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: clippy
  • GitHub Check: ensure-wasm
  • GitHub Check: docs
  • GitHub Check: build
🔇 Additional comments (5)
crates/torii/cli/src/options.rs (5)

2-2: Ohayo sensei, thanks for adding PathBuf!
No issues found with this addition.


7-7: Ohayo sensei, nice import of parse_url.
This will come in handy for handling RPC endpoints.


12-12: Ohayo sensei, good call adding the url crate.
This aligns well with robust URL parsing needs.


25-25: Ohayo sensei, default RPC URL looks fine.
Specifying the default at http://0.0.0.0:5050 is consistent with local development usage.


136-138: Ohayo sensei, all is well for this reconfirmed IndexingOptions.
No conflicts spotted after removing strict_model_reader from 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