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

refactor(katana): return error as default for state commitment provider #2967

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

kariy
Copy link
Member

@kariy kariy commented Jan 29, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • None
  • Bug Fixes

    • Corrected a minor typo in error message
  • Refactor

    • Simplified state proof and root handling across multiple components
    • Updated error handling for state root and proof operations
  • Chores

    • Removed unsupported multiproof and state root retrieval methods
    • Added default error responses for state proof and root operations

The changes primarily focus on streamlining state management interfaces and improving error handling in the system.

@kariy kariy changed the base branch from main to katana/executor-refactor January 29, 2025 15:22
Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

Ohayo, sensei! This pull request introduces significant changes to the state management and proof handling in the Katana executor. The modifications primarily involve removing multiproof and state root functionality across several components. Key changes include simplifying trait implementations, adding new error variants for state proofs and roots, and providing default error-based implementations for previously unimplemented methods.

Changes

File Change Summary
crates/katana/executor/src/.../state.rs Removed StateProofProvider and StateRootProvider implementations for CachedState<S>
crates/katana/storage/provider/src/error.rs Added StateProofNotSupported and StateRootNotFound error variants
crates/katana/storage/provider/src/providers/fork/state.rs Removed multiproof and root retrieval methods for ForkedStateDb, LatestStateProvider, and ForkedSnapshot
crates/katana/storage/provider/src/traits/state.rs Added default error implementations for StateRootProvider and StateProofProvider methods

Possibly related PRs


🪧 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: 1

🧹 Nitpick comments (4)
crates/katana/executor/src/implementation/blockifier/state.rs (1)

239-239: Ohayo sensei, empty trait implementation might lead to potential confusion!
Returning a default error or at least logging a message may help clarify that these proofs are not supported. Otherwise, calls to these traits might seem to succeed but provide no meaningful results.

crates/katana/storage/provider/src/traits/state.rs (2)

36-39: Ohayo sensei, returning Ok(None) for storage root!
The new default might preserve backward compatibility. However, ensure that code calling storage_root() expects an optional or no-op response.


113-116: Ohayo sensei, unify the class multiproof behavior with other methods!
All multiproof methods consistently respond with StateProofNotSupported. This is a neat approach but watch for partial usage in advanced features or test code.

Would you like me to open an issue to track removing references to multiproof from any residual code?

crates/katana/storage/provider/src/error.rs (1)

119-119: Ohayo sensei, corrected the typo in “Other” error message!
Fixing “soemthing” grammar improves codebase quality and user readability. Thanks for addressing this.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc88734 and f6355bf.

📒 Files selected for processing (4)
  • crates/katana/executor/src/implementation/blockifier/state.rs (1 hunks)
  • crates/katana/storage/provider/src/error.rs (2 hunks)
  • crates/katana/storage/provider/src/providers/fork/state.rs (3 hunks)
  • crates/katana/storage/provider/src/traits/state.rs (3 hunks)
🔇 Additional comments (9)
crates/katana/executor/src/implementation/blockifier/state.rs (1)

241-241: Ohayo sensei, verify invocation points!
Since this trait is also empty, verify if there are other parts of the code that expect a valid state root. Returning a default error or clarifying the unsupported nature might avoid misleading usage downstream.

crates/katana/storage/provider/src/traits/state.rs (3)

26-28: Ohayo sensei, returning StateRootNotFound ensures a clear error!
This is a valid approach as long as no existing consumer code depends on a valid root. Make sure to handle or log this error in higher-level calls to maintain clarity on why the root is unavailable.


31-33: Ohayo sensei, consistent error for contract root retrieval!
Similar to classes_root(), returning StateRootNotFound clarifies unsupported state root queries. Confirm that’s the intended behavior across the codebase.


102-106: Ohayo sensei, raise error for unsupported storage multiproof!
The StateProofNotSupported error is explicit and avoids silent failures. This is good, but confirm that no older path relies on multiproofs being partially implemented.

crates/katana/storage/provider/src/error.rs (2)

99-101: Ohayo sensei, introducing “StateProofNotSupported”!
Explicitly enumerating the lack of support for state proofs is beneficial and clarifies user feedback. Nice addition!


102-104: Ohayo sensei, new “StateRootNotFound” error variant!
This variant is coherent with returning an error when the root is unavailable. Great for debugging root-dependent logic.

crates/katana/storage/provider/src/providers/fork/state.rs (3)

149-150: LGTM! Consistent implementation pattern.

Empty implementations maintain consistency with ForkedStateDb's approach, ensuring uniform behavior across provider types.


105-106: Ohayo! Empty trait implementations align with refactoring goals.

The removal of explicit implementations in favor of using trait defaults aligns with the PR objective of returning errors as default for state commitment provider.

Let's verify the default implementations in the trait definition:

✅ Verification successful

Ohayo! Empty trait implementations are safe and working as intended, sensei!

The empty implementations in ForkedStateDb correctly inherit the default trait implementations:

  • StateRootProvider provides a default state root calculation using Poseidon hash
  • StateProofProvider includes a default storage multiproof implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify default implementations in StateProofProvider and StateRootProvider traits

rg -A 5 "trait State(Proof|Root)Provider" $(fd -t f "state\.rs$" "crates/katana")

Length of output: 1588


224-225: Ohayo sensei! Implementation pattern completed consistently.

Empty implementations align with the pattern established for other providers. However, we should verify test coverage for the default error cases.

Let's check the test coverage:

✅ Verification successful

Ohayo sensei! Empty implementations are correct and safe here!

The empty trait implementations for StateProofProvider and StateRootProvider are intentional as they inherit the default implementations from the traits. The default implementations provide standard Starknet state behavior:

  • StateRootProvider uses Poseidon hash with "STARKNET_STATE_V0"
  • StateProofProvider includes default multiproof generation

No additional test coverage is needed as these are using the trait's default implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for tests covering state proof and root provider error cases

rg -l "test.*state.*(proof|root)" $(fd -t f "test.*\.rs$" "crates/katana")

Length of output: 178


Script:

#!/bin/bash
# Search for ForkedSnapshot in test files and look for state-related tests
echo "=== Searching for ForkedSnapshot tests ==="
rg -l "ForkedSnapshot.*test" crates/katana

echo -e "\n=== Checking implementation file for tests ==="
rg "^#\[test\]" -A 10 crates/katana/storage/provider/src/providers/fork/state.rs

echo -e "\n=== Looking for any state-related tests ==="
rg -l "impl.*State.*(Provider|Root)" crates/katana

Length of output: 1185


Script:

#!/bin/bash
# Look for trait-level tests and integration tests
echo "=== Checking for trait tests ==="
rg -p "trait.*State.*(Provider|Root)" -A 5 crates/katana/storage/provider/src/traits

echo -e "\n=== Looking for integration tests ==="
fd -t f "integration.*test.*\.rs$" crates/katana/storage/provider/
fd -t f "test.*\.rs$" crates/katana/storage/provider/tests/

Length of output: 1968

Comment on lines +108 to +111
fn contract_multiproof(&self, addresses: Vec<ContractAddress>) -> ProviderResult<MultiProof> {
let _ = addresses;
Err(ProviderError::StateProofNotSupported)
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ohayo sensei, confirm contract multiproof removal is fully integrated!
This new error is consistent with the approach in storage_multiproof. Verify that no higher-level parts of the system still expect multiproof functionality.

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.

Project coverage is 57.28%. Comparing base (9b7d58d) to head (f6355bf).
Report is 4 commits behind head on katana/executor-refactor.

Files with missing lines Patch % Lines
crates/katana/storage/provider/src/traits/state.rs 0.00% 23 Missing ⚠️
Additional details and impacted files
@@                     Coverage Diff                      @@
##           katana/executor-refactor    #2967      +/-   ##
============================================================
+ Coverage                     56.89%   57.28%   +0.38%     
============================================================
  Files                           423      423              
  Lines                         56070    56051      -19     
============================================================
+ Hits                          31902    32108     +206     
+ Misses                        24168    23943     -225     

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

@kariy kariy merged commit 846899f into katana/executor-refactor Jan 29, 2025
14 of 15 checks passed
@kariy kariy deleted the katana/trie-unsupported branch January 29, 2025 15:55
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