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): genesis deprecated declared classes in state updates #2893

Merged
merged 2 commits into from
Jan 11, 2025

Conversation

kariy
Copy link
Member

@kariy kariy commented Jan 10, 2025

Put legacy classes in the correct mappings in the StateUpdates struct.

Summary by CodeRabbit

  • New Features

    • Enhanced class management with support for deprecated and legacy classes.
    • Added method to check if a class was declared before a specific block.
  • Refactor

    • Simplified contract class type checking methods.
    • Improved handling of state updates for class declarations.
  • Bug Fixes

    • Updated database insertion logic to accommodate deprecated class declarations.
  • Chores

    • Added optional dependency on starknet-crypto and updated feature requirements for starknet-messaging.

@kariy kariy changed the title fix(katana): deprecated declared classes in state updates fix(katana): genesis deprecated declared classes in state updates Jan 10, 2025
Copy link

coderabbitai bot commented Jan 10, 2025

Pull Request Analysis

Ohayo, sensei! Here's a comprehensive breakdown of the changes:

Walkthrough

The pull request introduces modifications to class management and state updates across multiple Rust files. The primary focus is on distinguishing between legacy and non-legacy classes, adding a new deprecated_declared_classes field, and updating methods to handle this new classification. The changes impact how contract classes are processed, declared, and stored, with improvements in type checking and state management.

Changes

File Change Summary
crates/katana/primitives/src/chain_spec.rs Modified state_updates method to separate legacy and non-legacy class declarations.
crates/katana/primitives/src/class.rs Replaced as_class and as_legacy methods with boolean is_class and is_legacy methods.
crates/katana/storage/provider/src/providers/db/mod.rs Added handling for deprecated_declared_classes in block insertion.
crates/katana/storage/provider/src/providers/db/state.rs Introduced is_class_declared_before_block method and updated class-related method logic.
crates/katana/core/Cargo.toml Added starknet-crypto dependency and modified starknet-messaging feature to include it.

Sequence Diagram

sequenceDiagram
    participant ChainSpec
    participant ContractClass
    participant DbProvider
    participant HistoricalStateProvider

    ChainSpec->>ContractClass: Check class type (is_legacy/is_class)
    ContractClass-->>ChainSpec: Return boolean
    ChainSpec->>DbProvider: Insert block with state updates
    DbProvider->>HistoricalStateProvider: Verify class declaration
    HistoricalStateProvider-->>DbProvider: Confirmation of class status
Loading

Possibly Related PRs

Suggested Reviewers

  • glihm

Sensei, I hope this breakdown helps illuminate the intricacies of the pull request! Let me know if you need any further clarification. Ohayo! 🍵🥷


🪧 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/primitives/src/class.rs (1)

60-64: Consider adding migration guidance, sensei! 📚

Since this change is part of fixing deprecated declared classes, it would be helpful to add a doc comment explaining the migration path from as_legacy() to is_legacy() for downstream users.

Example doc addition:

/// Checks if this contract class is a Cairo 0 legacy class.
///
/// Returns `true` if the contract class is a legacy class, `false` otherwise.
///
/// Note: This replaces the previous `as_legacy()` method as part of the deprecated classes cleanup.
/// If you need to access the underlying legacy class, use pattern matching instead:
/// ```
/// match contract_class {
///     ContractClass::Legacy(legacy) => // handle legacy class
///     ContractClass::Class(_) => // handle Sierra class
/// }
/// ```
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ecaa3ae and b112672.

📒 Files selected for processing (2)
  • crates/katana/core/Cargo.toml (2 hunks)
  • crates/katana/primitives/src/class.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: fmt
🔇 Additional comments (3)
crates/katana/core/Cargo.toml (2)

39-39: Ohayo! Nice addition of the optional dependency, sensei!

The addition of starknet-crypto as an optional dependency aligns well with the modular design principles. This approach ensures that the crypto functionality is available only when needed for handling legacy classes in state updates.


53-53: Clean feature definition, sensei!

The starknet-messaging feature now correctly depends on starknet-crypto, which makes sense as messaging operations might require cryptographic capabilities when dealing with state updates.

Let's verify if any other features might need the crypto dependency:

✅ Verification successful

Ohayo! Your feature definition is spot-on, sensei!

After thorough verification, the starknet-messaging feature correctly depends on starknet-crypto. Other features in the codebase either have direct crypto dependencies where needed or don't require crypto capabilities.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential crypto-related functionality in other features
rg -l "crypto|sign|verify|hash" --type rust | grep -v "messaging"

Length of output: 11799


Script:

#!/bin/bash
# Find all Cargo.toml files and search for starknet/crypto related features and dependencies
fd Cargo.toml --type f --exec sh -c 'echo "=== {} ==="; grep -A 5 -B 5 "features\|starknet\|crypto" {} || true'

Length of output: 40768

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

60-64: Ohayo! Clean implementation of is_legacy, sensei! 🎋

The change from Option<&T> to a boolean simplifies the API while maintaining functionality. However, I notice that the counterpart is_class method mentioned in the summary is missing.

Let's verify the impact of removing as_legacy on existing callers:

Could you also add the is_class method for consistency? Here's a suggested implementation:

/// Checks if this contract class is a Sierra class.
///
/// Returns `true` if the contract class is a Sierra class, `false` otherwise.
pub fn is_class(&self) -> bool {
    matches!(self, Self::Class(_))
}
✅ Verification successful

Ohayo! The removal of as_legacy is safe, sensei! 🎋

The codebase shows no remaining usage of the removed method, and all legacy class handling is done through pattern matching and direct variants. The new is_legacy implementation is clean and idiomatic.

Please add the suggested is_class method for API consistency:

pub fn is_class(&self) -> bool {
    matches!(self, Self::Class(_))
}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining uses of as_legacy that need updating
rg "as_legacy\(\)" --type rust

Length of output: 32


Script:

#!/bin/bash
# Search for any form of as_legacy usage
rg "as_legacy" --type rust

# Look for the old implementation pattern
ast-grep --pattern 'fn as_legacy'

# Also check for potential uses of LegacyContractClass
rg "LegacyContractClass" --type rust -A 2

Length of output: 14561

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.83%. Comparing base (dd1ccce) to head (b112672).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2893      +/-   ##
==========================================
+ Coverage   55.81%   55.83%   +0.01%     
==========================================
  Files         449      449              
  Lines       57697    57700       +3     
==========================================
+ Hits        32206    32219      +13     
+ Misses      25491    25481      -10     

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

@kariy kariy merged commit b5e45c3 into main Jan 11, 2025
15 checks passed
@kariy kariy deleted the katana/deprecated-class branch January 11, 2025 00:04
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