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

fix: katana granular config for starknet #2677

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Nov 11, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced configuration merging capabilities for StarknetOptions, EnvironmentOptions, and DevOptions, allowing for more flexible integration of settings.
    • Added invoke_max_steps field for granular control over invocation limits in starknet.environment.
  • Bug Fixes

    • Improved handling of starknet configuration merging to ensure consistent behavior regardless of initial state.
  • Documentation

    • Updated test cases to reflect changes in configuration options and expected values.

Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

Ohayo, sensei! This pull request introduces modifications to the NodeArgs struct and the StarknetOptions and EnvironmentOptions structs, enhancing their configuration capabilities. Key changes include the alteration of the with_config_file method to always merge the starknet configuration and the addition of the invoke_max_steps field in the starknet.environment. New merging methods for StarknetOptions, EnvironmentOptions, and DevOptions allow for more flexible configuration management. Test cases have been updated to reflect these changes.

Changes

File Path Change Summary
bin/katana/src/cli/node.rs Updated NodeArgs struct: modified with_config_file method to always merge starknet config; added invoke_max_steps field in starknet.environment.
bin/katana/src/cli/options.rs Added merge method to StarknetOptions, EnvironmentOptions, and DevOptions for enhanced configuration merging.

Possibly related PRs

Suggested reviewers

  • Larkooo
  • steebchen

🪧 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 and nitpick comments (1)
bin/katana/src/cli/options.rs (1)

111-121: Ohayo sensei! The merge implementation looks good, but could use some documentation.

The merge logic is well-implemented, correctly handling both the environment options and the optional genesis field. However, adding documentation would help clarify the merging behavior.

Consider adding documentation like this:

 impl StarknetOptions {
+    /// Merges another StarknetOptions into this one.
+    /// 
+    /// # Arguments
+    /// * `other` - The StarknetOptions to merge from
+    ///
+    /// # Behavior
+    /// - Environment options are always merged
+    /// - Genesis is only set if the current genesis is None
     pub fn merge(&mut self, other: Option<&Self>) {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 95afbe0 and 9da3dd3.

📒 Files selected for processing (2)
  • bin/katana/src/cli/node.rs (6 hunks)
  • bin/katana/src/cli/options.rs (2 hunks)
🔇 Additional comments (4)
bin/katana/src/cli/options.rs (1)

158-174: Ohayo sensei! The merge logic needs documentation and verification.

The implementation looks solid but has two areas for improvement:

  1. Documentation to explain the merging behavior
  2. Verification of the default value preservation logic

Add documentation to clarify the merging behavior:

 impl EnvironmentOptions {
+    /// Merges another EnvironmentOptions into this one.
+    /// 
+    /// # Arguments
+    /// * `other` - The EnvironmentOptions to merge from
+    ///
+    /// # Behavior
+    /// - chain_id is only set if the current chain_id is None
+    /// - validate_max_steps is only updated if at default value
+    /// - invoke_max_steps is only updated if at default value
     pub fn merge(&mut self, other: Option<&Self>) {

Let's verify the default value behavior:

✅ Verification successful

Ohayo sensei! The merge behavior is correctly implemented and consistent with the codebase

The verification confirms that:

  1. The default values are properly imported from katana_node::config::execution
  2. These constants are consistently used across the codebase:
    • As default values in CLI args via #[arg(default_value_t)]
    • As default values in the struct's implementation
    • In the merge logic comparison
  3. The merge behavior correctly preserves non-default values while allowing overrides of default values

The suggested documentation addition would still be valuable for clarity, but the implementation is solid and behaves as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the default values in the code match the imported constants

# Search for the DEFAULT constants and their usage
rg "DEFAULT_(VALIDATION|INVOCATION)_MAX_STEPS" -A 2

Length of output: 3159

bin/katana/src/cli/node.rs (3)

363-363: Ohayo sensei! The config merging looks good!

The change to always merge the starknet config using the merge method is a good improvement, as it allows for more flexible configuration management.


508-509: LGTM! New imports are properly organized.

The addition of FromStr and Felt imports supports the new chain ID configuration functionality.

Also applies to: 519-519


695-696: Test coverage looks comprehensive, sensei!

The test cases properly verify:

  1. The new invoke_max_steps configuration
  2. Chain ID configuration and parsing
  3. CLI arguments taking precedence over config file values

However, it would be good to add a negative test case for invalid chain ID values.

Let's verify if there are any other chain ID related tests:

Also applies to: 713-714, 721-721, 736-736

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

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

Project coverage is 57.57%. Comparing base (95afbe0) to head (46e11b3).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
bin/katana/src/cli/options.rs 80.48% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2677      +/-   ##
==========================================
- Coverage   57.59%   57.57%   -0.02%     
==========================================
  Files         404      404              
  Lines       51101    51139      +38     
==========================================
+ Hits        29431    29444      +13     
- Misses      21670    21695      +25     

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

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)
bin/katana/src/cli/options.rs (2)

111-121: Ohayo! The merge implementation looks good, sensei!

The merge logic correctly handles both the environment options and genesis field. Consider adding documentation to explain the merge behavior, especially regarding the precedence rules when merging configurations.

Add documentation like this:

 impl StarknetOptions {
+    /// Merges another StarknetOptions into this one.
+    /// The current values take precedence over the other values.
+    /// The environment options are merged recursively.
+    /// The genesis is only set if the current value is None.
     pub fn merge(&mut self, other: Option<&Self>) {

225-249: Excellent implementation of development options merging, sensei!

The merge logic correctly handles all development-related settings. The use of default values as triggers for updates is consistent with the pattern used in other merge implementations.

Consider extracting the default value comparisons into a helper trait to reduce code duplication across merge implementations. Here's a suggestion:

trait ConfigMerge {
    fn should_update(&self, default: Self) -> bool;
}

impl ConfigMerge for bool {
    fn should_update(&self, default: bool) -> bool {
        *self == default
    }
}

impl ConfigMerge for u16 {
    fn should_update(&self, default: u16) -> bool {
        *self == default
    }
}

// Then in DevOptions:
if self.total_accounts.should_update(DEFAULT_DEV_ACCOUNTS) {
    self.total_accounts = other.total_accounts;
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9da3dd3 and 46e11b3.

📒 Files selected for processing (2)
  • bin/katana/src/cli/node.rs (6 hunks)
  • bin/katana/src/cli/options.rs (3 hunks)
🔇 Additional comments (5)
bin/katana/src/cli/options.rs (1)

158-174: Clean implementation of environment options merging, sensei!

The merge logic correctly handles all fields and uses default values as triggers for updates. This ensures that CLI-provided values take precedence over configuration file values.

Let's verify that the default constants are correctly imported and used:

✅ Verification successful

Ohayo! The default constants are properly imported and used, sensei!

The verification confirms that:

  • The constants are correctly defined in katana_node::config::execution
  • They are properly imported in bin/katana/src/cli/options.rs
  • The merge implementation correctly uses these constants for comparison
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the default constants usage
rg "DEFAULT_(VALIDATION|INVOCATION)_MAX_STEPS" --type rust

Length of output: 1620

bin/katana/src/cli/node.rs (4)

503-504: LGTM! Clean import organization.

The new imports are properly organized and grouped with related dependencies.

Also applies to: 514-514


708-709: LGTM! Proper chain ID configuration support.

The implementation correctly handles both named and hex chain IDs, with appropriate test coverage.

Also applies to: 731-731


690-691: LGTM! Well-tested invoke max steps configuration.

The new invoke_max_steps configuration is properly implemented and tested, maintaining backward compatibility with default values.

Also applies to: 716-716


363-364: LGTM! Enhanced config merging logic.

The new implementation provides more consistent behavior by always merging configurations using dedicated merge methods.

Let's verify the merge behavior:

@glihm glihm merged commit 82de373 into dojoengine:main Nov 11, 2024
12 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.

1 participant