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(katana): chain spec file management tools #2945

Merged
merged 4 commits into from
Jan 23, 2025

Conversation

kariy
Copy link
Member

@kariy kariy commented Jan 23, 2025

Summary by CodeRabbit

Here are the release notes for this pull request:

  • New Features

    • Introduced a new katana-chain-spec crate to manage chain configuration and specification
    • Added support for flexible settlement layer configuration
    • Enhanced chain initialization with more robust configuration options
  • Improvements

    • Streamlined gas oracle implementation
    • Updated protocol version handling
    • Improved error handling for genesis and contract class configurations
  • Dependencies

    • Added katana-chain-spec as a workspace dependency across multiple crates
    • Removed some legacy dependencies like dirs and toml
  • Breaking Changes

    • Refactored chain specification and version management
    • Modified gas oracle and settlement layer handling
    • Updated import paths for chain-related modules

@kariy kariy changed the base branch from main to katana/chainspec January 23, 2025 17:23
Copy link

coderabbitai bot commented Jan 23, 2025

Pull Request Analysis 🚀

Ohayo, sensei! Let's dive into the details of this comprehensive pull request that introduces significant changes to the Katana project's architecture and dependencies.

Walkthrough

This pull request introduces a new crate called katana-chain-spec, which centralizes chain specification management across the Katana project. The changes involve restructuring how chain configurations are handled, introducing a more modular approach to defining chain parameters, settlement layers, and protocol versions. The modifications span multiple crates, updating imports, dependencies, and refactoring how chain specifications are processed and utilized.

Changes

File Change Summary
Cargo.toml Added katana-chain-spec as a new workspace member and dependency
bin/katana/Cargo.toml Added katana-chain-spec and lazy_static dependencies; removed dirs, serde, and toml
crates/katana/chain-spec/ New crate introduced with comprehensive chain specification functionality
Multiple source files Updated imports from katana_primitives::chain_spec to katana_chain_spec
Core implementation files Refactored gas oracle, node configuration, and settlement layer handling

Sequence Diagram

sequenceDiagram
    participant CLI as Katana CLI
    participant ChainSpec as Chain Specification
    participant SettlementLayer as Settlement Layer
    participant Backend as Node Backend

    CLI->>ChainSpec: Initialize Chain Configuration
    ChainSpec->>SettlementLayer: Determine Settlement Type
    SettlementLayer-->>ChainSpec: Configure Parameters
    ChainSpec->>Backend: Provide Chain Specification
    Backend->>Backend: Configure Node Settings
Loading

Possibly related PRs

Sensei, this PR represents a significant architectural refactoring that improves the modularity and flexibility of the Katana blockchain implementation! 🌟


🪧 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 2

🧹 Nitpick comments (5)
bin/katana/src/cli/init/mod.rs (2)

54-65: Enhance Validation for Chain ID Input

Ohayo sensei, the chain ID parser currently only checks for ASCII characters. Consider adding additional validation to ensure the chain ID meets the expected format and avoids invalid or potentially harmful inputs.

Apply this diff to improve the validation:

             let chain_id = CustomType::<String>::new("Id")
                 .with_help_message("This will be the id of your rollup chain.")
-                // checks that the input is a valid ascii string.
+                // Validates that the input is alphanumeric and within expected length.
                 .with_parser(&|input| {
-                    if input.is_ascii() {
+                    if input.chars().all(|c| c.is_alphanumeric() || c == '_') && input.len() <= 32 {
                         Ok(input.to_string())
                     } else {
                         Err(())
                     }
                 })
-                .with_error_message("Must be valid ASCII characters")
+                .with_error_message("Chain ID must be alphanumeric (including underscores), up to 32 characters")
                 .prompt()?;

128-133: Consider Removing Commented-Out Code

Ohayo sensei, it's generally good practice to avoid keeping commented-out code in the codebase. Since there's already a TODO note, consider removing this section to keep the code clean and maintainable.

crates/katana/primitives/src/contract.rs (1)

25-28: Sugoi constant additions, sensei! 🎋

The new predefined contract address constants will be helpful for testing and default configurations. The implementation is clean and follows Rust naming conventions.

However, consider adding documentation to explain the purpose and typical usage of these constants.

+    /// The zero address (0x0)
     pub const ZERO: Self = Self(Felt::ZERO);
+    /// The one address (0x1)
     pub const ONE: Self = Self(Felt::ONE);
+    /// The two address (0x2)
     pub const TWO: Self = Self(Felt::TWO);
+    /// The three address (0x3)
     pub const THREE: Self = Self(Felt::THREE);
crates/katana/core/src/backend/gas_oracle.rs (1)

62-68: Nice addition of Starknet support, sensei!

The placeholder implementation for Starknet gas prices is well-documented and provides a clear path for future implementation.

Consider adding a TODO comment with tracking issue number for implementing actual Starknet gas price sampling in the future.

crates/katana/executor/Cargo.toml (1)

24-27: Consider grouping related dependencies.

Ohayo! The dependencies could be better organized by grouping katana-related dependencies together.

-katana-cairo.workspace = true
-katana-chain-spec.workspace = true
-katana-provider = { workspace = true, features = [ "test-utils" ] }
-katana-rpc-types.workspace = true
+katana-cairo.workspace = true
+katana-provider = { workspace = true, features = [ "test-utils" ] }
+katana-rpc-types.workspace = true
+katana-chain-spec.workspace = true
🛑 Comments failed to post (2)
crates/katana/chain-spec/src/file.rs (1)

58-59: 🛠️ Refactor suggestion

Remove Debugging Statement

Ohayo sensei, the dbg! macro is used for debugging purposes and should be removed from production code to prevent unnecessary console output.

Apply this diff to remove the debug statement:

         let dir = ChainConfigDir::create(&chain_spec.id)?;
 
-        dbg!(&dir);
📝 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.

    let dir = ChainConfigDir::create(&chain_spec.id)?;

crates/katana/core/src/backend/gas_oracle.rs (1)

300-305: 💡 Codebase verification

Ohayo! Test coverage needed for sampled_starknet, sensei!

The sampled_starknet() function is implemented but currently lacks test coverage. Since it's a simple implementation returning fixed gas prices, adding tests would help ensure interface consistency as the implementation evolves.

🔗 Analysis chain

Test case update looks good, sensei!

The test has been updated to use the new GasOracle enum and properly handle the sampled variant.

Consider adding test coverage for the new sampled_starknet functionality:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check test coverage for sampled_starknet
rg -l "sampled_starknet.*test" .

Length of output: 34


Script:

#!/bin/bash
# Find the implementation of sampled_starknet
ast-grep --pattern 'fn sampled_starknet'

# Find test files in the gas oracle directory
fd test\.rs$ crates/katana/core/src/backend/

# Look for any gas oracle related tests
rg -l "GasOracle.*test" .

Length of output: 118


Script:

#!/bin/bash
# Look for any Starknet-related code in gas oracle
rg -l "starknet" crates/katana/core/src/backend/gas_oracle.rs

# Find all test files in the project
fd "test\.rs$"

# Look for any gas-related tests
rg -l "gas.*test" .

Length of output: 907


Script:

#!/bin/bash
# Check the content of gas oracle file focusing on tests and Starknet
rg "mod test|starknet" -A 5 crates/katana/core/src/backend/gas_oracle.rs

Length of output: 390

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

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

Please upload report for BASE (katana/chainspec@47ed4d1). Learn more about missing BASE report.

Files with missing lines Patch % Lines
bin/katana/src/cli/init/mod.rs 0.00% 3 Missing ⚠️
crates/katana/chain-spec/src/file.rs 98.16% 2 Missing ⚠️
crates/katana/cli/src/args.rs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##             katana/chainspec    #2945   +/-   ##
===================================================
  Coverage                    ?   55.95%           
===================================================
  Files                       ?      445           
  Lines                       ?    57592           
  Branches                    ?        0           
===================================================
  Hits                        ?    32226           
  Misses                      ?    25366           
  Partials                    ?        0           

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

@kariy kariy merged commit aa316df into katana/chainspec Jan 23, 2025
15 checks passed
@kariy kariy deleted the katana/chainspec-file branch January 23, 2025 18:30
@coderabbitai coderabbitai bot mentioned this pull request Jan 23, 2025
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