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): include msg sender in the tx calldata #2550

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 16, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced messaging functionality between L1 and L2 contracts.
    • Added a new section for estimating message fees in the messaging system.
  • Bug Fixes

    • Updated the construction of calldata to include the sender's Ethereum address.
  • Documentation

    • Improved comments in the test suite for better clarity on function signatures and parameters.

Copy link

coderabbitai bot commented Oct 16, 2024

Walkthrough

Ohayo, sensei! This pull request introduces modifications to the MsgFromL1 struct and its method into_tx_with_chain_id, enhancing the construction of the calldata vector to include the sender's Ethereum address. The L1HandlerTx struct has been updated to use this new calldata. Additionally, the messaging test suite has been improved with detailed comments and adjustments to function signatures and payload handling, ensuring clarity and flexibility in the messaging system between L1 and L2 contracts.

Changes

File Path Change Summary
crates/katana/rpc/rpc-types/src/message.rs Modified MsgFromL1 struct and into_tx_with_chain_id method to construct a new calldata vector. Updated L1HandlerTx to use this new vector.
crates/katana/rpc/rpc/tests/messaging.rs Enhanced test suite with comments, clarified msg_handler_value behavior, simplified estimate_message_fee payload, and created a new MsgFromL1 instance.

Possibly related PRs

  • fix(katana): estimate message insufficient fee error #2549: The changes in the MsgFromL1 struct and its method into_tx_with_chain_id are directly related, as both PRs modify the same method and struct, albeit with different internal logic adjustments. Additionally, both PRs enhance the testing functionality involving the MsgFromL1 structure.

🪧 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 (3)
crates/katana/rpc/rpc-types/src/message.rs (1)

30-33: Ohayo, sensei! LGTM with a small suggestion.

The changes look good and correctly implement the L1 handler transaction calldata structure. The added comment provides valuable context.

Consider renaming calldata to l1_handler_calldata for improved clarity:

-        let mut calldata = vec![Felt::from(self.0.from_address)];
-        calldata.extend(self.0.payload);
+        let mut l1_handler_calldata = vec![Felt::from(self.0.from_address)];
+        l1_handler_calldata.extend(self.0.payload);

This change would make it more explicit that we're dealing with L1 handler-specific calldata.

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

343-355: Ohayo, sensei! Your code is as sharp as a katana!

The changes to the estimate_message_fee test for msg_handler_value are well-implemented. The use of the MsgFromL1 struct provides a clear structure for the message data, and the test now correctly estimates the fee for the simplified message.

For even greater clarity, consider adding a brief comment explaining why payload only contains one value now:

-let payload = vec![felt!("123")];
+// Only one value in payload as `from_address` is automatically injected
+let payload = vec![felt!("123")];

Line range hint 357-380: Ohayo, sensei! Your code is evolving like a true ninja!

The addition of the test case for msg_handler_struct is an excellent improvement to the test coverage. It demonstrates how to handle structured payloads in L1 handler functions, which is a valuable scenario to test.

For consistency with the previous test case, consider adding a brief comment explaining the payload structure:

-// [ MyData.a , MyData.b ]
-let payload = vec![felt!("1"), felt!("2")];
+// Payload represents MyData struct: [MyData.a, MyData.b]
+let payload = vec![felt!("1"), felt!("2")];

This small change will make it even clearer for other developers reading the test.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fbef8a8 and e8ec0a7.

📒 Files selected for processing (2)
  • crates/katana/rpc/rpc-types/src/message.rs (1 hunks)
  • crates/katana/rpc/rpc/tests/messaging.rs (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
crates/katana/rpc/rpc-types/src/message.rs (1)

38-38: Ohayo again, sensei! This change looks solid.

The calldata field is correctly set to use the newly constructed vector that includes the sender's address.

To ensure consistency across the codebase, let's verify that all L1 handler transactions are using this updated structure:

This will help us confirm that the new calldata structure is consistently applied throughout the project.

✅ Verification successful

Ohayo again, sensei! This change passes verification.

The calldata field is consistently set to the newly constructed vector across all L1HandlerTx instances, ensuring it includes the sender's address as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for L1 handler transaction calldata construction

# Search for L1 handler transaction creation or processing
rg --type rust -e "L1HandlerTx" -e "l1_handler" -A 10 -B 5

Length of output: 75387

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

333-340: Ohayo, sensei! These comments are a treasure trove of wisdom!

The added comments provide excellent context for the msg_handler_value function, explaining the automatic injection of from_address and linking to the Starknet documentation. This clarity will be invaluable for future developers working with L1 handler functions.

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.55%. Comparing base (fbef8a8) to head (e8ec0a7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2550      +/-   ##
==========================================
- Coverage   69.55%   69.55%   -0.01%     
==========================================
  Files         388      388              
  Lines       49959    49964       +5     
==========================================
- Hits        34751    34750       -1     
- Misses      15208    15214       +6     

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

@kariy kariy merged commit 70ecca7 into main Oct 16, 2024
14 of 15 checks passed
@kariy kariy deleted the katana/fix-messaging-payload branch October 16, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant