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): add STRK fee token #2536

Merged
merged 15 commits into from
Oct 15, 2024
Merged

feat(katana): add STRK fee token #2536

merged 15 commits into from
Oct 15, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 14, 2024

resolves #2405

ref #2524

depends on #2541

deploy the STRK fee token by default. all the generated predeployed accounts will be prefunded in both ETH and STRK.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new ChainSpec structure for enhanced blockchain configuration.
    • Added SealedBlockWithStatus struct for improved block representation.
    • Updated transaction handling to support new fee structures, including InvokeTx::V3.
  • Improvements

    • Simplified genesis configuration logic and improved clarity in chain initialization.
    • Enhanced test setups by transitioning to a chain specification model.
    • Updated fee token address references for better clarity and specificity.
  • Bug Fixes

    • Corrected references to fee token addresses, ensuring consistent naming across the application.

@kariy kariy marked this pull request as ready for review October 15, 2024 16:53
@kariy kariy changed the title feat(katana): STRK fee token refactor(katana): move Genesis methods to ChainSpec Oct 15, 2024
@kariy kariy changed the title refactor(katana): move Genesis methods to ChainSpec feat(katana): add STRK fee token Oct 15, 2024
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 69.51%. Comparing base (cddb99e) to head (7eae009).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/katana/primitives/src/chain_spec.rs 90.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2536      +/-   ##
==========================================
+ Coverage   69.20%   69.51%   +0.31%     
==========================================
  Files         388      388              
  Lines       49819    49868      +49     
==========================================
+ Hits        34478    34667     +189     
+ Misses      15341    15201     -140     

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

Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

Ohayo, sensei! This pull request introduces significant modifications across various files, primarily focusing on the transition from using Genesis to ChainSpec for managing blockchain configurations and fee tokens. Key changes include updates to method signatures, the introduction of new structs, and the renaming of constants related to fee tokens. The overall structure of the node's command-line interface and blockchain initialization processes has been refined, enhancing clarity and functionality.

Changes

File Path Change Summary
bin/katana/src/cli/node.rs Updated NodeArgs struct methods to use ChainSpec, modified chain_id to Option<ChainId>, and refactored functions to accept ChainSpec.
crates/katana/core/src/backend/storage.rs Replaced Genesis type with ChainSpec in Blockchain methods, updated logic for genesis block hash retrieval and state updates.
crates/katana/executor/benches/utils.rs Changed DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS in transaction structures.
crates/katana/executor/src/implementation/blockifier/utils.rs Updated transact and call functions to support new InvokeTx::V3 variant, added parameters for step limits, and modified transaction handling logic.
crates/katana/executor/tests/executor.rs Updated to use DEFAULT_ETH_FEE_TOKEN_ADDRESS in tests, reflecting changes in fee token handling.
crates/katana/executor/tests/fixtures/mod.rs Renamed genesis function to chain, updated to return ChainSpec, and modified state provider logic accordingly.
crates/katana/executor/tests/fixtures/transaction.rs Updated to use ChainSpec instead of Genesis, reflecting changes in fee token handling.
crates/katana/node/src/lib.rs Changed fee token addresses to reference config.chain.fee_contracts, updated instantiation of Blockchain to use config.chain.
crates/katana/primitives/src/block.rs Introduced new struct SealedBlockWithStatus to encapsulate sealed blocks with their finality status.
crates/katana/primitives/src/chain_spec.rs Added FeeContracts struct, updated ChainSpec to include fee contracts, and enhanced methods for block and state updates.
crates/katana/primitives/src/genesis/constant.rs Renamed DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS, added DEFAULT_STRK_FEE_TOKEN_ADDRESS, and updated function visibility.
crates/katana/primitives/src/genesis/json.rs Removed fee_token and universal_deployer fields from GenesisJson, simplified structure.
crates/katana/primitives/src/genesis/mod.rs Removed FeeTokenConfig and UniversalDeployerConfig, updated Genesis struct to simplify its fields.
crates/katana/rpc/rpc/tests/starknet.rs Updated fee token constants and transaction logic to accommodate STRK fee token, added new test for v3 transactions.
crates/katana/storage/provider/src/test_utils.rs Renamed create_genesis_for_testing to create_chain_for_testing, updated to return ChainSpec.

Assessment against linked issues

Objective Addressed Explanation
Add support for paying fee using STRK (2405)
Implement a config flag to select fee-paying token (2405)

Possibly related issues

Possibly related PRs

Suggested labels

sozo


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

🧹 Outside diff range and nitpick comments (13)
crates/katana/executor/benches/utils.rs (1)

12-12: Ohayo again, sensei! The tx function update looks great!

The change to DEFAULT_ETH_FEE_TOKEN_ADDRESS is spot on and keeps us consistent with our new naming convention. It's like we're laying the groundwork for a multi-token future!

For future enhancement, consider parameterizing the fee token address in this function. This could make our benchmarks more flexible, allowing us to test with different fee tokens easily. What do you think, sensei?

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

37-42: Ohayo again, sensei! These changes look solid!

The transition from genesis to chain and the corresponding method updates align well with the shift to ChainSpec. It's a clear improvement in terms of code clarity and consistency.

A small suggestion to consider:

Consider renaming chain to chain_spec for even more clarity:

-    let chain = create_chain_for_testing();
+    let chain_spec = create_chain_for_testing();

-    let block = chain.block().seal_with_hash_and_status(hash, status);
-    let states = chain.state_updates();
+    let block = chain_spec.block().seal_with_hash_and_status(hash, status);
+    let states = chain_spec.state_updates();

This minor change would make it absolutely clear that we're working with a chain specification.


Line range hint 58-58: Ohayo, sensei! Good catch on the TODO!

The TODO comment about creating a genesis builder is a great idea for future improvement. It could significantly simplify the genesis creation process and enhance maintainability.

Would you like assistance in creating a GitHub issue to track this TODO? I can help draft the issue description for implementing a genesis builder.

crates/katana/executor/tests/fixtures/transaction.rs (2)

Line range hint 101-107: Ohayo, sensei! The executable_tx function looks great!

The transition from Genesis to ChainSpec is well-implemented. The function now correctly uses the chain parameter to access allocations.

A small suggestion to enhance readability:

Consider using pattern matching to destructure the allocation directly:

let (&addr, GenesisAllocation::Account(account)) = chain.genesis.allocations
    .first_key_value()
    .expect("should have account");

This would eliminate the need for the separate else panic and make the code more concise.


Line range hint 122-129: Excellent work on executable_tx_without_max_fee, sensei!

The transition from Genesis to ChainSpec is well-implemented here too. The function correctly uses the chain parameter to access allocations.

As with the executable_tx function, here's a small suggestion to enhance readability:

Consider using pattern matching to destructure the allocation directly:

let (&addr, GenesisAllocation::Account(account)) = chain.genesis.allocations
    .first_key_value()
    .expect("should have account");

This would eliminate the need for the separate else panic and make the code more concise.

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

Line range hint 169-176: Ohayo, sensei! The new struct looks great!

The SealedBlockWithStatus struct is well-designed and aligns perfectly with the PR objectives. It effectively combines a sealed block with its finality status, which is exactly what we need for the new fee token support.

One small suggestion to enhance the documentation:

Consider adding a brief explanation of how this struct relates to the new fee token support. For example:

 /// A sealed block along with its status.
 ///
 /// Block whose commitment has been computed.
+/// This struct is particularly useful for tracking blocks in the context of different fee tokens.
 #[derive(Debug, Clone)]
 pub struct SealedBlockWithStatus {
     pub block: SealedBlock,
     /// The block status.
     pub status: FinalityStatus,
 }

This addition would provide more context for developers working with this struct in the future.

crates/katana/primitives/src/genesis/constant.rs (1)

20-23: Ohayo again, sensei! This addition is spot on!

The new DEFAULT_STRK_FEE_TOKEN_ADDRESS constant is exactly what we need to support STRK as a fee token. Great job on maintaining consistency with the ETH constant format!

A tiny suggestion to make it even better:

Consider adding a brief explanation of what STRK is in the documentation comment, similar to how ETH is commonly known. This could help developers who might not be familiar with STRK. For example:

/// The default STRK (Starknet Token) fee token contract address.
/// Corresponds to 0x04718f5a0Fc34cC1AF16A1cdee98fFB20C31f5cD61D6Ab07201858f4287c938D
crates/katana/executor/tests/fixtures/mod.rs (1)

Line range hint 51-65: Ohayo, sensei! The chain function looks sharp!

The transition from genesis to chain is smooth like a well-forged Katana. The logic for generating accounts remains intact, which is great for consistency.

A small suggestion to make it even better:

Consider adding a comment explaining the purpose of the seed initialization. It might help future ninjas understand the reasoning behind this specific seed value.

 let mut seed = [0u8; 32];
+// Initialize the seed to generate a consistent set of test accounts
 seed[0] = b'0';
crates/katana/executor/tests/executor.rs (1)

309-312: Ohayo again, sensei! The assertion update looks good!

The change to use DEFAULT_ETH_FEE_TOKEN_ADDRESS in the assertion is consistent with the import statement modification. It maintains the test's functionality while adapting to the new constant name.

Consider enhancing this test to cover scenarios where STRK is used as the fee token. This could involve adding a new test case or modifying the existing one to handle both ETH and STRK fee token scenarios. Here's a potential refactor suggestion:

-assert!(
-    actual_storage_updates.contains_key(&DEFAULT_ETH_FEE_TOKEN_ADDRESS),
-    "fee token storage must get updated"
-);
+for &fee_token in &[DEFAULT_ETH_FEE_TOKEN_ADDRESS, DEFAULT_STRK_FEE_TOKEN_ADDRESS] {
+    assert!(
+        actual_storage_updates.contains_key(&fee_token),
+        "fee token storage for {} must get updated", 
+        if fee_token == DEFAULT_ETH_FEE_TOKEN_ADDRESS { "ETH" } else { "STRK" }
+    );
+}

This change would ensure that the test covers both ETH and STRK fee token scenarios. Don't forget to import DEFAULT_STRK_FEE_TOKEN_ADDRESS if you decide to implement this suggestion.

crates/katana/primitives/src/genesis/mod.rs (2)

Line range hint 118-125: Ohayo, sensei! Typo in Comment: "depoyer" Should Be "deployer"

In the comment before the universal deployer contract class, there's a minor typo:

// universal depoyer contract class

Please correct "depoyer" to "deployer" to maintain clarity.

Apply this diff to fix the typo:

-// universal depoyer contract class
+// universal deployer contract class

9-9: Ohayo, sensei! Consider Organizing Imports for Readability

The imports from constant are spread across multiple statements:

  • Line 9~:

    use constant::DEFAULT_ACCOUNT_CLASS;
  • Lines 16~ to 19~:

    use self::constant::{
        DEFAULT_ACCOUNT_CLASS_CASM, DEFAULT_ACCOUNT_CLASS_HASH, DEFAULT_ACCOUNT_COMPILED_CLASS_HASH,
        DEFAULT_LEGACY_ERC20_CASM, DEFAULT_LEGACY_ERC20_CLASS_HASH,
        DEFAULT_LEGACY_ERC20_COMPILED_CLASS_HASH, DEFAULT_LEGACY_UDC_CASM,
        DEFAULT_LEGACY_UDC_CLASS_HASH, DEFAULT_LEGACY_UDC_COMPILED_CLASS_HASH,
    };

Consolidating these imports can enhance readability and maintainability. Grouping related constants together or using glob imports where appropriate might help.

Also applies to: 16-19

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

Line range hint 71-93: Update documentation to reflect ChainSpec usage

The new_with_genesis function now accepts &ChainSpec instead of &Genesis. Please update the function's documentation and any relevant comments to reflect this change for clarity.

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

42-47: Add Documentation for FeeContracts Struct

Ohayo, sensei! To improve code readability and maintainability, consider adding Rustdoc comments to the FeeContracts struct and its fields eth and strk. This will help other developers understand the purpose and usage of the fee token contracts in the chain.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 547ad8b and 2e4f96d.

📒 Files selected for processing (18)
  • bin/katana/src/cli/node.rs (8 hunks)
  • crates/katana/core/src/backend/storage.rs (11 hunks)
  • crates/katana/executor/benches/utils.rs (3 hunks)
  • crates/katana/executor/src/implementation/blockifier/utils.rs (1 hunks)
  • crates/katana/executor/tests/executor.rs (2 hunks)
  • crates/katana/executor/tests/fixtures/mod.rs (4 hunks)
  • crates/katana/executor/tests/fixtures/transaction.rs (5 hunks)
  • crates/katana/node/src/lib.rs (3 hunks)
  • crates/katana/primitives/src/block.rs (1 hunks)
  • crates/katana/primitives/src/chain_spec.rs (1 hunks)
  • crates/katana/primitives/src/genesis/constant.rs (2 hunks)
  • crates/katana/primitives/src/genesis/json.rs (5 hunks)
  • crates/katana/primitives/src/genesis/mod.rs (5 hunks)
  • crates/katana/primitives/src/genesis/test-genesis-with-class.json (0 hunks)
  • crates/katana/primitives/src/genesis/test-genesis-with-duplicate-name.json (0 hunks)
  • crates/katana/primitives/src/genesis/test-genesis.json (0 hunks)
  • crates/katana/rpc/rpc/tests/starknet.rs (14 hunks)
  • crates/katana/storage/provider/src/test_utils.rs (4 hunks)
💤 Files with no reviewable changes (3)
  • crates/katana/primitives/src/genesis/test-genesis-with-class.json
  • crates/katana/primitives/src/genesis/test-genesis-with-duplicate-name.json
  • crates/katana/primitives/src/genesis/test-genesis.json
🧰 Additional context used
🔇 Additional comments (27)
crates/katana/executor/benches/utils.rs (1)

3-3: Ohayo, sensei! LGTM on the import statement update!

The change from DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS aligns perfectly with our mission to support different fee-paying tokens. It's a small but crucial step towards greater flexibility in our fee structure.

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

6-6: Ohayo, sensei! These import changes look great!

The new imports for ChainSpec and the combined import for address and chain_spec align perfectly with the transition from Genesis to ChainSpec. This change enhances code organization and readability.

Also applies to: 14-14


52-52: Ohayo once more, sensei! This function signature update is spot on!

The renaming of create_genesis_for_testing to create_chain_for_testing and the change in return type from Genesis to ChainSpec perfectly align with the overall transition in the codebase. It accurately represents the new functionality and maintains consistency.

crates/katana/executor/tests/fixtures/transaction.rs (2)

2-2: Ohayo, sensei! LGTM on the import changes.

The transition from Genesis to ChainSpec is well-reflected in the import statements. This change aligns perfectly with the PR objectives of updating the fee payment mechanism.


6-6: Excellent constant renaming, sensei!

The change from DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS is spot-on. It clearly indicates that this constant is specifically for the ETH fee token address, which aligns perfectly with the PR's goal of supporting both ETH and STRK as fee tokens.

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

Line range hint 1-176: Ohayo again, sensei! Overall, the changes look solid!

The addition of the SealedBlockWithStatus struct is well-integrated with the existing code. The minimal changes demonstrate a focused approach to implementing the new feature for supporting different fee tokens.

The new struct complements the existing SealedBlock and FinalityStatus types, providing a clean way to associate a block with its finality status. This will be particularly useful for managing blocks with different fee tokens.

Great job on maintaining code consistency and clarity!

crates/katana/primitives/src/genesis/constant.rs (2)

15-18: Ohayo, sensei! This change looks great!

The renaming of DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS enhances clarity and aligns perfectly with the PR's objective of supporting multiple fee tokens. It's a small change, but it makes a big difference in code readability.


113-113: Ohayo, sensei! Let's chat about this visibility change.

I noticed that get_fee_token_balance_base_storage_address is now pub instead of pub(super). While this might be intentional to allow broader use of this utility function, it's worth considering the implications:

  1. Does this change align with the module's encapsulation principles?
  2. Are there any security considerations in making this function more widely accessible?
  3. Are there other modules that now need this function, justifying the visibility change?

Could you please clarify the reasoning behind this change? It would be helpful to understand how this fits into the larger architecture and if any additional safeguards are needed.

crates/katana/executor/tests/fixtures/mod.rs (3)

10-10: Ohayo, sensei! LGTM on this import change.

The addition of ChainSpec import is spot-on for the transition from Genesis to ChainSpec. It's like adding a new weapon to our Katana arsenal!


70-71: Ohayo, sensei! The state_provider adaptation is on point!

The shift from &Genesis to &ChainSpec in the function signature is as smooth as a Katana slice. The use of chain.state_updates() maintains the functionality while embracing the new ChainSpec structure. Well done, fellow ninja!


226-229: Ohayo, sensei! The cfg function update looks promising!

The use of DEFAULT_ETH_FEE_TOKEN_ADDRESS aligns perfectly with our mission to support STRK as a fee token. It's like sharpening our Katana for a new battle!

However, let's make sure our blade is properly forged:

Could you confirm that DEFAULT_ETH_FEE_TOKEN_ADDRESS is correctly defined and imported? Let's run a quick check:

This will help us ensure that our new constant is properly in place across the codebase.

✅ Verification successful

Ohayo, sensei! The DEFAULT_ETH_FEE_TOKEN_ADDRESS is correctly defined and imported across the codebase. Everything looks sharp and ready for battle!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the definition and import of DEFAULT_ETH_FEE_TOKEN_ADDRESS
rg --type rust "DEFAULT_ETH_FEE_TOKEN_ADDRESS" crates/

Length of output: 4034

crates/katana/node/src/lib.rs (4)

176-177: Ohayo, sensei! LGTM: Fee token addresses updated as per PR objectives.

The changes to the FeeTokenAddresses struct now source both ETH and STRK addresses from config.chain.fee_contracts. This aligns perfectly with the PR's goal of supporting STRK as a fee token and provides a more flexible approach to managing fee token addresses.


Line range hint 176-243: Ohayo, sensei! Let's wrap up this review with a bow.

The changes in this file represent a significant shift in how chain configurations and fee tokens are handled. By moving from genesis-specific configurations to broader chain configurations, and explicitly including STRK alongside ETH as fee tokens, these modifications align perfectly with the PR objectives of supporting STRK for fee payments.

These changes seem to be part of a larger refactoring effort, and while they look good in isolation, it's crucial to ensure that all related parts of the codebase have been updated consistently. Keep an eye out for any other files or components that might need similar updates to maintain consistency across the entire system.

Great work on implementing this feature, sensei! It's a solid step towards supporting Starknet transactions v3.


243-243: Ohayo once more, sensei! The genesis Blockchain initialization also looks good, but let's verify.

The change from &config.chain.genesis to &config.chain in the Blockchain::new_with_genesis call is consistent with the previous change and aligns with the broader approach to chain configuration. However, we should also verify that the Blockchain::new_with_genesis method implementation has been updated to handle this new parameter correctly.

Let's confirm the Blockchain::new_with_genesis method signature:

#!/bin/bash
# Description: Verify the Blockchain::new_with_genesis method signature
rg --type rust "fn new_with_genesis.*&ChainSpec" crates/

241-241: Ohayo again, sensei! The Blockchain initialization looks good, but let's double-check something.

The change from &config.chain.genesis to &config.chain in the Blockchain::new_with_db call looks good and aligns with the broader changes in chain configuration handling. However, we should verify that the Blockchain::new_with_db method implementation has been updated to handle this new parameter correctly.

Let's confirm the Blockchain::new_with_db method signature:

crates/katana/executor/tests/executor.rs (1)

10-12: Ohayo, sensei! LGTM on the import statement update.

The renaming of DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS aligns well with the PR objective of supporting STRK as a fee token. It provides better clarity by explicitly mentioning ETH in the constant name.

To ensure consistency across the codebase, let's verify if this renaming has been applied uniformly:

✅ Verification successful

Ohayo, sensei! The renaming of DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS has been fully verified across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of DEFAULT_FEE_TOKEN_ADDRESS
# and verify the usage of DEFAULT_ETH_FEE_TOKEN_ADDRESS

echo "Checking for any remaining instances of DEFAULT_FEE_TOKEN_ADDRESS:"
rg "DEFAULT_FEE_TOKEN_ADDRESS" --type rust

echo "\nVerifying usage of DEFAULT_ETH_FEE_TOKEN_ADDRESS:"
rg "DEFAULT_ETH_FEE_TOKEN_ADDRESS" --type rust

Length of output: 4325

crates/katana/primitives/src/genesis/mod.rs (1)

Line range hint 109-116: Ohayo, sensei! Ensure Fee Token Configurability Aligns with PR Objectives

The default configuration currently hardcodes the fee token class as DEFAULT_LEGACY_ERC20_CLASS_HASH (ETH):

(
    DEFAULT_LEGACY_ERC20_CLASS_HASH,
    GenesisClass {
        sierra: None,
        casm: DEFAULT_LEGACY_ERC20_CASM.clone().into(),
        compiled_class_hash: DEFAULT_LEGACY_ERC20_COMPILED_CLASS_HASH,
    },
),

Given our objective to support STRK as a fee-paying token via a configuration flag, please verify that this hardcoded value does not impede users from specifying STRK as the fee token.

To confirm that fee token configurability is properly implemented, you can run:

✅ Verification successful

Fee Token Configurability Verified

Ohayo sensei! The fee token configurability aligns with PR objectives. Both ETH and STRK are supported as fee-paying tokens, and the hardcoded DEFAULT_LEGACY_ERC20_CLASS_HASH for ETH does not restrict the specification of STRK.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the presence of fee-paying token configuration options.

# Test: Search for command-line arguments or configurations related to the fee-paying token.
# Expect: Occurrences of "--fee-paying-token" or similar options.

rg --type rust 'fee[_-]paying[_-]token' --context 5

Length of output: 53


Script:

#!/bin/bash
# Description: Search for alternative fee token configuration options.

# Test: Look for variations of fee token configuration keywords.
# Expect: Occurrences of terms like "--fee-token", "--payment-token", "feeToken", or "paymentToken".

rg --type rust 'fee[_-]?token|payment[_-]?token' --context 5

Length of output: 29721

crates/katana/core/src/backend/storage.rs (4)

4-4: Ohayo, sensei! Importing ChainSpec is appropriate

The addition of use katana_primitives::chain_spec::ChainSpec; is necessary for the updated function signatures and ensures that the ChainSpec type is available.


284-287: Review fee token constants in tests

The tests are using DEFAULT_ETH_FEE_TOKEN_ADDRESS and related constants from genesis::constant. Since the objective is to support STRK as a fee-paying token, ensure that tests cover scenarios using STRK and that the constants are updated or parameterized as needed.

Do you need help updating the tests to include STRK as a fee-paying token?


107-113: Confirm parameter update in new_from_forked

The function new_from_forked now accepts chain: &ChainSpec instead of genesis: &Genesis. Ensure that all internal references within this function have been updated from genesis to chain to maintain consistency.

Run the following script to check for lingering references to genesis:

#!/bin/bash
# Description: Check for residual uses of `genesis` in `new_from_forked`

# Test: Search within the `new_from_forked` method for `genesis`
# Expect: No occurrences of `genesis` should be found
rg 'fn new_from_forked' -A 15 | rg 'genesis'

99-102: Ensure consistent updates in new_with_db

The new_with_db function now takes chain: &ChainSpec as a parameter. Verify that all calls to this function have been updated accordingly to prevent any mismatches.

Run the following script to find all calls to new_with_db and ensure they pass &ChainSpec:

✅ Verification successful

Ohayo, sensei!

It appears that the initial search didn't find any calls to new_with_db. To ensure we haven't missed any, let's refine our search pattern. Please run the following script to comprehensively find all invocations of new_with_db:

[/run_scripts]


Ohayo, sensei!

To ensure we've thoroughly checked all usages of new_with_db, please run the following script to find every call to this function, regardless of its arguments:

[/run_scripts]


Ohayo, sensei!

All calls to new_with_db correctly pass &ChainSpec as the second argument.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `new_with_db` use `&ChainSpec`

# Test: Search for function calls to `new_with_db`
# Expect: All calls pass `&ChainSpec` as the second argument
rg 'new_with_db\(([^,]+),\s*&\w+\)' -A 2 -B 2

Length of output: 250


Script:

#!/bin/bash
# Description: Verify all calls to `new_with_db` use `&ChainSpec`

# Refined Test: Search for function calls to `new_with_db` with any second argument
rg 'new_with_db\([^,]+,\s*&ChainSpec\)' --type rust

Length of output: 53


Script:

#!/bin/bash
# Description: Find all calls to `new_with_db` regardless of arguments

rg 'new_with_db\(' --type rust

Length of output: 481

bin/katana/src/cli/node.rs (6)

155-155: Update to default_value_t is Appropriate

Ohayo, sensei! Great job updating #[arg(default_value = "10")] to #[arg(default_value_t = 10)] for total_accounts. This change ensures that the default value is correctly interpreted as a numeric type.


416-429: Confirm STRK Fee Token Integration

Ohayo, sensei! The print_genesis_contracts function now includes details for the STRK Fee Token. Please verify that chain.fee_contracts.strk correctly references the STRK token's address and that the class hash is accurate.

Would you like assistance in verifying these values or updating the display to ensure all fee tokens are correctly represented?


Line range hint 368-438: Ensure Accurate Data Display in Intro Messages

Ohayo, sensei! The modifications to print_intro and print_genesis_contracts aim to display the correct information based on ChainSpec. Please confirm that all data, such as predeployed contracts and account details, are accurately retrieved and displayed.


312-338: Validate chain_spec Initialization and Account Generation

Ohayo, sensei! The chain_spec() function has been refactored to initialize from DEV_UNALLOCATED and conditionally set the chain_id and genesis. Please ensure that:

  • When a chain_id is provided, it's correctly assigned to chain_spec.id.
  • If a genesis configuration is provided, it's properly integrated.
  • The development accounts are generated and allocated as expected.

Here's a script to review how chain_spec is built and modified:

#!/bin/bash
# Description: Inspect `chain_spec` initialization and modifications

rg --type rust 'fn chain_spec\(' -A 50

236-236: Ensure Consistency with Updated print_intro Function

Ohayo, sensei! The print_intro function now takes &ChainSpec instead of &Genesis. Please verify that all calls to print_intro are updated accordingly and that the function processes the ChainSpec data correctly.

Here's a script to check all calls to print_intro:

#!/bin/bash
# Description: Find all calls to `print_intro` to ensure they pass `&ChainSpec`

rg --type rust 'print_intro\(' -A 2

185-185: ⚠️ Potential issue

Handle Optional chain_id Correctly

Ohayo, sensei! The chain_id field has been changed to Option<ChainId>. Please ensure that all usages of chain_id in the code handle the None case properly to avoid potential None unwraps or unexpected behaviors.

Here's a script to verify how chain_id is used throughout the codebase:

Comment on lines 37 to 38
eth: DEFAULT_ETH_FEE_TOKEN_ADDRESS,
strk: DEFAULT_ETH_FEE_TOKEN_ADDRESS,
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Ohayo, sensei! Found some inconsistencies with STRK fee token addresses.

I noticed that in benches/utils.rs, both eth and strk are set to DEFAULT_ETH_FEE_TOKEN_ADDRESS. However, elsewhere in the codebase, strk has its own distinct address (DEFAULT_STRK_FEE_TOKEN_ADDRESS). This inconsistency might lead to unexpected behavior during benchmarking.

🔗 Analysis chain

Ohayo, sensei! We might have a small hiccup in the envs function.

I noticed that both eth and strk fee token addresses are set to DEFAULT_ETH_FEE_TOKEN_ADDRESS. This seems a bit odd, considering our grand plan to support STRK as a separate fee-paying token.

Could you clarify if this is intentional? If not, we might want to introduce a separate constant for the STRK fee token address.

To verify the current usage of fee token addresses, let's run this quick check:

This will help us ensure consistency across the codebase, sensei!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of fee token address usage
rg --type rust "DEFAULT_ETH_FEE_TOKEN_ADDRESS" -C 3

Length of output: 19572

Comment on lines 53 to 54
let mut chain = chain_spec::DEV_UNALLOCATED.clone();

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! These changes are looking good!

The transition to creating a ChainSpec object while preserving the existing genesis creation logic is well-implemented. It maintains backward compatibility while allowing for future extensions to the ChainSpec.

A suggestion for potential improvement:

Consider extracting the genesis creation logic into a separate function for better modularity:

fn create_genesis() -> Genesis {
    let mut genesis = Genesis::default();
    // ... (existing genesis creation logic)
    genesis
}

pub fn create_chain_for_testing() -> ChainSpec {
    let mut chain = chain_spec::DEV_UNALLOCATED.clone();
    chain.genesis = create_genesis();
    chain
}

This refactoring would improve readability and make it easier to maintain or modify the genesis creation logic independently of the ChainSpec creation.

Also applies to: 79-81

Comment on lines 38 to 45
impl core::fmt::Debug for GenesisClass {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("GenesisClass")
.field("compiled_class_hash", &self.compiled_class_hash)
.field("casm", &"...")
.field("sierra", &"...")
.finish()
}
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! Clarify the Debug Implementation for GenesisClass

In the custom Debug implementation for GenesisClass, the casm and sierra fields are represented as "...":

.field("casm", &"...")
.field("sierra", &"...")

While this simplifies the debug output, consider whether this meets our debugging needs. Including more informative placeholders or actual summaries of these fields could enhance debugging effectiveness.

Comment on lines 142 to 149
DEFAULT_ETH_FEE_TOKEN_ADDRESS, DEFAULT_LEGACY_ERC20_CASM, DEFAULT_LEGACY_ERC20_CLASS_HASH,
DEFAULT_LEGACY_UDC_CASM, DEFAULT_LEGACY_UDC_CLASS_HASH, DEFAULT_UDC_ADDRESS,
};
use katana_primitives::genesis::Genesis;
use katana_primitives::receipt::{InvokeTxReceipt, Receipt};
use katana_primitives::state::StateUpdatesWithDeclaredClasses;
use katana_primitives::trace::TxExecInfo;
use katana_primitives::transaction::{InvokeTx, Tx, TxWithHash};
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor test imports to use chain_spec module

The test module imports from katana_primitives::genesis::Genesis. Since the main code now utilizes ChainSpec, consider updating the tests to import from katana_primitives::chain_spec for consistency.

Comment on lines 192 to 196
};

let mut chain = chain_spec::DEV.clone();
chain.genesis = genesis;

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Modify test setup to align with ChainSpec usage

In the blockchain_from_fork test, you're creating a Genesis instance and then assigning it to chain.genesis. To maintain consistency with the updated codebase, consider creating a custom ChainSpec directly or providing a helper function to generate a ChainSpec with the desired parameters.

Comment on lines 216 to 217
println!("creating invoke transaction v3...");

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! Consider replacing println! with a proper logging mechanism

Using println! for logging is not recommended in production code. It's better to use a logging framework to manage log levels and outputs.

Apply this diff to replace println! with an appropriate logging macro:

-                    println!("creating invoke transaction v3...");
+                    log::debug!("creating invoke transaction v3...");
📝 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
println!("creating invoke transaction v3...");
log::debug!("creating invoke transaction v3...");

Comment on lines +910 to +913
// craft a raw v3 transaction, should probably use abigen for simplicity
let to = DEFAULT_STRK_FEE_TOKEN_ADDRESS.into();
let selector = selector!("transfer");
let calldata = vec![felt!("0x1"), felt!("0x1"), Felt::ZERO];
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! Consider using abigen to simplify transaction crafting

In line 910, there's a comment suggesting that using abigen could simplify the crafting of the raw v3 transaction. Leveraging abigen would enhance code readability and maintainability by automatically generating contract bindings.

@@ -171,7 +171,7 @@

// Fund the new account
abigen_legacy!(FeeToken, "crates/katana/rpc/rpc/tests/test_data/erc20.json");
let contract = FeeToken::new(DEFAULT_FEE_TOKEN_ADDRESS.into(), &funding_account);
let contract = FeeToken::new(DEFAULT_ETH_FEE_TOKEN_ADDRESS.into(), &funding_account);
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! Consider parameterizing tests to include the STRK fee token

The tests at these lines currently use DEFAULT_ETH_FEE_TOKEN_ADDRESS as the fee token. With the introduction of STRK support, it would be beneficial to parameterize these tests to run with both ETH and STRK fee tokens. This ensures comprehensive test coverage and verifies functionality across both fee payment options.

Also applies to: 248-248, 313-313, 367-367, 398-398, 477-477, 523-523, 594-594, 680-680, 768-768, 818-818

@@ -1011,33 +842,20 @@ mod tests {
let expected_genesis = Genesis {
classes: expected_classes,
number: 0,
fee_token: expected_fee_token,
// fee_token: expected_fee_token,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ohayo sensei! Update tests to reflect the removal of fee_token

In the test, the line // fee_token: expected_fee_token, is commented out. Ensure that all tests are updated to accommodate the removal of fee_token from the GenesisJson struct. This includes removing or modifying test cases that are no longer applicable to maintain comprehensive test coverage.

Comment on lines 236 to 237
// pub fee_token: FeeTokenConfigJson,
// pub universal_deployer: Option<UniversalDeployerConfigJson>,
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Ohayo sensei! Impact of Removing fee_token Detected

  • References to fee_token found in the following files:
    • crates/katana/primitives/src/chain_spec.rs
    • crates/katana/node/src/lib.rs
    • crates/katana/executor/tests/executor.rs
    • crates/katana/executor/tests/fixtures/mod.rs
    • crates/katana/executor/benches/utils.rs
    • crates/katana/executor/src/implementation/blockifier/utils.rs
    • crates/katana/core/src/backend/storage.rs

Please update or remove these references to align with the removal of the fee_token field from GenesisJson.

🔗 Analysis chain

Ohayo sensei! Verify the impact of removing fee_token from GenesisJson

The fee_token field has been removed from the GenesisJson struct. This change may affect how fees are configured during genesis initialization. Please confirm that this aligns with the PR objectives and that all dependent code and configurations have been updated accordingly.

Run the following script to check for any remaining references to fee_token in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for references to 'fee_token' outside this file.

rg --type rust 'fee_token' --glob '!crates/katana/primitives/src/genesis/json.rs'

Length of output: 5762

@kariy kariy changed the base branch from main to katana/state-updates-at-chainspec October 15, 2024 17:26
Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

Ohayo, sensei! This pull request introduces significant changes to the configuration and handling of blockchain parameters within the Katana project. Key modifications include the restructuring of the NodeArgs and ChainSpec structures, the introduction of a new FeeContracts struct, and the renaming of constants related to fee tokens. The changes enhance the flexibility of configuration options and streamline the transaction handling process, particularly with respect to fee payments using different tokens.

Changes

File Path Change Summary
bin/katana/src/cli/node.rs Updated chain_id in EnvironmentOptions to Option<ChainId>, simplified total_accounts in StarknetOptions, refactored ChainSpec generation logic.
crates/katana/core/src/backend/storage.rs Replaced Genesis with ChainSpec in method signatures and implementations for new_with_genesis, new_with_db, and new_from_forked.
crates/katana/executor/benches/utils.rs Replaced DEFAULT_FEE_TOKEN_ADDRESS with DEFAULT_ETH_FEE_TOKEN_ADDRESS in tx and envs functions.
crates/katana/executor/src/implementation/blockifier/utils.rs Introduced transact_inner for fee calculation, modified handling of InvokeTx::V3 and DeployAccountTx::V3.
crates/katana/executor/tests/executor.rs Updated constant from DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS in tests.
crates/katana/executor/tests/fixtures/mod.rs Renamed genesis() to chain(), updated to return ChainSpec, modified state_provider() to accept ChainSpec.
crates/katana/executor/tests/fixtures/transaction.rs Updated to use ChainSpec instead of Genesis, modified invoke_executable_tx to use DEFAULT_ETH_FEE_TOKEN_ADDRESS.
crates/katana/node/src/lib.rs Updated fee_token_addresses to reference config.chain.fee_contracts, modified Blockchain instantiation to use &config.chain.
crates/katana/primitives/src/block.rs Added new struct SealedBlockWithStatus with block and status fields.
crates/katana/primitives/src/chain_spec.rs Added FeeContracts struct, modified methods for block creation and state updates to include fee tokens.
crates/katana/primitives/src/genesis/constant.rs Renamed DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS, added DEFAULT_STRK_FEE_TOKEN_ADDRESS.
crates/katana/primitives/src/genesis/json.rs Removed FeeTokenConfigJson and UniversalDeployerConfigJson structs from GenesisJson.
crates/katana/primitives/src/genesis/mod.rs Removed FeeTokenConfig and UniversalDeployerConfig structs from Genesis.
crates/katana/primitives/src/genesis/test-genesis-with-class.json Removed feeToken and universalDeployer entries from JSON.
crates/katana/rpc/rpc/tests/starknet.rs Updated constants related to fee tokens and added new test case for v3 transactions.
crates/katana/storage/provider/src/test_utils.rs Replaced create_genesis_for_testing with create_chain_for_testing returning ChainSpec.

Assessment against linked issues

Objective Addressed Explanation
Add support for paying fee using STRK (#2405) The changes do not implement the configuration flag to switch between STRK and ETH as fee-paying tokens.

Possibly related issues

Possibly related PRs

Suggested labels

sozo


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 547ad8b and 2e4f96d.

📒 Files selected for processing (18)
  • bin/katana/src/cli/node.rs (8 hunks)
  • crates/katana/core/src/backend/storage.rs (11 hunks)
  • crates/katana/executor/benches/utils.rs (3 hunks)
  • crates/katana/executor/src/implementation/blockifier/utils.rs (1 hunks)
  • crates/katana/executor/tests/executor.rs (2 hunks)
  • crates/katana/executor/tests/fixtures/mod.rs (4 hunks)
  • crates/katana/executor/tests/fixtures/transaction.rs (5 hunks)
  • crates/katana/node/src/lib.rs (3 hunks)
  • crates/katana/primitives/src/block.rs (1 hunks)
  • crates/katana/primitives/src/chain_spec.rs (1 hunks)
  • crates/katana/primitives/src/genesis/constant.rs (2 hunks)
  • crates/katana/primitives/src/genesis/json.rs (5 hunks)
  • crates/katana/primitives/src/genesis/mod.rs (5 hunks)
  • crates/katana/primitives/src/genesis/test-genesis-with-class.json (0 hunks)
  • crates/katana/primitives/src/genesis/test-genesis-with-duplicate-name.json (0 hunks)
  • crates/katana/primitives/src/genesis/test-genesis.json (0 hunks)
  • crates/katana/rpc/rpc/tests/starknet.rs (14 hunks)
  • crates/katana/storage/provider/src/test_utils.rs (4 hunks)
💤 Files with no reviewable changes (3)
  • crates/katana/primitives/src/genesis/test-genesis-with-class.json
  • crates/katana/primitives/src/genesis/test-genesis-with-duplicate-name.json
  • crates/katana/primitives/src/genesis/test-genesis.json
🧰 Additional context used
🪛 GitHub Check: codecov/patch
bin/katana/src/cli/node.rs

[warning] 236-236: bin/katana/src/cli/node.rs#L236
Added line #L236 was not covered by tests


[warning] 319-319: bin/katana/src/cli/node.rs#L319
Added line #L319 was not covered by tests


[warning] 335-335: bin/katana/src/cli/node.rs#L335
Added line #L335 was not covered by tests


[warning] 368-369: bin/katana/src/cli/node.rs#L368-L369
Added lines #L368 - L369 were not covered by tests


[warning] 399-399: bin/katana/src/cli/node.rs#L399
Added line #L399 was not covered by tests


[warning] 413-413: bin/katana/src/cli/node.rs#L413
Added line #L413 was not covered by tests


[warning] 416-429: bin/katana/src/cli/node.rs#L416-L429
Added lines #L416 - L429 were not covered by tests


[warning] 432-438: bin/katana/src/cli/node.rs#L432-L438
Added lines #L432 - L438 were not covered by tests


[warning] 443-444: bin/katana/src/cli/node.rs#L443-L444
Added lines #L443 - L444 were not covered by tests

crates/katana/node/src/lib.rs

[warning] 228-228: crates/katana/node/src/lib.rs#L228
Added line #L228 was not covered by tests


[warning] 241-241: crates/katana/node/src/lib.rs#L241
Added line #L241 was not covered by tests

crates/katana/primitives/src/chain_spec.rs

[warning] 365-365: crates/katana/primitives/src/chain_spec.rs#L365
Added line #L365 was not covered by tests


[warning] 370-370: crates/katana/primitives/src/chain_spec.rs#L370
Added line #L370 was not covered by tests


[warning] 373-375: crates/katana/primitives/src/chain_spec.rs#L373-L375
Added lines #L373 - L375 were not covered by tests


[warning] 378-380: crates/katana/primitives/src/chain_spec.rs#L378-L380
Added lines #L378 - L380 were not covered by tests


[warning] 390-390: crates/katana/primitives/src/chain_spec.rs#L390
Added line #L390 was not covered by tests


[warning] 396-396: crates/katana/primitives/src/chain_spec.rs#L396
Added line #L396 was not covered by tests


[warning] 403-403: crates/katana/primitives/src/chain_spec.rs#L403
Added line #L403 was not covered by tests


[warning] 412-412: crates/katana/primitives/src/chain_spec.rs#L412
Added line #L412 was not covered by tests


[warning] 420-420: crates/katana/primitives/src/chain_spec.rs#L420
Added line #L420 was not covered by tests


[warning] 426-426: crates/katana/primitives/src/chain_spec.rs#L426
Added line #L426 was not covered by tests


[warning] 432-432: crates/katana/primitives/src/chain_spec.rs#L432
Added line #L432 was not covered by tests


[warning] 439-439: crates/katana/primitives/src/chain_spec.rs#L439
Added line #L439 was not covered by tests


[warning] 445-445: crates/katana/primitives/src/chain_spec.rs#L445
Added line #L445 was not covered by tests


[warning] 451-451: crates/katana/primitives/src/chain_spec.rs#L451
Added line #L451 was not covered by tests


[warning] 460-460: crates/katana/primitives/src/chain_spec.rs#L460
Added line #L460 was not covered by tests


[warning] 466-466: crates/katana/primitives/src/chain_spec.rs#L466
Added line #L466 was not covered by tests


[warning] 474-474: crates/katana/primitives/src/chain_spec.rs#L474
Added line #L474 was not covered by tests


[warning] 480-480: crates/katana/primitives/src/chain_spec.rs#L480
Added line #L480 was not covered by tests


[warning] 486-486: crates/katana/primitives/src/chain_spec.rs#L486
Added line #L486 was not covered by tests

🔇 Additional comments (24)
crates/katana/executor/benches/utils.rs (1)

3-3: Ohayo, sensei! LGTM on this import change!

The update to import DEFAULT_ETH_FEE_TOKEN_ADDRESS instead of DEFAULT_FEE_TOKEN_ADDRESS aligns perfectly with our mission to support STRK as a fee token. This change brings more clarity to our code by specifying that this constant is specifically for ETH.

crates/katana/executor/tests/fixtures/transaction.rs (2)

2-2: Ohayo, sensei! LGTM on the import and constant changes!

The addition of ChainSpec import and the renaming of the fee token constant to DEFAULT_ETH_FEE_TOKEN_ADDRESS align well with the PR objectives. These changes lay the groundwork for supporting multiple fee-paying tokens, including STRK.

Also applies to: 6-6


Line range hint 1-138: Ohayo for the last time, sensei! Overall, these changes are sugoi (amazing)!

The modifications to this file successfully lay the groundwork for supporting multiple fee-paying tokens, including STRK, as outlined in the PR objectives. The shift from Genesis to ChainSpec provides more flexibility and aligns well with the goal of configurable fee tokens.

Key points:

  1. Consistent use of ChainSpec across functions.
  2. Renaming of constants for clarity.
  3. Maintained backwards compatibility with ETH as the default fee token.

These changes set a solid foundation for implementing the --fee-paying-token flag in future iterations.

crates/katana/primitives/src/block.rs (2)

Line range hint 103-108: Ohayo again, sensei! The Block implementation is looking sharp!

The addition of the seal_with_hash_and_status method to the Block struct is a great complement to the new SealedBlockWithStatus struct. It provides a clean and consistent way to create a sealed block with its status, aligning well with the existing sealing methods.

This implementation maintains the API consistency and enhances the functionality to support the new finality status feature. Good job!


Line range hint 1-175: Ohayo one last time, sensei! Overall, this file is looking stellar!

The changes introduced in this file are focused, minimal, and well-integrated with the existing code structure. The new SealedBlockWithStatus struct and the corresponding method in the Block implementation enhance the block handling capabilities, aligning perfectly with the PR objectives.

Great job on maintaining code consistency and expanding functionality without disrupting the existing structure. The changes provide a solid foundation for handling blocks with finality status, which will be crucial for supporting the STRK fee token as outlined in the PR objectives.

crates/katana/primitives/src/genesis/constant.rs (3)

15-18: Ohayo, sensei! Nice clarification on the ETH fee token constant.

The renaming of DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS enhances clarity and aligns well with the PR objective of supporting multiple fee tokens. This change maintains backward compatibility while improving code readability.


113-113: Ohayo, sensei! Interesting change in function visibility.

The get_fee_token_balance_base_storage_address function is now public, which could be beneficial for the new multi-token fee system. However, it would be helpful to understand the specific use cases that necessitated this change.

Could you please clarify why this function needs to be public now? Are there new components in the system that require access to this functionality?


Line range hint 1-141: Ohayo one last time, sensei! Overall, these changes are well-crafted and purposeful.

The modifications in this file effectively support the introduction of STRK as a fee token while maintaining backward compatibility with ETH. The constant renaming and addition improve code clarity, and the increased visibility of the utility function seems to accommodate the new multi-token fee system.

These changes align perfectly with the PR objectives and maintain the existing code style and quality. Great work on enhancing Katana's flexibility!

crates/katana/executor/tests/fixtures/mod.rs (4)

10-10: Ohayo, sensei! LGTM on this import change.

The addition of ChainSpec import aligns perfectly with our mission to make Katana more flexible with fee tokens. It's a small change, but it's laying the groundwork for our grand fee token revolution!


70-71: Ohayo once more, sensei! The state_provider() function is now a ChainSpec master!

This function has leveled up from Genesis to ChainSpec, showing it's ready to handle our new fee token regime. It's like watching a student become the sensei!

Let's make sure our state updates are as enlightened as our function:

#!/bin/bash
# Description: Check if state updates include fee token information

rg --type rust -A 5 'fn state_updates'

If we don't see fee token updates in there, we might need to add them to ensure our STRK support is complete, sensei!


16-18: Ohayo again, sensei! This constant change is on point!

The switch to DEFAULT_ETH_FEE_TOKEN_ADDRESS is spot-on for our STRK support mission. It's like we're giving ETH its own special badge in our code dojo!

Just to be thorough, let's make sure we have a similar constant for STRK:

If this doesn't yield results, we might want to consider adding a DEFAULT_STRK_FEE_TOKEN_ADDRESS constant for consistency, sensei!

✅ Verification successful

Ohayo again, sensei!

Great news—DEFAULT_STRK_FEE_TOKEN_ADDRESS is already in place throughout our codebase. This means our STRK support is solid and aligned with the recent constant import changes. Keep up the fantastic work!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the existence of a STRK fee token address constant

rg --type rust 'DEFAULT_STRK_FEE_TOKEN_ADDRESS'

Length of output: 1017


51-52: Ohayo, sensei! This chain() function is evolving beautifully!

The metamorphosis from genesis() to chain() is like watching a caterpillar turn into a butterfly - it's still recognizable, but now it can soar with ChainSpec! This change gives us the flexibility we need for our fee token adventures.

Let's make sure our ChainSpec butterfly has all the right colors:

If we don't see fee token fields in there, we might need to add them to fully support our STRK dreams, sensei!

Also applies to: 64-65

crates/katana/node/src/lib.rs (1)

176-177: Ohayo, sensei! LGTM: Fee token addresses update

The changes to the FeeTokenAddressses struct initialization look good. They align perfectly with our objective to support STRK as a fee token, providing more flexibility in configuring fee tokens. Nice work on implementing this crucial part of the feature!

crates/katana/executor/tests/executor.rs (1)

309-309: Ohayo, sensei! LGTM: Constant renamed to reflect ETH specificity.

The change from DEFAULT_FEE_TOKEN_ADDRESS to DEFAULT_ETH_FEE_TOKEN_ADDRESS aligns perfectly with our mission to support STRK as a fee token. This subtle yet crucial update ensures our tests remain accurate and relevant to the new multi-token fee system. Domo arigato for your attention to detail!

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

6-6: Ohayo sensei! Importing ChainSpec looks good

The addition of use katana_primitives::chain_spec::ChainSpec; is appropriate and necessary for the new ChainSpec usage.

crates/katana/primitives/src/genesis/mod.rs (2)

38-45: Manual Debug implementation is appropriate.

Ohayo, sensei! The custom Debug implementation for GenesisClass effectively elides the casm and sierra fields by displaying "...". This is a suitable approach to prevent potentially large or sensitive data from cluttering debug outputs.


Line range hint 109-127: Updates to Genesis default implementation align with PR objectives.

Ohayo, sensei! The modifications within the Genesis::default() method correctly remove the fee_token and universal_deployer configurations. The inclusion of the DEFAULT_LEGACY_ERC20 and DEFAULT_LEGACY_UDC classes directly into the classes map streamlines the genesis block initialization, aligning with the goal to support STRK as the fee token.

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

298-300: Ohayo, sensei! Ensure database re-initialization respects fee token configuration.

When re-opening the database, the blockchain is initialized with &chain_spec::DEV. If the fee-paying token has been changed, confirm that the ChainSpec used reflects the correct fee token to maintain consistency in the blockchain state.

It's important to verify that the fee token configuration persists across database re-initializations.

bin/katana/src/cli/node.rs (2)

155-155: Ohayo, sensei! Great use of default_value_t for default arguments.

Switching to #[arg(default_value_t = 10)] improves performance by eliminating the need to parse a string at runtime. This is a cleaner and more efficient approach.


312-338: Ohayo, sensei! Refactored chain_spec logic looks solid.

The restructuring of chain_spec initialization enhances readability and flexibility. Handling of chain_id and genesis options is clear and concise.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 319-319: bin/katana/src/cli/node.rs#L319
Added line #L319 was not covered by tests


[warning] 335-335: bin/katana/src/cli/node.rs#L335
Added line #L335 was not covered by tests

crates/katana/primitives/src/chain_spec.rs (2)

35-47: Ohayo, sensei! The FeeContracts struct addition enhances flexibility.

The introduction of the FeeContracts struct effectively encapsulates fee token addresses for both ETH and STRK. This aligns well with the PR objectives to support multiple fee tokens and improves the configurability of the chain specifications.


236-661: Verify test coverage for the updated test module.

The static analysis hints indicate that some added lines in the test module are not covered by tests. Please ensure all new code in the tests is being executed and that coverage is complete.

You can confirm test coverage by running:

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 365-365: crates/katana/primitives/src/chain_spec.rs#L365
Added line #L365 was not covered by tests


[warning] 370-370: crates/katana/primitives/src/chain_spec.rs#L370
Added line #L370 was not covered by tests


[warning] 373-375: crates/katana/primitives/src/chain_spec.rs#L373-L375
Added lines #L373 - L375 were not covered by tests


[warning] 378-380: crates/katana/primitives/src/chain_spec.rs#L378-L380
Added lines #L378 - L380 were not covered by tests


[warning] 390-390: crates/katana/primitives/src/chain_spec.rs#L390
Added line #L390 was not covered by tests


[warning] 396-396: crates/katana/primitives/src/chain_spec.rs#L396
Added line #L396 was not covered by tests


[warning] 403-403: crates/katana/primitives/src/chain_spec.rs#L403
Added line #L403 was not covered by tests


[warning] 412-412: crates/katana/primitives/src/chain_spec.rs#L412
Added line #L412 was not covered by tests


[warning] 420-420: crates/katana/primitives/src/chain_spec.rs#L420
Added line #L420 was not covered by tests


[warning] 426-426: crates/katana/primitives/src/chain_spec.rs#L426
Added line #L426 was not covered by tests


[warning] 432-432: crates/katana/primitives/src/chain_spec.rs#L432
Added line #L432 was not covered by tests


[warning] 439-439: crates/katana/primitives/src/chain_spec.rs#L439
Added line #L439 was not covered by tests


[warning] 445-445: crates/katana/primitives/src/chain_spec.rs#L445
Added line #L445 was not covered by tests


[warning] 451-451: crates/katana/primitives/src/chain_spec.rs#L451
Added line #L451 was not covered by tests


[warning] 460-460: crates/katana/primitives/src/chain_spec.rs#L460
Added line #L460 was not covered by tests


[warning] 466-466: crates/katana/primitives/src/chain_spec.rs#L466
Added line #L466 was not covered by tests


[warning] 474-474: crates/katana/primitives/src/chain_spec.rs#L474
Added line #L474 was not covered by tests


[warning] 480-480: crates/katana/primitives/src/chain_spec.rs#L480
Added line #L480 was not covered by tests


[warning] 486-486: crates/katana/primitives/src/chain_spec.rs#L486
Added line #L486 was not covered by tests

crates/katana/rpc/rpc/tests/starknet.rs (2)

897-927: New test v3_transactions successfully validates STRK fee token usage

Ohayo, sensei! The added test function v3_transactions correctly tests v3 transactions using the STRK fee token. This ensures compatibility with Starknet's updated transaction model. Excellent work aligning the tests with the latest protocol changes.


17-18: Ohayo, sensei!

Ensure consistent usage of fee token constants

The addition of DEFAULT_STRK_FEE_TOKEN_ADDRESS is appropriate for supporting STRK as a fee token. Please verify that all instances where the fee token address is utilized are updated to reference the correct constant based on the configured fee-paying token.

Here's a script to identify usages of DEFAULT_ETH_FEE_TOKEN_ADDRESS that may need to be updated:


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

Actionable comments posted: 13

🧹 Outside diff range and nitpick comments (19)
crates/katana/executor/benches/utils.rs (1)

12-12: Ohayo again, sensei! This change looks good, but let's think ahead!

The update to use DEFAULT_ETH_FEE_TOKEN_ADDRESS in the calldata vector is spot on. It's consistent with our import changes and ensures we're using the correct ETH fee token address.

However, to make our code more flexible for future updates, we might want to consider using a configurable fee token address here. This could allow for easier switching between ETH and STRK in our benchmarks.

What do you think about introducing a parameter to the tx() function that allows specifying the fee token address? This could make our benchmarks more versatile. Here's a quick example:

pub fn tx(fee_token_address: Felt) -> ExecutableTxWithHash {
    let invoke = InvokeTx::V1(InvokeTxV1 {
        sender_address: felt!("0x1").into(),
        calldata: vec![
            fee_token_address.into(),
            // ... rest of the calldata
        ],
        // ... rest of the struct
    });
    // ... rest of the function
}

This way, we could easily benchmark with different fee tokens. What do you think, sensei?

crates/katana/executor/tests/fixtures/transaction.rs (3)

46-46: Ohayo again, sensei! The invoke_executable_tx function looks good!

The update to use DEFAULT_ETH_FEE_TOKEN_ADDRESS is consistent with the earlier changes. It maintains the current behavior while paving the way for future enhancements.

For future iterations, consider parameterizing the fee token address to allow for easy switching between ETH and STRK based on user configuration.


101-102: Ohayo once more, sensei! The executable_tx function changes look solid!

The update to use ChainSpec instead of Genesis aligns perfectly with the PR objectives. It provides more flexibility for future enhancements related to fee token configuration.

Consider adding a comment explaining the relationship between ChainSpec and Genesis for future maintainers.


122-125: Ohayo yet again, sensei! The executable_tx_without_max_fee function changes are on point!

The updates here mirror those in the executable_tx function, maintaining consistency across the codebase. Great job!

Consider extracting the common logic for accessing allocations from ChainSpec into a helper function to reduce code duplication between executable_tx and executable_tx_without_max_fee.

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

Line range hint 169-175: Ohayo, sensei! The new struct looks good, but let's add a bit more flavor to the docs!

The SealedBlockWithStatus struct is a great addition and aligns well with the PR objectives. It nicely encapsulates a sealed block along with its finality status.

Consider expanding the documentation comment to provide more context. Here's a suggestion:

- /// Block whose commitment has been computed.
+ /// Represents a sealed block along with its finality status.
+ /// This struct is used to track blocks that have been processed and sealed,
+ /// providing information about their acceptance status on L1 or L2.

This additional context helps developers understand the purpose and usage of the struct more clearly.

crates/katana/primitives/src/genesis/constant.rs (1)

20-24: Ohayo again, sensei! Excellent addition of the STRK fee token constant.

The new DEFAULT_STRK_FEE_TOKEN_ADDRESS constant perfectly aligns with the PR objective of supporting STRK as a fee token. The formatting and style are consistent with the existing codebase.

Consider adding a brief comment explaining the significance of STRK in the context of Starknet's recent transaction updates. This could help future developers understand the rationale behind this addition.

crates/katana/executor/tests/fixtures/mod.rs (1)

226-229: Ohayo for the last time, sensei! The cfg() function is now fee-token-aware!

The switch to DEFAULT_ETH_FEE_TOKEN_ADDRESS shows we're on the right path to fee token enlightenment. It's like upgrading from a abacus to a calculator!

However, I noticed we're still using a hardcoded value for the STRK address. Perhaps we should consider using a constant for this as well? Something like:

 let fee_token_addresses = FeeTokenAddressses {
     eth: DEFAULT_ETH_FEE_TOKEN_ADDRESS,
-    strk: ContractAddress(222u64.into()),
+    strk: DEFAULT_STRK_FEE_TOKEN_ADDRESS,
 };

This would make our code more consistent and easier to maintain, sensei. What do you think?

crates/katana/node/src/lib.rs (1)

243-243: Ohayo, sensei! LGTM with a refactor suggestion

The update to Blockchain::new_with_genesis looks good and is consistent with the changes made to new_with_db. It's great to see the broader &config.chain being used here as well.

To reduce duplication and improve maintainability, we could consider extracting the common &config.chain parameter into a separate variable or method. What do you think about this refactor suggestion, sensei?

Here's a possible refactor:

let chain_config = &config.chain;
// ... other code ...
match (...) {
    // ... other cases ...
    _ => (Blockchain::new_with_genesis(InMemoryProvider::new(), chain_config)?, None)
}
crates/katana/executor/tests/executor.rs (1)

Line range hint 1-341: Ohayo again, sensei! A word on the big picture.

The change we've seen is small but significant. While our tests look solid for the current setup, we might want to consider expanding them in the future to cover scenarios with STRK as the fee token. This could involve:

  1. Adding test cases that use STRK for fee payments.
  2. Verifying that the executor correctly handles both ETH and STRK fee scenarios.
  3. Ensuring that the cfg_env.fee_token_addresses is correctly populated and used throughout the tests.

What do you think, sensei? Shall we open an issue to track these potential enhancements?

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

Line range hint 52-81: Ohayo sensei! Consider implementing a genesis builder

To enhance maintainability and readability, consider using a genesis builder to construct the ChainSpec more elegantly, as mentioned in the TODO comment. This will make the code more modular and easier to extend in the future.

Would you like assistance in creating a genesis builder or should I open a GitHub issue to track this task?

crates/katana/primitives/src/genesis/mod.rs (1)

118-118: Typo in comment: 'depoyer' should be 'deployer'.

Ohayo, sensei! There's a minor typo in the comment at line 118. It should read "universal deployer contract class" instead of "universal depoyer contract class".

crates/katana/core/src/backend/storage.rs (3)

173-175: Ohayo, sensei! Add test cases for STRK fee token.

In the blockchain_from_genesis_states test, the state check uses DEFAULT_ETH_FEE_TOKEN_ADDRESS. To fully validate the new feature, consider adding test cases where the fee token is STRK.

Would you like assistance in writing additional tests to cover the STRK fee token scenario?


194-196: Ohayo, sensei! Clone and modify ChainSpec carefully.

In lines 194-196, you clone chain_spec::DEV and modify its genesis. Ensure that this does not unintentionally affect other tests or parts of the code that rely on chain_spec::DEV.

Consider creating a new ChainSpec instance or using a testing utility to prevent side effects.


284-286: Ohayo, sensei! Fix potential typo in test assertion.

In the test, the class comparison uses DEFAULT_LEGACY_ERC20_CASM.clone(). Verify that clone() is necessary here and that it doesn't affect the assertion outcome.

If DEFAULT_LEGACY_ERC20_CASM is already a clone or a value type, the clone() method might be redundant.

bin/katana/src/cli/node.rs (3)

236-236: Ohayo, sensei! Consider adding tests for print_intro.

The call to print_intro is crucial for displaying startup information. Adding tests can help ensure that the introduction outputs as expected, enhancing reliability.

Would you like assistance in creating unit tests for this function?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 236-236: bin/katana/src/cli/node.rs#L236
Added line #L236 was not covered by tests


368-369: Ohayo, sensei! Adding tests for account display would be beneficial.

The print_intro function now processes account information. Including tests will help ensure account details are correctly presented to users.

Would you like help in drafting tests for displaying account information?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 368-369: bin/katana/src/cli/node.rs#L368-L369
Added lines #L368 - L369 were not covered by tests


399-399: Ohayo, sensei! Ensure print_genesis_contracts is tested.

The function print_genesis_contracts outputs important contract information. Adding tests can help maintain correctness as the codebase evolves.

Can I assist in creating tests for this function?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 399-399: bin/katana/src/cli/node.rs#L399
Added line #L399 was not covered by tests

crates/katana/primitives/src/chain_spec.rs (2)

50-61: Consider adding unit tests for the new block method.

The block method provides a crucial function to generate the genesis block. To ensure its reliability, please consider adding unit tests that verify its correctness.

Would you like assistance in creating unit tests for this method, sensei?


64-131: Ensure thorough testing of the state_updates method.

The state_updates method is essential for initializing state updates with declared classes and deployed contracts. Adding comprehensive unit tests will enhance the robustness of this method and ensure the chain state is correctly established.

I'm happy to help draft test cases for this method if you'd like, sensei.

🛑 Comments failed to post (13)
crates/katana/executor/benches/utils.rs (1)

37-38: 💡 Codebase verification

⚠️ Potential issue

Update STRK Fee Token Address

Ohayo, sensei!

I noticed that DEFAULT_STRK_FEE_TOKEN_ADDRESS is defined in crates/katana/primitives/src/genesis/constant.rs. Currently, both eth and strk in fee_token_addresses are set to DEFAULT_ETH_FEE_TOKEN_ADDRESS. It would be best to update the strk field to use DEFAULT_STRK_FEE_TOKEN_ADDRESS instead:

fee_token_addresses: FeeTokenAddresses {
    eth: DEFAULT_ETH_FEE_TOKEN_ADDRESS,
    strk: DEFAULT_STRK_FEE_TOKEN_ADDRESS,
},

This ensures that STRK is correctly associated with its designated fee token address.

🔗 Analysis chain

Ohayo, sensei! We might have a small hiccup here.

I noticed that both eth and strk fields in the fee_token_addresses are set to DEFAULT_ETH_FEE_TOKEN_ADDRESS. This seems a bit odd, considering our noble quest to support STRK as a separate fee token.

Is this intentional for testing purposes, or should we be using a different address for strk? If it's intentional, perhaps we could add a comment explaining why both are set to the ETH address for now.

If it's not intentional, we might want to introduce a separate constant for the STRK fee token address. Something like this:

fee_token_addresses: FeeTokenAddressses {
    eth: DEFAULT_ETH_FEE_TOKEN_ADDRESS,
    strk: DEFAULT_STRK_FEE_TOKEN_ADDRESS,
},

What are your thoughts on this, sensei? Should we keep it as is or make a change here?

To double-check if we have a DEFAULT_STRK_FEE_TOKEN_ADDRESS constant defined elsewhere, we can run:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for DEFAULT_STRK_FEE_TOKEN_ADDRESS constant
rg --type rust "const DEFAULT_STRK_FEE_TOKEN_ADDRESS"

Length of output: 164

crates/katana/node/src/lib.rs (1)

241-241: 💡 Codebase verification

Ohayo, sensei!

It looks like there are no existing tests for Blockchain::new_with_db. To ensure the new configuration changes are properly validated, could you please add appropriate test coverage for this method?

🔗 Analysis chain

Ohayo, sensei! LGTM with a small suggestion

The update to Blockchain::new_with_db looks good, using the broader &config.chain instead of just the genesis configuration. This change aligns well with our new flexible fee token setup.

However, our codecov sensei noticed that this line isn't covered by tests yet. Would you mind adding some test coverage for this change to ensure it behaves as expected?


Ohayo, sensei! Let me check for any tests related to Blockchain::new_with_db elsewhere in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for existing tests related to Blockchain::new_with_db
rg --type rust "new_with_db.*config\.chain" crates/katana/node/src/tests

Length of output: 143


Script:

#!/bin/bash
# Search for tests related to Blockchain::new_with_db across the codebase
rg --type rust "new_with_db.*config\.chain"

Length of output: 147

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 241-241: crates/katana/node/src/lib.rs#L241
Added line #L241 was not covered by tests

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

37-42: 💡 Codebase verification

Ohayo sensei!

Several remaining references to genesis were found outside the expected locations. Please update these to chain to ensure consistency and prevent potential issues:

  • crates/saya/core/src/lib.rs
  • crates/katana/node-bindings/src/lib.rs
  • crates/katana/executor/tests/fixtures/mod.rs
  • crates/katana/storage/provider/src/traits/block.rs
  • crates/katana/controller/src/lib.rs
🔗 Analysis chain

Ohayo sensei! Verify all references to genesis are updated to chain

In updating to use ChainSpec, please ensure that all references to genesis have been replaced with chain to prevent any potential issues.

You can run the following script to check for any remaining references to genesis outside of expected locations:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find any remaining usages of 'genesis' in the codebase, excluding definitions and the genesis module.

# Test: Search for 'genesis' in Rust files, excluding the genesis module and test utilities.
rg --type rust --word-regexp '\bgenesis\b' --glob '!*genesis*' --glob '!**/genesis/**' --glob '!**/test_utils.rs'

Length of output: 12408

crates/katana/core/src/backend/storage.rs (3)

142-145: 🛠️ Refactor suggestion

Ohayo, sensei! Parameterize fee token address constants in tests.

The test uses DEFAULT_ETH_FEE_TOKEN_ADDRESS, but since the fee-paying token is now configurable (either ETH or STRK), it would be beneficial to parameterize the fee token address to reflect this change.

Consider introducing a variable or a test parameter that allows the tests to run with both fee token addresses. This enhances test coverage for different configurations.


284-287: ⚠️ Potential issue

Ohayo, sensei! Update class hash checks for configurable fee tokens.

The test verifies the actual_fee_token_class_hash against DEFAULT_LEGACY_ERC20_CLASS_HASH, which corresponds to ETH. With the introduction of STRK as a fee token, the test should account for the correct class hash based on the selected fee token.

Consider modifying the test to check the class hash dynamically, depending on the configured fee token. This ensures that the test remains valid regardless of the fee token used.


71-78: ⚠️ Potential issue

Ohayo, sensei! Update error message to reflect ChainSpec.

In the new_with_genesis function, the error message on line 78 still refers to "Genesis block hash mismatch". Since we are now using ChainSpec, consider updating the error message for clarity.

Apply this diff to update the error message:

-                        Err(anyhow!(
-                            "Genesis block hash mismatch: expected {genesis_hash:#x}, got {db_hash:#}",
-                        ))
+                        Err(anyhow!(
+                            "Block hash mismatch in ChainSpec: expected {genesis_hash:#x}, got {db_hash:#x}",
+                        ))

Committable suggestion was skipped due to low confidence.

bin/katana/src/cli/node.rs (2)

413-444: 🛠️ Refactor suggestion

Ohayo, sensei! Dynamic display of fee tokens could enhance UX.

Currently, both ETH and STRK fee tokens are displayed regardless of the user's selection. Consider adjusting print_genesis_contracts to show only the fee token in use, making the output more relevant.

You might implement a check based on the configured fee token and conditionally display the corresponding information.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 413-413: bin/katana/src/cli/node.rs#L413
Added line #L413 was not covered by tests


[warning] 416-429: bin/katana/src/cli/node.rs#L416-L429
Added lines #L416 - L429 were not covered by tests


[warning] 432-438: bin/katana/src/cli/node.rs#L432-L438
Added lines #L432 - L438 were not covered by tests


[warning] 443-444: bin/katana/src/cli/node.rs#L443-L444
Added lines #L443 - L444 were not covered by tests


185-185: 💡 Codebase verification

Ohayo, sensei! 🌸 It seems there are instances where chain_id is used without handling the None case. Please review the following locations to ensure proper None handling:

  • crates/saya/provider/src/rpc/mod.rs:

    • .map(|tx_rpc| tx_converter::tx_from_rpc(tx_rpc, self.chain_id))
  • crates/katana/executor/src/implementation/blockifier/utils.rs:

    • let chain_info = ChainInfo { fee_token_addresses, chain_id: to_blk_chain_id(cfg_env.chain_id) };
  • bin/saya/src/args/mod.rs:

    • chain_id: cairo_short_string_to_felt(&args.starknet_account.chain_id)?
🔗 Analysis chain

Ohayo, sensei! Ensure proper handling of optional chain_id.

By changing pub chain_id: ChainId to pub chain_id: Option<ChainId>, you've made the chain_id optional. Please verify that all usages of chain_id handle the None case appropriately to prevent potential None dereferencing issues.

You can run the following script to check for unhandled None cases:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for instances where `chain_id` is used without checking for `None`

rg --type rust "(\.chain_id\s*;|\.\s*chain_id\s*\))" --context 2

Length of output: 1928

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

162-209: ⚠️ Potential issue

Handle potential errors in add_fee_token function gracefully.

In the add_fee_token function, the use of .unwrap() on cairo_short_string_to_felt could lead to a panic if the conversion fails. Although the inputs are hardcoded and unlikely to fail, it's good practice to handle potential errors to improve reliability.

Consider modifying the code to handle errors without panicking:

-let name = cairo_short_string_to_felt(name).unwrap();
-let symbol = cairo_short_string_to_felt(symbol).unwrap();
+let name = cairo_short_string_to_felt(name)?;
+let symbol = cairo_short_string_to_felt(symbol)?;

This change will require updating the function signature to return a Result.

Committable suggestion was skipped due to low confidence.

crates/katana/executor/src/implementation/blockifier/utils.rs (1)

216-217: ⚠️ Potential issue

Ohayo, sensei! Consider replacing println! with a logging mechanism

Using println! may not be ideal for production code as it writes directly to standard output. It's better to use a logging library to control log levels and outputs effectively.

Apply this diff to replace println! with a logging statement:

- println!("creating invoke transaction v3...");
+ log::debug!("creating invoke transaction v3...");

Ensure that the appropriate logging crate (e.g., log or tracing) is included and properly configured.

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

                log::debug!("creating invoke transaction v3...");
crates/katana/rpc/rpc/tests/starknet.rs (1)

174-174: 🛠️ Refactor suggestion

Parameterize the fee token address in test contracts

Ohayo, sensei! Multiple test cases are initializing Erc20Contract and FeeToken instances with DEFAULT_ETH_FEE_TOKEN_ADDRESS. To fully support testing with both ETH and STRK fee tokens, consider parameterizing the fee token address based on the configuration.

Refactor the code to use the configured fee token address:

-let contract = Erc20Contract::new(DEFAULT_ETH_FEE_TOKEN_ADDRESS.into(), &account);
+let fee_token_address = if use_strk_fee_token {
+    DEFAULT_STRK_FEE_TOKEN_ADDRESS
+} else {
+    DEFAULT_ETH_FEE_TOKEN_ADDRESS
+};
+let contract = Erc20Contract::new(fee_token_address.into(), &account);

Ensure that use_strk_fee_token reflects the actual configuration used in the tests.

Also applies to: 248-248, 313-313, 367-367, 398-398, 477-477, 523-523, 594-594, 680-680, 768-768, 818-818

crates/katana/primitives/src/genesis/json.rs (2)

236-237: ⚠️ Potential issue

Remove commented-out code for a cleaner codebase

Ohayo, sensei! The fee_token and universal_deployer fields in the GenesisJson struct are commented out on lines 236-237. It's best to remove unused code instead of commenting it out to maintain code cleanliness and readability.

Apply this diff to remove the commented-out code:

-        // pub fee_token: FeeTokenConfigJson,
-        // pub universal_deployer: Option<UniversalDeployerConfigJson>,
📝 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.



845-845: ⚠️ Potential issue

Eliminate commented-out line to maintain clarity

Ohayo, sensei! The fee_token field is commented out on line 845. Removing it entirely would help keep the codebase clean and avoid confusion.

Apply this diff to remove the unnecessary line:

-                // fee_token: expected_fee_token,
📝 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.


Base automatically changed from katana/state-updates-at-chainspec to main October 15, 2024 18:09
An error occurred while trying to automatically change base from katana/state-updates-at-chainspec to main October 15, 2024 18:09
@kariy kariy merged commit 542df4f into main Oct 15, 2024
15 checks passed
@kariy kariy deleted the katana/strk-fee-token branch October 15, 2024 18:41
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2e4f96d and 7eae009.

📒 Files selected for processing (1)
  • crates/katana/primitives/src/chain_spec.rs (9 hunks)
🧰 Additional context used
🔇 Additional comments (4)
crates/katana/primitives/src/chain_spec.rs (4)

590-592: Handle Potential Errors Instead of Using .unwrap()

Ohayo, sensei! As previously mentioned, using .unwrap() with cairo_short_string_to_felt can cause a panic if the conversion fails. Consider handling the potential errors gracefully to enhance robustness.


630-632: Ensure Consistent Balance Checks for STRK Fee Token

Ohayo, sensei! Great job adding balance checks for the STRK fee token. Please ensure that all allocations with balances are correctly accounted for in both ETH and STRK to maintain consistency across fee tokens.


651-661: Verify Total Supply Calculation for STRK Fee Token

Ohayo, sensei! Please verify that the total supply for the STRK fee token is accurately calculated from the allocation balances, just as it is for ETH. This ensures that the STRK fee token reflects the correct total supply based on initial allocations.

To confirm the total supply calculation, you can run the following script:

#!/bin/bash
# Description: Verify that the total supply of STRK is calculated correctly from allocations.

# Expected: The total supply should match the sum of all allocation balances.

# Calculate total allocated STRK balance
alloc_total=$(rg 'balance: Some\((U256::from_str\("0x[0-9a-fA-F]+"\)\.unwrap\(\))\)' crates/katana/primitives/src/chain_spec.rs | sed -E 's/.*"0x([0-9a-fA-F]+)".*/0x\1/' | awk '{ sum += strtonum($1) } END { printf("%x\n", sum) }')

# Display total supply from STRK fee token storage
rg 'assert_eq!\(.*strk_fee_token_storage.*ERC20_TOTAL_SUPPLY_STORAGE_SLOT.*' -A 5 crates/katana/primitives/src/chain_spec.rs

echo "Calculated total allocated STRK balance: $alloc_total"

110-119: Verify Correct Class Hash for STRK Fee Token

Ohayo, sensei! Please verify that DEFAULT_LEGACY_ERC20_CLASS_HASH is the appropriate class hash for the STRK fee token. If STRK uses a different ERC20 contract class, you might need to update the class hash accordingly to ensure proper functionality.

To assist with verification, please run the following script:

✅ Verification successful

Verified: Correct Class Hash for STRK Fee Token

Ohayo, sensei! I've confirmed that DEFAULT_LEGACY_ERC20_CLASS_HASH is the appropriate class hash for the STRK fee token, as no separate class hash exists for STRK. Everything looks good!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there is a specific class hash defined for STRK fee token.

# Expected: Find if a separate class hash exists for STRK.

# Search for STRK-specific class hash definitions
rg 'DEFAULT_STRK.*CLASS_HASH' crates/katana/primitives/src/*

# Display the current value of DEFAULT_LEGACY_ERC20_CLASS_HASH
rg 'pub const DEFAULT_LEGACY_ERC20_CLASS_HASH' crates/katana/primitives/src/*

Length of output: 470

@@ -60,8 +60,7 @@
Block { header, body: Vec::new() }
}

// this method will include the the ETH fee token, and the UDC. Declaring and deploying the
// necessary classes and contracts.
// this method will include the the ETH and STRK fee tokens, and the UDC
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Typographical Error in Comment

Ohayo, sensei! There's a minor typo in the comment. The word "the" is duplicated. Please remove the extra "the" for clarity.

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.

Add support for paying fee using STRK
1 participant