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(torii): erc options for max tasks & artifacts path #3061

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

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Feb 24, 2025

Summary by CodeRabbit

  • New Features

    • Introduced dedicated ERC options within the CLI to customize and optimize token indexing. Users can now adjust concurrent task limits and specify an artifact storage path, with improved default settings.
  • Refactor

    • Streamlined the configuration by replacing legacy indexing parameters with the new ERC-specific options, ensuring a more intuitive and focused setup experience.
    • Updated the handling of concurrent tasks and artifact paths to align with the new ERC structure.

Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

Ohayo, sensei! This PR refines the command-line interface for Torii by removing the artifacts_path field from ToriiArgs and introducing a new erc field. The ErcOptions structure is added to encapsulate ERC-related settings, including max_metadata_tasks and an optional artifacts_path, with appropriate default values. Updates in the configuration handling and the Runner module now reference the new ERC options for managing tasks and artifact paths.

Changes

File(s) Change Summary
crates/torii/cli/src/args.rs
crates/torii/cli/src/options.rs
Removed artifacts_path from ToriiArgs; added erc field to both ToriiArgs and ToriiArgsConfig. Introduced ErcOptions with fields for max_metadata_tasks and optional artifacts_path, along with its default implementation and constant.
crates/torii/runner/src/lib.rs Updated Runner to source configuration from erc fields—in particular, using erc.max_metadata_tasks and erc.artifacts_path instead of referencing the removed indexing configurations.
crates/torii/sqlite/src/executor/mod.rs Renamed semaphore to metadata_semaphore and updated the constructor to accept max_metadata_tasks. Adjusted references in the run method and RegisterNftToken query handling to use the new semaphore.

Possibly related PRs

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 ad9e489 and 4cb3764.

📒 Files selected for processing (3)
  • crates/torii/cli/src/options.rs (5 hunks)
  • crates/torii/runner/src/lib.rs (2 hunks)
  • crates/torii/sqlite/src/executor/mod.rs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/torii/runner/src/lib.rs
  • crates/torii/cli/src/options.rs
🔇 Additional comments (3)
crates/torii/sqlite/src/executor/mod.rs (3)

146-146: LGTM! Clear and descriptive field naming.

The renaming from semaphore to metadata_semaphore better reflects its purpose in managing concurrent metadata tasks.


237-243: LGTM! Constructor changes align with the field renaming.

The parameter renaming from max_concurrent_tasks to max_metadata_tasks and the corresponding semaphore initialization maintain consistency with the field renaming.


606-689: LGTM! Proper semaphore handling in the spawned task.

The semaphore usage is consistent with the field renaming, and the permit is properly acquired and dropped in the spawned task.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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: 0

🧹 Nitpick comments (4)
crates/torii/runner/src/lib.rs (1)

145-145: Ohayo sensei! Consider using ERC-specific default for max concurrent tasks.

The code is using DEFAULT_MAX_CONCURRENT_TASKS (100) for both indexing and ERC tasks. Since ERC token indexing might have different resource requirements, consider using the ERC-specific default DEFAULT_ERC_MAX_CONCURRENT_TASKS (10) defined in options.rs.

crates/torii/cli/src/options.rs (3)

355-356: Ohayo! Use ERC-specific default and improve help text.

Two suggestions for improvement:

  1. Use DEFAULT_ERC_MAX_CONCURRENT_TASKS instead of DEFAULT_MAX_CONCURRENT_TASKS for consistency.
  2. Add more descriptive help text about the impact of concurrent tasks on resource usage.
-    #[arg(long = "erc.max_concurrent_tasks", default_value_t = DEFAULT_MAX_CONCURRENT_TASKS)]
+    #[arg(
+        long = "erc.max_concurrent_tasks",
+        default_value_t = DEFAULT_ERC_MAX_CONCURRENT_TASKS,
+        help = "Maximum number of concurrent tasks for indexing ERC tokens. Higher values increase memory usage."
+    )]
     pub max_concurrent_tasks: usize,

359-360: Add help text for artifacts path.

Consider adding descriptive help text for the artifacts path option.

-    #[arg(long)]
+    #[arg(
+        long = "erc.artifacts_path",
+        help = "Directory path to store ERC token metadata and media files. Defaults to a temporary directory."
+    )]
     pub artifacts_path: Option<Utf8PathBuf>,

364-366: Use ERC-specific default in Default implementation.

For consistency, use DEFAULT_ERC_MAX_CONCURRENT_TASKS in the Default implementation.

     fn default() -> Self {
-        Self { max_concurrent_tasks: DEFAULT_MAX_CONCURRENT_TASKS, artifacts_path: None }
+        Self { max_concurrent_tasks: DEFAULT_ERC_MAX_CONCURRENT_TASKS, artifacts_path: None }
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b93308 and 4a852c1.

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

51-52: Ohayo! Nice addition of ERC options!

The flattening of ERC options into the command-line arguments is well-implemented and follows Rust's command-line argument parsing best practices.


106-108: LGTM! Clean configuration merging logic.

The configuration merging logic for ERC options follows the same pattern as other options, maintaining consistency.


138-138: LGTM! Consistent configuration structure.

The addition of ERC options to the configuration structure is clean and consistent with other option types.


169-169: LGTM! Clean serialization logic.

The serialization logic for ERC options follows the same pattern as other options, maintaining consistency.

crates/torii/runner/src/lib.rs (1)

209-213: LGTM! Clean artifacts path handling.

The artifacts path handling with fallback to a temporary directory is well-implemented.

crates/torii/cli/src/options.rs (1)

23-23: LGTM! Good default value for ERC tasks.

The default value of 10 for ERC concurrent tasks is reasonable and helps prevent resource exhaustion.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a852c1 and ad9e489.

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

5-5: Ohayo! The new imports and constants look good, sensei!

The DEFAULT_ERC_MAX_CONCURRENT_TASKS constant with a value of 10 is a reasonable default for managing ERC token metadata indexing tasks.

Also applies to: 23-24


123-124: Documentation improvement looks good!

The updated help text for max_concurrent_tasks in IndexingOptions is now more precise and clearer about its purpose.

Also applies to: 127-127


463-465: Helper function looks good!

The default_erc_max_concurrent_tasks function correctly returns the ERC-specific default value.

Comment on lines 351 to 373
#[derive(Debug, clap::Args, Clone, Serialize, Deserialize, PartialEq)]
#[command(next_help_heading = "ERC options")]
pub struct ErcOptions {
/// The maximum number of concurrent tasks to use for indexing ERC721 and ERC1155 token
/// metadata.
#[arg(
long = "erc.max_concurrent_tasks",
default_value_t = DEFAULT_ERC_MAX_CONCURRENT_TASKS,
help = "The maximum number of concurrent tasks to use for indexing ERC721 and ERC1155 token metadata."
)]
#[serde(default = "default_erc_max_concurrent_tasks")]
pub max_concurrent_tasks: usize,

/// Path to a directory to store ERC artifacts
#[arg(long)]
pub artifacts_path: Option<Utf8PathBuf>,
}

impl Default for ErcOptions {
fn default() -> Self {
Self { max_concurrent_tasks: DEFAULT_MAX_CONCURRENT_TASKS, artifacts_path: None }
}
}
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! The new ErcOptions structure looks well-designed, sensei!

The structure provides a clean separation of concerns for ERC-specific configuration. However, there's a small issue in the default implementation.

The default implementation uses DEFAULT_MAX_CONCURRENT_TASKS (100) instead of DEFAULT_ERC_MAX_CONCURRENT_TASKS (10). Apply this diff to fix:

-        Self { max_concurrent_tasks: DEFAULT_MAX_CONCURRENT_TASKS, artifacts_path: None }
+        Self { max_concurrent_tasks: DEFAULT_ERC_MAX_CONCURRENT_TASKS, artifacts_path: None }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[derive(Debug, clap::Args, Clone, Serialize, Deserialize, PartialEq)]
#[command(next_help_heading = "ERC options")]
pub struct ErcOptions {
/// The maximum number of concurrent tasks to use for indexing ERC721 and ERC1155 token
/// metadata.
#[arg(
long = "erc.max_concurrent_tasks",
default_value_t = DEFAULT_ERC_MAX_CONCURRENT_TASKS,
help = "The maximum number of concurrent tasks to use for indexing ERC721 and ERC1155 token metadata."
)]
#[serde(default = "default_erc_max_concurrent_tasks")]
pub max_concurrent_tasks: usize,
/// Path to a directory to store ERC artifacts
#[arg(long)]
pub artifacts_path: Option<Utf8PathBuf>,
}
impl Default for ErcOptions {
fn default() -> Self {
Self { max_concurrent_tasks: DEFAULT_MAX_CONCURRENT_TASKS, artifacts_path: None }
}
}
#[derive(Debug, clap::Args, Clone, Serialize, Deserialize, PartialEq)]
#[command(next_help_heading = "ERC options")]
pub struct ErcOptions {
/// The maximum number of concurrent tasks to use for indexing ERC721 and ERC1155 token
/// metadata.
#[arg(
long = "erc.max_concurrent_tasks",
default_value_t = DEFAULT_ERC_MAX_CONCURRENT_TASKS,
help = "The maximum number of concurrent tasks to use for indexing ERC721 and ERC1155 token metadata."
)]
#[serde(default = "default_erc_max_concurrent_tasks")]
pub max_concurrent_tasks: usize,
/// Path to a directory to store ERC artifacts
#[arg(long)]
pub artifacts_path: Option<Utf8PathBuf>,
}
impl Default for ErcOptions {
fn default() -> Self {
Self { max_concurrent_tasks: DEFAULT_ERC_MAX_CONCURRENT_TASKS, artifacts_path: None }
}
}

Copy link

codecov bot commented Feb 24, 2025

Codecov Report

Attention: Patch coverage is 63.15789% with 7 lines in your changes missing coverage. Please review.

Project coverage is 57.50%. Comparing base (9b93308) to head (4cb3764).

Files with missing lines Patch % Lines
crates/torii/cli/src/options.rs 50.00% 4 Missing ⚠️
crates/torii/runner/src/lib.rs 0.00% 2 Missing ⚠️
crates/torii/cli/src/args.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3061      +/-   ##
==========================================
+ Coverage   57.49%   57.50%   +0.01%     
==========================================
  Files         439      439              
  Lines       59820    59833      +13     
==========================================
+ Hits        34392    34406      +14     
+ Misses      25428    25427       -1     

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

@Larkooo Larkooo enabled auto-merge (squash) February 24, 2025 13:02
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