Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(katana): estimate message insufficient fee error #2549

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 16, 2024

resolves #2546

Summary by CodeRabbit

  • New Features

    • Introduced a new variable for fee estimation in message processing.
    • Added a function to estimate message fees for L1 handlers.
    • Enhanced testing capabilities for StarkNet RPC functionalities.
  • Bug Fixes

    • Improved code standards by removing deprecated directives.
  • Tests

    • Implemented parameterized testing for various functionalities, ensuring comprehensive coverage.

@kariy kariy changed the title wip fix(katana): estimate message insufficient fee error Oct 16, 2024
Copy link

coderabbitai bot commented Oct 16, 2024

Walkthrough

Ohayo, sensei! This pull request introduces modifications to the MsgFromL1 struct in the message.rs file, specifically adjusting the initialization of the paid_fee_on_l1 variable and the calldata field. A new test function, estimate_message_fee, is added to assess the cost of L1 handler functions. Additionally, the starknet.rs file undergoes updates, including the removal of the deprecated directive and the implementation of parameterized testing for various functionalities.

Changes

File Path Change Summary
crates/katana/rpc/rpc-types/src/message.rs Modified MsgFromL1 struct: introduced paid_fee_on_l1 initialized to 1u128; adjusted calldata position. Updated comments for clarity.
crates/katana/rpc/rpc/tests/messaging.rs Added new test function estimate_message_fee to estimate L1 handler costs; updated imports.
crates/katana/rpc/rpc/tests/starknet.rs Removed #![allow(deprecated)]; enhanced tests with rstest macro; added functions for event retrieval.

Possibly related PRs

  • rm useless #[allow(deprecated)] #2519: The removal of the #[allow(deprecated)] directive in both PRs indicates a shared focus on improving code quality and standards, particularly in the context of fee estimation functionalities.

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

🧹 Outside diff range and nitpick comments (2)
crates/katana/rpc/rpc-types/src/message.rs (1)

16-20: Ohayo, sensei! LGTM with a small suggestion.

The addition of paid_fee_on_l1 and the accompanying comments are well-explained and address the specific requirement in the blockifier crate. Great job on providing context!

Consider adding a link to the relevant documentation or discussion about fee estimation to provide even more context for future developers.

crates/katana/rpc/rpc/tests/messaging.rs (1)

306-351: Ohayo, sensei! The new function looks promising, but let's make it even better!

The estimate_message_fee function is well-structured and covers the necessary steps to test the fee estimation. However, I have a few suggestions to enhance its effectiveness:

  1. Consider using the deployed contract address directly instead of computing it again.
  2. The assertion on line 348 only checks if the result is OK. It would be more valuable to assert something about the actual fee value, such as ensuring it's greater than zero or within an expected range.
  3. Think about adding some cleanup or tear-down of the test environment to ensure a clean state for subsequent tests.

Here's a suggested improvement for the assertion:

-    assert!(result.is_ok());
+    let fee = result.expect("Fee estimation failed");
+    assert!(fee.gas_price > 0, "Estimated gas price should be greater than zero");
+    assert!(fee.gas_consumed > 0, "Estimated gas consumed should be greater than zero");

What do you think about these suggestions, sensei? Would you like me to propose more detailed changes?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f9a559f and 9bf31c6.

📒 Files selected for processing (3)
  • crates/katana/rpc/rpc-types/src/message.rs (2 hunks)
  • crates/katana/rpc/rpc/tests/messaging.rs (3 hunks)
  • crates/katana/rpc/rpc/tests/starknet.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • crates/katana/rpc/rpc/tests/starknet.rs
🧰 Additional context used
🔇 Additional comments (3)
crates/katana/rpc/rpc-types/src/message.rs (2)

34-36: Ohayo again, sensei! This change looks good.

The repositioning of the calldata field in the struct initialization is a nice touch. It doesn't affect functionality but might improve readability by grouping related fields together.


Line range hint 1-41: Ohayo one last time, sensei! Overall, these changes look solid.

The modifications to the MsgFromL1 struct and its into_tx_with_chain_id method effectively address the requirements mentioned in the PR objectives. The addition of paid_fee_on_l1 and the repositioning of the calldata field are well-implemented and documented.

Great work on improving this part of the codebase!

crates/katana/rpc/rpc/tests/messaging.rs (1)

8-8: Ohayo, sensei! The import changes look good!

The new imports are necessary for the added functionality and there are no unused imports. Great job keeping the imports clean and relevant!

Also applies to: 15-15, 24-25

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.54%. Comparing base (f9a559f) to head (9bf31c6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2549      +/-   ##
==========================================
+ Coverage   69.44%   69.54%   +0.10%     
==========================================
  Files         388      388              
  Lines       49953    49959       +6     
==========================================
+ Hits        34688    34745      +57     
+ Misses      15265    15214      -51     

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

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.

[BUG] Issue with starknet_estimateMessageFee on Katana
1 participant