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): read only torii #2795

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Dec 11, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new option to enable or disable indexing within the application settings.
    • Enhanced configurability of indexing options through updated fields and default values.
  • Bug Fixes

    • Improved error handling to ensure graceful application exit if required parameters are not specified.

Copy link

coderabbitai bot commented Dec 11, 2024

Walkthrough

Ohayo! This pull request introduces significant changes to the main function in bin/torii/src/main.rs, focusing on the initialization of the Engine and the world variable. The world is now created before the Engine, which is conditionally instantiated based on the args.indexing.enabled flag. Additionally, a new boolean field enabled is added to the IndexingOptions struct in crates/torii/cli/src/options.rs, enabling better control over indexing options. The modifications enhance the application’s configurability and control flow.

Changes

File Change Summary
bin/torii/src/main.rs Modified main function to initialize world before Engine. Wrapped Engine in Option for conditional instantiation. Updated handling of engine_handle to account for None. Retained error handling for world_address.
crates/torii/cli/src/options.rs Added new boolean field enabled to IndexingOptions struct, initialized to true. Modified merge method to conditionally update enabled. Added comments for clarity.

Possibly related PRs

  • feat(torii-core): bitflags for indexing #2450: The changes in this PR also modify the main function in bin/torii/src/main.rs and introduce new command-line arguments related to indexing, which directly connects to the handling of the Engine and the world variable in the main PR.

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. (Experiment)
  • @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 (2)
crates/torii/cli/src/options.rs (1)

93-95: Ohayo! Consider enhancing the help text for better clarity, sensei.

The help text could be more descriptive about what happens when indexing is disabled. Consider updating it to explain that this makes torii operate in read-only mode.

-    #[arg(long, default_value_t = true, help = "If indexing should be enabled.")]
+    #[arg(long, default_value_t = true, help = "If indexing should be enabled. When disabled, torii operates in read-only mode without processing new events or blocks.")]
bin/torii/src/main.rs (1)

253-258: Clean implementation of the engine handle spawn!

The error handling is appropriate, but consider adding a debug log when indexing is disabled for better observability.

 let engine_handle = tokio::spawn(async move {
     if let Some(engine) = &mut engine {
         return engine.start().await;
     }
+    tracing::debug!(target: LOG_TARGET, "Engine not started as indexing is disabled");
     Ok(())
 });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bcd581e and aa3755a.

📒 Files selected for processing (2)
  • bin/torii/src/main.rs (2 hunks)
  • crates/torii/cli/src/options.rs (3 hunks)
🔇 Additional comments (3)
crates/torii/cli/src/options.rs (2)

169-169: LGTM! Default implementation is correct.

The default value of true maintains backward compatibility.


185-187: Verify the merge logic intention for the enabled field.

The merge logic for enabled differs from other fields. While other fields check for default values, enabled only updates if it's currently true. This suggests that once disabled, it cannot be re-enabled through merging. Is this the intended behavior?

✅ Verification successful

The previous search was too specific. Let's broaden our search to understand the context better and verify the merge behavior intention.


Let's look for the complete merge implementation to understand the pattern for other fields.


The merge logic for enabled field is intentionally designed to be one-way disabling

Ohayo sensei! After analyzing the codebase, I can confirm that the merge behavior for enabled is intentionally different from other fields. The IndexingOptions struct shows that:

  1. enabled defaults to true in the Default implementation
  2. The merge logic only updates when self.enabled is true, effectively making it a one-way switch that can only be disabled through merging

This is a valid pattern when you want to ensure that once indexing is disabled (e.g., through a config file or command line), it cannot be re-enabled through subsequent merge operations. This provides a reliable way to disable indexing that persists across configuration merges.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if this behavior is documented or discussed elsewhere
rg -A 5 "indexing.*enabled" --type md

Length of output: 39


Script:

#!/bin/bash
# Let's check the struct definition and other usages of enabled field
ast-grep --pattern 'struct $_ {
  $$$
  enabled: $_,
  $$$
}'

# Also check for any comments or documentation around the enabled field
rg -B 2 -A 2 "enabled: bool"

# Look for merge implementation tests
rg -A 10 "fn test.*merge"

Length of output: 844


Script:

#!/bin/bash
# Let's check the implementation of merge for this struct
ast-grep --pattern 'impl $_ {
  $$$
  fn merge($$$) {
    $$$
  }
  $$$
}'

# Let's also check for any default implementation or trait implementations
rg -B 5 -A 15 "impl.*for.*Options"

Length of output: 10427

bin/torii/src/main.rs (1)

149-174: Ohayo! Clean implementation of conditional Engine initialization, sensei!

The separation of world initialization from Engine and the use of Option for conditional Engine creation is well-structured. This allows other services to use the world reader while respecting the indexing configuration.

event_processor_config: EventProcessorConfig {
historical_events: args.events.historical.into_iter().collect(),
namespaces: args.indexing.namespaces.into_iter().collect(),
// Get world address
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Get world address

Comment on lines +93 to +95
/// If indexing should be enabled
#[arg(long, default_value_t = true, help = "If indexing should be enabled.")]
pub enabled: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would we want this to be disabled? For replicates syncing from a single indexing Torii?

Comment on lines +93 to +95
/// If indexing should be enabled
#[arg(long, default_value_t = true, help = "If indexing should be enabled.")]
pub enabled: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// If indexing should be enabled
#[arg(long, default_value_t = true, help = "If indexing should be enabled.")]
pub enabled: bool,
/// If indexing should be enabled
#[arg(long, default_value_t = true, help = "If indexing should be enabled.")]
#[serde(default)]
pub enabled: bool,

Add serde default to ensure it's not required to be given in configuration files.

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