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-contracts): update piltover #2980

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Feb 2, 2025

@kariy this PR contains the contract class built on your PR cartridge-gg/piltover#5 rebased on main.

Also added katana init --list and katana init --show-config <chain_id> which I found useful for dev purposes. At your consideration if they are worth being kept. Feature added in #2983 .

Summary by CodeRabbit

  • New Features

    • Introduced an integration with a new external module to broaden functionality.
    • Enhanced the contract deployment flow with additional validation checks for improved reliability.
    • Increased the RPC server’s response capacity to support larger data transfers.
    • Added optional configuration fields for maximum request and response body sizes in the RPC server settings.
  • Chores

    • Updated dependency sources and versions for better stability.
    • Optimized the build process for more efficient external module assembly.
    • Updated the submodule reference to a new repository.

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

Attention: Patch coverage is 23.80952% with 48 lines in your changes missing coverage. Please review.

Project coverage is 57.06%. Comparing base (022d71a) to head (d233272).

Files with missing lines Patch % Lines
bin/katana/src/cli/init/deployment.rs 0.00% 36 Missing ⚠️
crates/katana/rpc/rpc/src/lib.rs 33.33% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2980      +/-   ##
==========================================
+ Coverage   57.02%   57.06%   +0.03%     
==========================================
  Files         429      429              
  Lines       56939    56925      -14     
==========================================
+ Hits        32470    32484      +14     
+ Misses      24469    24441      -28     

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

bin/katana/src/cli/init/mod.rs Outdated Show resolved Hide resolved
@kariy kariy force-pushed the katana/piltover-update-deser branch from 50f0094 to 3a4ffb3 Compare February 2, 2025 18:47
@kariy kariy changed the title fix(katana-contracts): update piltover and add dev options to katana init fix(katana-contracts): update piltover Feb 2, 2025
@kariy kariy force-pushed the katana/piltover-update-deser branch from ae75910 to 9152f2c Compare February 3, 2025 03:20
@glihm glihm requested a review from kariy February 7, 2025 19:06
@glihm glihm marked this pull request as ready for review February 7, 2025 19:06
Copy link

coderabbitai bot commented Feb 7, 2025

Ohayo, sensei! Below is the updated summary of the PR changes:

Walkthrough

This PR updates the Piltover dependency configuration and enhances deployment logic. The submodule URL for Piltover has been changed, a new Piltover dependency has been added, and the cainome-cairo-serde dependency has been upgraded. Additionally, deployment initialization now includes new program hash constants with improved validation and error handling. The build process is refined through adjustments in the Makefile, and the RPC server’s configuration now supports larger request and response body sizes.

Changes

File(s) Change Summary
.gitmodules, bin/katana/Cargo.toml, crates/katana/contracts/piltover Modified Piltover dependency configuration; updated submodule URL, added new dependency with revision, and updated the subproject commit hash.
Cargo.toml Upgraded dependency cainome-cairo-serde from v0.4.11 to v0.4.12.
bin/katana/src/cli/init/deployment.rs Enhanced deployment logic by adding SNOS and LAYOUT bridge program hash constants, updating the contract initialization process, and extending error handling with a new variant.
crates/katana/contracts/Makefile, crates/katana/rpc/rpc/src/lib.rs Updated build configurations: changed BUILD_DIR to an absolute path, refined build rules for Piltover contracts, and enhanced RpcServer configuration for request and response body sizes.
crates/katana/cli/src/args.rs, crates/katana/cli/src/options.rs, crates/katana/node/src/config/rpc.rs Modified RPC configurations to support optional max connections and body sizes. Removed unnecessary constants and streamlined initialization logic.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI Sensei
    participant Deploy as Deployment Module
    participant RPC as RpcProvider
    CLI->>Deploy: Initiate Deployment
    Deploy->>RPC: Retrieve Program Info (Hashes)
    RPC-->>Deploy: Return Program Hashes
    Deploy->>Deploy: Validate against SNOS and LAYOUT constants
    alt Validation Success
      Deploy-->>CLI: Confirm Deployment Success
    else Validation Failure
      Deploy-->>CLI: Return InvalidSnosProgramHash error
    end
Loading

Possibly related PRs

  • feat(katana): L1 initialization command #2821: The changes in the main PR, which involve updating the URL of a submodule in the .gitmodules file, are related to the addition of a new submodule for "crates/katana/contracts/piltover" in the retrieved PR, as both PRs modify the same submodule entry.

🪧 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 (1)
crates/katana/node/src/config/rpc.rs (1)

43-45: Add documentation for the new configuration fields.

Ohayo sensei! Consider adding doc comments for these new fields to explain:

  • The purpose and impact of each field
  • The units used (bytes, KB, MB?)
  • The behavior when set to None

Apply this diff to add documentation:

+    /// Maximum number of concurrent connections allowed.
+    /// When set to None, no limit is enforced.
     pub max_connections: Option<u32>,
+    /// Maximum size of a request body in bytes.
+    /// When set to None, no limit is enforced.
     pub max_request_body_size: Option<u32>,
+    /// Maximum size of a response body in bytes.
+    /// When set to None, no limit is enforced.
     pub max_response_body_size: Option<u32>,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12b849b and 3d12cbc.

📒 Files selected for processing (5)
  • crates/dojo/test-utils/src/sequencer.rs (2 hunks)
  • crates/katana/cli/src/args.rs (1 hunks)
  • crates/katana/cli/src/options.rs (3 hunks)
  • crates/katana/node/src/config/rpc.rs (2 hunks)
  • crates/katana/rpc/rpc/src/lib.rs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/katana/rpc/rpc/src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: ensure-wasm
  • GitHub Check: clippy
  • GitHub Check: docs
🔇 Additional comments (2)
crates/dojo/test-utils/src/sequencer.rs (1)

129-129: LGTM!

Ohayo sensei! The change to use ..Default::default() aligns well with the updated RpcConfig structure where max_connections is now optional.

crates/katana/cli/src/options.rs (1)

109-118: LGTM!

Ohayo sensei! The CLI argument definitions for the new configuration options are well-documented and properly integrated into the ServerOptions struct.

Comment on lines +223 to +224
max_request_body_size: None,
max_response_body_size: None,
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use CLI arguments for request/response body sizes.

Ohayo sensei! The new body size fields are hardcoded to None instead of using the values from self.server. Consider using the CLI arguments:

-                max_request_body_size: None,
-                max_response_body_size: None,
+                max_request_body_size: self.server.max_request_body_size,
+                max_response_body_size: self.server.max_response_body_size,
📝 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.

Suggested change
max_request_body_size: None,
max_response_body_size: None,
max_request_body_size: self.server.max_request_body_size,
max_response_body_size: self.server.max_response_body_size,

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

108-119: Ohayo! The server configuration enhancements look great, sensei!

The changes provide more flexibility in server configuration by:

  • Making max_connections optional
  • Adding configurable request and response body size limits

These improvements will help prevent resource exhaustion and provide better control over server behavior.

Consider adding validation to ensure that when body size limits are set, they are reasonable values (e.g., not too small to handle typical requests or too large to cause memory issues).

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d12cbc and 6c50924.

📒 Files selected for processing (1)
  • crates/katana/cli/src/options.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: docs
  • GitHub Check: clippy
  • GitHub Check: build
  • GitHub Check: ensure-wasm
🔇 Additional comments (1)
crates/katana/cli/src/options.rs (1)

143-145: The default implementation is clean and idiomatic, sensei!

Setting the new fields to None by default is a good choice, allowing the server to use its internal defaults when no explicit values are provided.

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: 2

🧹 Nitpick comments (1)
bin/katana/src/cli/init/deployment.rs (1)

323-327: Consider updating the NOTE comment, sensei.

The comment about using the same address for both fee tokens could be more descriptive about when this limitation will be addressed.

Consider updating the comment:

-// NOTE: The reason why we're using the same address for both fee tokens is because we don't yet
-// support having native fee token on the chain.
+// NOTE: Using the same address for both fee tokens temporarily.
+// TODO: Update when native fee token support is implemented (tracked in issue #XXXX)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c50924 and 323eda1.

📒 Files selected for processing (1)
  • bin/katana/src/cli/init/deployment.rs (7 hunks)
🔇 Additional comments (3)
bin/katana/src/cli/init/deployment.rs (3)

104-106: Nice optimization for genesis block, sensei!

Using Felt::MAX for the genesis block number is a good practice as it helps distinguish the genesis block from regular blocks.


142-146: Clean implementation of ProgramInfo, sensei!

The ProgramInfo structure provides a clear and organized way to manage program-related information.


230-235: Solid validation for SNOS program hash, sensei!

The addition of SNOS program hash validation enhances the security and reliability of the deployment process.

Comment on lines 209 to 213
// TODO:
//
// This is the default fee token contract address. We shouldn't hardcode
// this and need to handle this more elegantly.
felt!("0x2e7442625bab778683501c0eadbc1ea17b3535da040a12ac7d281066e915eea"),
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! Another TODO that needs attention, sensei.

The hardcoded fee token address should be handled more elegantly as noted in the TODO comment. Consider making it configurable.

Consider adding a configuration parameter for the fee token address:

-        felt!("0x2e7442625bab778683501c0eadbc1ea17b3535da040a12ac7d281066e915eea"),
+        config.fee_token_address,
📝 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.

Suggested change
// TODO:
//
// This is the default fee token contract address. We shouldn't hardcode
// this and need to handle this more elegantly.
felt!("0x2e7442625bab778683501c0eadbc1ea17b3535da040a12ac7d281066e915eea"),
// TODO:
//
// This is the default fee token contract address. We shouldn't hardcode
// this and need to handle this more elegantly.
config.fee_token_address,

Comment on lines 32 to 34
// TODO: to replace with actual value.
const LAYOUT_BRIDGE_PROGRAM_HASH: Felt =
felt!("0x193641eb151b0f41674641089952e60bc3aded26e3cf42793655c562b8c3aa0");
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

⚠️ Potential issue

🧩 Analysis chain

Ohayo! TODO comment needs attention, sensei.

The TODO comment indicates that LAYOUT_BRIDGE_PROGRAM_HASH needs to be replaced with the actual value. This could lead to runtime issues if not addressed.

Let me help verify if this hash is used in production:


🏁 Script executed:

#!/bin/bash
# Search for references to this hash in the codebase
rg -l "0x193641eb151b0f41674641089952e60bc3aded26e3cf42793655c562b8c3aa0"

Length of output: 111


Ohayo, sensei! The shell script confirms that the hardcoded hash is only referenced in bin/katana/src/cli/init/deployment.rs. Since the constant is marked with a TODO and isn’t used elsewhere, it’s clear that the placeholder value is intended to be updated prior to production—otherwise, you risk potential runtime issues when this value is relied on. Please update LAYOUT_BRIDGE_PROGRAM_HASH with the correct production value.

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

227-269: Ohayo! Comprehensive validation logic, sensei!

The validation checks for program hashes are thorough and well-structured. However, consider extracting the fee token address validation into a separate function for better reusability.

+fn validate_fee_token(actual: Felt, expected: Felt) -> Result<(), ContractInitError> {
+    if actual != expected {
+        return Err(ContractInitError::InvalidFeeToken {
+            actual,
+            expected,
+        });
+    }
+    Ok(())
+}
+
 pub async fn check_program_info(
     chain_id: Felt,
     appchain_address: Felt,
     provider: &RpcProvider,
 ) -> Result<(), ContractInitError> {
     // ... existing code ...
+    validate_fee_token(actual_fee_token, expected_fee_token)?;
     // ... rest of the code ...
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 323eda1 and 743413d.

📒 Files selected for processing (1)
  • bin/katana/src/cli/init/deployment.rs (7 hunks)
🧰 Additional context used
🪛 GitHub Actions: ci
bin/katana/src/cli/init/deployment.rs

[warning] 39-39: Comments have been modified for clarity. Please ensure that the changes maintain the intended meaning.

🔇 Additional comments (5)
bin/katana/src/cli/init/deployment.rs (5)

30-52: Ohayo! Documentation looks good, sensei!

The documentation for both program hashes is thorough and includes helpful links to the source code.

🧰 Tools
🪛 GitHub Actions: ci

[warning] 39-39: Comments have been modified for clarity. Please ensure that the changes maintain the intended meaning.


115-126: Ohayo! Good use of constants and documentation, sensei!

The use of constants with clear documentation improves code maintainability. The explanation for INITIAL_BLOCK_NUMBER being Felt::MAX is particularly helpful.


164-169: Ohayo! TODO needs attention, sensei.

The hardcoded fee token address should be handled more elegantly as noted in the TODO comment. Consider making it configurable.


176-184: Ohayo! Good refactoring with ProgramInfo, sensei!

The use of the ProgramInfo struct improves code organization and type safety.


305-310: Ohayo! Good error handling addition, sensei!

The new error variant InvalidSnosProgramHash follows the existing error pattern and provides clear error messages.

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

261-273: Enhance error handling with more context.

Consider adding more context to error messages by including the chain ID in the error variants.

-    if actual_program_info.program_hash != LAYOUT_BRIDGE_PROGRAM_HASH {
-        return Err(ContractInitError::InvalidProgramHash {
-            actual: actual_program_info.program_hash,
-            expected: LAYOUT_BRIDGE_PROGRAM_HASH,
-        });
-    }
+    if actual_program_info.program_hash != LAYOUT_BRIDGE_PROGRAM_HASH {
+        return Err(ContractInitError::InvalidProgramHash {
+            chain_id,
+            actual: actual_program_info.program_hash,
+            expected: LAYOUT_BRIDGE_PROGRAM_HASH,
+        });
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 743413d and d233272.

📒 Files selected for processing (1)
  • bin/katana/src/cli/init/deployment.rs (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: ensure-wasm
  • GitHub Check: docs
  • GitHub Check: build
🔇 Additional comments (5)
bin/katana/src/cli/init/deployment.rs (5)

36-37: LGTM! Well-documented constant with source reference.

The SNOS program hash constant is well-documented with a clear explanation and source link.


119-129: LGTM! Well-documented initial values with clear explanations.

The initial values for state root, block number, and block hash are well-documented, especially the explanation for using Felt::MAX as the initial block number with a reference to the source code.


168-173: Ohayo! Another TODO that needs attention, sensei.

The hardcoded fee token address should be handled more elegantly as noted in the TODO comment. Consider making it configurable.


180-188: LGTM! Clean program info initialization.

The program info initialization is clean and well-structured using the new ProgramInfo struct.


309-314: LGTM! Clear error variant for SNOS program hash validation.

The new error variant for SNOS program hash validation is well-structured and follows the existing error pattern.

Comment on lines +52 to +53
const LAYOUT_BRIDGE_PROGRAM_HASH: Felt =
felt!("0x193641eb151b0f41674641089952e60bc3aded26e3cf42793655c562b8c3aa0");
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the Layout Bridge program hash value.

The hardcoded hash appears to be truncated (missing a digit) compared to typical Starknet hashes.


🏁 Script executed:

#!/bin/bash
# Verify the hash length
echo "0x193641eb151b0f41674641089952e60bc3aded26e3cf42793655c562b8c3aa0" | wc -c

Length of output: 83


Ohayo sensei, based on our check:

  • The hardcoded hash "0x193641eb151b0f41674641089952e60bc3aded26e3cf42793655c562b8c3aa0" prints a total of 65 characters (excluding the newline), indicating it’s missing one digit compared to the usual Starknet hash format (which should be "0x" plus 64 hex digits, or 66 characters total).

Please update the constant value with the full hash.

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