Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(katana): merge ServerOptions #3047

Closed
wants to merge 1 commit into from
Closed

Conversation

notV4l
Copy link
Collaborator

@notV4l notV4l commented Feb 18, 2025

closes #2968

Summary by CodeRabbit

  • New Features

    • Introduced a flexible configuration merging process for server settings, enabling partial updates from configuration files.
  • Refactor

    • Streamlined how configuration settings are integrated, improving robustness when applying updates to server options.

@notV4l notV4l requested a review from kariy February 18, 2025 10:54
Copy link

coderabbitai bot commented Feb 18, 2025

Walkthrough

Ohayo sensei! This PR revises the configuration merging process for the Katana CLI. In the NodeArgs struct, the with_config_file() method now calls a merge method on the server field instead of relying solely on a default check, allowing for partial updates from a config file. Additionally, a new merge method is added to the ServerOptions struct to conditionally update default values across multiple fields (such as http_addr, http_port, etc.). The logic for updating the metrics field remains unchanged.

Changes

File Path Change Summary
crates/katana/cli/src/args.rs Modified the with_config_file method in NodeArgs: replaced the conditional default check for the server field with a call to merge; metrics field check remains intact.
crates/katana/cli/src/options.rs Added a new merge method to ServerOptions to update config fields (e.g., http_addr, http_port, etc.) when their current values are default.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as "CLI (Caller)"
    participant NA as "NodeArgs"
    participant SO as "ServerOptions"
    participant CF as "ConfigFile"

    CLI->>NA: with_config_file(config)
    NA->>SO: merge(config.server)
    NA->>NA: update(metrics) if default
    SO-->>NA: Merged server options
    NA-->>CLI: Return updated NodeArgs
Loading

Possibly related PRs

  • fix: katana granular config for starknet #2677 – The changes in the main PR are related to the modifications of the with_config_file method in the NodeArgs struct, which also appears in the retrieved PR, indicating a direct connection in their implementation.
  • fix(katana-cli): ensure compilation without server feature #2896 – The changes in the main PR, specifically the modification of the with_config_file method in the NodeArgs struct, are related to the changes in the retrieved PR, which also involves the NodeArgs struct but focuses on conditional compilation for server-related features.
  • fix: cli args for torii and katana with serde default #2692 – The changes in the main PR, specifically the modification of the with_config_file method in the NodeArgs struct to utilize the merge method, are related to the addition of the merge method in the ServerOptions struct in the retrieved PR.

Suggested reviewers

  • glihm
  • kariy

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 (1)
crates/katana/cli/src/options.rs (1)

157-192: Ohayo sensei! The merge logic looks good, but let's optimize those clones!

The merge implementation correctly updates fields only when they have default values, maintaining the precedence of CLI arguments over config file values. However, we can optimize it by removing unnecessary clone() calls on primitive types.

Here's the optimized version:

 pub fn merge(&mut self, other: Option<&Self>){
     if let Some(other) = other {
         if self.http_addr == DEFAULT_RPC_ADDR {
-            self.http_addr = other.http_addr.clone();
+            self.http_addr = other.http_addr;
         }
         if self.http_port == DEFAULT_RPC_PORT {
-            self.http_port = other.http_port.clone();
+            self.http_port = other.http_port;
         }
         if self.http_cors_origins.len() == 0 {
             self.http_cors_origins = other.http_cors_origins.clone();
         }
         if self.http_modules.is_none() {
             self.http_modules = other.http_modules.clone();
         }
         if self.max_event_page_size == DEFAULT_RPC_MAX_EVENT_PAGE_SIZE {
-            self.max_event_page_size = other.max_event_page_size.clone();
+            self.max_event_page_size = other.max_event_page_size;
         }
         if self.max_proof_keys == DEFAULT_RPC_MAX_PROOF_KEYS {
-            self.max_proof_keys = other.max_proof_keys.clone();
+            self.max_proof_keys = other.max_proof_keys;
         }
         if self.max_connections.is_none() {
-            self.max_connections = other.max_connections.clone();
+            self.max_connections = other.max_connections;
         }
         if self.max_request_body_size.is_none() {
-            self.max_request_body_size = other.max_request_body_size.clone();
+            self.max_request_body_size = other.max_request_body_size;
         }
         if self.max_response_body_size.is_none() {
-            self.max_response_body_size = other.max_response_body_size.clone();
+            self.max_response_body_size = other.max_response_body_size;
         }
         if self.max_call_gas == DEFAULT_RPC_MAX_CALL_GAS {
-            self.max_call_gas = other.max_call_gas.clone();
+            self.max_call_gas = other.max_call_gas;
         }
     }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e5b93ac and 4343649.

📒 Files selected for processing (2)
  • crates/katana/cli/src/args.rs (1 hunks)
  • crates/katana/cli/src/options.rs (1 hunks)
🔇 Additional comments (1)
crates/katana/cli/src/args.rs (1)

389-389: LGTM! Clean and consistent with other merge calls.

The change simplifies the server options merging by using the new merge method, making it consistent with how other options are merged in this file.

@notV4l notV4l force-pushed the katana_server_options branch from 4343649 to 7fb3fcf Compare February 18, 2025 11:20
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 (1)
crates/katana/cli/src/options.rs (1)

157-192: Ohayo sensei! The merge implementation looks good with minor improvements possible.

The merge logic is well-implemented, preserving user-specified values and following a consistent pattern. Consider these minor refinements:

-            if self.http_cors_origins.len() == 0 {
+            if self.http_cors_origins.is_empty() {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4343649 and 7fb3fcf.

📒 Files selected for processing (2)
  • crates/katana/cli/src/args.rs (1 hunks)
  • crates/katana/cli/src/options.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/katana/cli/src/args.rs
🧰 Additional context used
🪛 GitHub Actions: ci
crates/katana/cli/src/options.rs

[error] 155-155: Rust formatting check failed. Please run 'rustfmt' to format the code.

Comment on lines 155 to +157
}

impl ServerOptions {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix formatting: Add newline after closing brace.

The pipeline indicates a formatting issue. Please run rustfmt or add a newline after the closing brace of the Default implementation.

    }
}
+
impl ServerOptions {
📝 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
}
impl ServerOptions {
}
}
impl ServerOptions {
🧰 Tools
🪛 GitHub Actions: ci

[error] 155-155: Rust formatting check failed. Please run 'rustfmt' to format the code.

@glihm
Copy link
Collaborator

glihm commented Feb 18, 2025

Will close since done in #3044. 👍

@glihm glihm closed this Feb 18, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[katana] http_cors_origins parameter is not ok with config file
2 participants