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): check predeployed settlement contract is configured correctly #2971

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

kariy
Copy link
Member

@kariy kariy commented Jan 29, 2025

Add a check on the No branch of 'Deploy settlement contract' prompt. The program config hash has to be computed from the chain id, so this avoid providing arbitrary settlement contract.

Screenshot 2025-01-29 at 2 54 01 PM

Summary by CodeRabbit

  • New Features

    • Enhanced contract deployment validation process
    • Added runtime handling improvements for settlement contract initialization
  • Refactor

    • Streamlined type definitions for RPC provider
    • Improved code structure for contract deployment checks
    • Simplified runtime type handling
  • Bug Fixes

    • Added validation to ensure settlement contract is correctly configured

Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

Ohayo, sensei! The pull request introduces refinements to the contract deployment process in Katana's initialization module. The changes focus on improving type definitions, specifically updating the InitializerAccount with a new RpcProvider type alias. A new check_program_info function is added to encapsulate contract verification logic, replacing inline checks and promoting better code organization. The modifications streamline the deployment workflow by centralizing program information validation.

Changes

File Change Summary
bin/katana/src/cli/init/deployment.rs - Added RpcProvider type alias
- Updated InitializerAccount type definition
- Introduced check_program_info async function for contract verification
bin/katana/src/cli/init/mod.rs - Renamed Runtime to AsyncRuntime in method signature
- Added contract program info validation

Possibly related PRs


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d354c6 and 4d7928b.

📒 Files selected for processing (1)
  • bin/katana/src/cli/init/mod.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bin/katana/src/cli/init/mod.rs

🪧 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 (2)
bin/katana/src/cli/init/mod.rs (1)

142-155: Ohayo sensei! Great addition of contract verification.

The verification logic ensures the settlement contract is properly configured before proceeding. However, we could enhance the error handling by providing more specific guidance.

Consider enhancing the error message to guide users on how to fix configuration issues:

-                    .context(
-                        "Invalid settlement contract. The contract might have been configured \
-                         incorrectly",
-                    )?;
+                    .context(
+                        "Invalid settlement contract configuration. Please ensure the contract was \
+                         deployed with correct program hash, config hash, and facts registry. \
+                         You may need to redeploy the contract.",
+                    )?;
bin/katana/src/cli/init/deployment.rs (1)

194-238: Excellent implementation of contract verification logic!

The function thoroughly validates all necessary components with clear error messages. Consider adding logging for debugging purposes.

Add debug logs to help with troubleshooting:

 pub async fn check_program_info(
     chain_id: Felt,
     appchain_address: Felt,
     provider: &RpcProvider,
 ) -> Result<(), ContractInitError> {
+    tracing::debug!("Verifying program info for contract {appchain_address:#x}");
     let appchain = AppchainContractReader::new(appchain_address, provider);

     // Compute the chain's config hash
     let config_hash = compute_config_hash(
         chain_id,
         felt!("0x2e7442625bab778683501c0eadbc1ea17b3535da040a12ac7d281066e915eea"),
     );
+    tracing::debug!("Expected config hash: {config_hash:#x}");

     // Assert that the values are correctly set
     let (program_info_res, facts_registry_res) =
         tokio::join!(appchain.get_program_info().call(), appchain.get_facts_registry().call());

     let (actual_program_hash, actual_config_hash) = program_info_res?;
     let facts_registry = facts_registry_res?;
+    tracing::debug!("Actual values - program_hash: {actual_program_hash:#x}, config_hash: {actual_config_hash:#x}, facts_registry: {facts_registry:#x}");
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f3373e and 0d354c6.

📒 Files selected for processing (2)
  • bin/katana/src/cli/init/deployment.rs (3 hunks)
  • bin/katana/src/cli/init/mod.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: fmt
🔇 Additional comments (3)
bin/katana/src/cli/init/mod.rs (1)

23-23: LGTM! Clear type alias.

The rename to AsyncRuntime improves code clarity by explicitly indicating its asynchronous nature.

bin/katana/src/cli/init/deployment.rs (2)

26-27: Clean type organization, sensei!

The introduction of RpcProvider type alias improves code readability and maintainability.


29-42: Well-structured contract interface definition.

The formatted abigen! macro improves code readability while maintaining functionality.

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

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

Project coverage is 57.18%. Comparing base (4f3373e) to head (4d7928b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
bin/katana/src/cli/init/deployment.rs 0.00% 53 Missing ⚠️
bin/katana/src/cli/init/mod.rs 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2971      +/-   ##
==========================================
- Coverage   57.19%   57.18%   -0.02%     
==========================================
  Files         423      423              
  Lines       56125    56147      +22     
==========================================
+ Hits        32103    32108       +5     
- Misses      24022    24039      +17     

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

@kariy kariy merged commit 010bf80 into main Jan 29, 2025
13 of 15 checks passed
@kariy kariy deleted the katana/init-check-predeployed branch January 29, 2025 21:41
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