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: change async_callback.id to number type #170

Merged
merged 2 commits into from
Dec 23, 2024
Merged

Conversation

ALPAC-4
Copy link
Contributor

@ALPAC-4 ALPAC-4 commented Dec 3, 2024

After change json marshal, u64 type changed from number to string. This cause failure of unmarshal async callback msg.

  • Change async_callback.id type to u32 on minitswap, ibc_transfer_test.

Summary by CodeRabbit

  • New Features

    • Introduced new structures IBCMemoV2, MemoMoveV2, and MemoAsyncCallbackV2 to enhance compatibility with JSON marshaling.
  • Improvements

    • Updated the id field type in callback structures from u64 to u32 for better type safety.
    • Enhanced timeout handling in the relay_packets function, factoring in both block height and timestamp.
  • Bug Fixes

    • Standardized the id format in test cases from string to numeric for consistency in IBC transfer tests.
  • Tests

    • Modified test cases to validate changes in the memo structure and ensure expected outcomes align with the new ID format.

@ALPAC-4 ALPAC-4 requested a review from a team as a code owner December 3, 2024 06:15
Copy link

coderabbitai bot commented Dec 3, 2024

Walkthrough

The pull request introduces modifications to several modules, primarily focusing on the handling of asynchronous callbacks and the associated types. The id field in the MoveAsyncCallback and MemoAsyncCallbackV2 structs has been changed from u64 to u32, impacting how callback identifiers are managed. Functions such as generate_ibc_message and relay_acks_timeouts have been updated to accommodate these changes. Additionally, test cases have been revised to reflect the new numeric format for IDs, ensuring consistency across IBC transfer scenarios.

Changes

File Path Change Summary
precompile/modules/initia_stdlib/sources/ibctesting/ibctesting.move - Updated MoveAsyncCallback struct: changed id field from u64 to u32.
- Modified relay_acks_timeouts function to cast id to u64.
- Enhanced timeout checks in relay_packets.
precompile/modules/initia_stdlib/sources/minitswap.move - Added new structs: IBCMemoV2, MemoMoveV2, MemoAsyncCallbackV2.
- Updated generate_ibc_message to use new memo structures.
precompile/modules/initia_stdlib/tests/ibc_transfer_tests.move - Adjusted id in TransferRequest from string to numeric format across multiple test functions.
- Updated test logic for failure states.
precompile/modules/minitia_stdlib/sources/ibctesting/ibctesting.move - Updated MoveAsyncCallback struct: changed id field from u64 to u32.
- Modified relay_acks_timeouts for type compatibility.
- Refined logic for handling transfers.
precompile/modules/minitia_stdlib/tests/ibc_transfer_tests.move - Changed id in TransferRequest from string to numeric format across test functions.
- Maintained test structure and logic.

Possibly related PRs

Suggested reviewers

  • sh-cha

Poem

In the land of code where rabbits hop,
We changed some types, made them pop!
From u64 to u32, we did refine,
Ensuring our callbacks align just fine.
With tests that now dance in numeric grace,
Our IBC transfers find their place! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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 (1)
precompile/modules/initia_stdlib/sources/minitswap.move (1)

3439-3439: Consider constructing JSON programmatically in tests

Hardcoding JSON strings in tests can be error-prone and less maintainable. Consider using JSON serialization functions to construct the expected JSON strings, enhancing readability and reducing potential errors.

Also applies to: 3458-3458

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e5294e7 and 5f819d3.

📒 Files selected for processing (5)
  • precompile/modules/initia_stdlib/sources/ibctesting/ibctesting.move (3 hunks)
  • precompile/modules/initia_stdlib/sources/minitswap.move (4 hunks)
  • precompile/modules/initia_stdlib/tests/ibc_transfer_tests.move (3 hunks)
  • precompile/modules/minitia_stdlib/sources/ibctesting/ibctesting.move (3 hunks)
  • precompile/modules/minitia_stdlib/tests/ibc_transfer_tests.move (3 hunks)
🔇 Additional comments (9)
precompile/modules/minitia_stdlib/sources/ibctesting/ibctesting.move (3)

208-208: LGTM!

The casting of async_callback.id from u32 to u64 ensures compatibility with the expected parameter type of dispatchable_ibc_timeout.


221-221: LGTM!

Casting async_callback.id from u32 to u64 ensures compatibility with dispatchable_ibc_ack.


404-406: LGTM!

Changing the id field from u64 to u32 addresses the JSON marshaling issue. Ensure that all parts of the code using MoveAsyncCallback are updated accordingly.

precompile/modules/initia_stdlib/sources/minitswap.move (2)

2401-2405: Confirm safe casting of batch_index to u32

In generate_ibc_message, batch_index of type u64 is cast to u32. Ensure that batch_index values remain within the u32 range to prevent data loss or overflow during the cast.


2340-2345: ⚠️ Potential issue

Potential overflow risk after changing id from u64 to u32

Changing the id field in MemoAsyncCallbackV2 from u64 to u32 reduces the maximum allowable value from 18,446,744,073,709,551,615 to 4,294,967,295. Ensure that batch_index and any other sources of id do not exceed u32::MAX, otherwise this could lead to integer overflows or unexpected behavior.

Please verify that batch_index cannot exceed u32::MAX. If there is a possibility, consider implementing a mechanism to handle larger values or explore alternative solutions to retain u64 while addressing the JSON marshaling issue.

precompile/modules/initia_stdlib/sources/ibctesting/ibctesting.move (2)

404-404: Ensure consistency with id type change from u64 to u32

Changing the id field in MoveAsyncCallback from u64 to u32 requires verifying that all usages and related functions handle this change consistently. Confirm that other parts of the codebase that use id are compatible with this new type.


208-208: Validate safe casting from u32 to u64 in function calls

In relay_acks_timeouts, async_callback.id of type u32 is cast back to u64 when passed to dispatchable_ibc_timeout and dispatchable_ibc_ack. Ensure this casting does not introduce issues, and the functions correctly handle u32 values within a u64 parameter.

Also applies to: 221-221

precompile/modules/minitia_stdlib/tests/ibc_transfer_tests.move (1)

288-288: Update of id field in memo JSON is correct

The id field in the memo JSON has been updated from a string to a numeric value, reflecting the change to a u32 type in MoveAsyncCallback. The test cases have been appropriately adjusted.

Also applies to: 365-365, 444-444

precompile/modules/initia_stdlib/tests/ibc_transfer_tests.move (1)

288-288: Update of id field in memo JSON is correct

The changes correctly update the id field in the memo JSON from a string to a numeric value, aligning with the u32 type in MoveAsyncCallback. The test cases reflect this change accurately.

Also applies to: 365-365, 444-444

Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

LGTM

@beer-1
Copy link
Member

beer-1 commented Dec 12, 2024

still do we need this? or is it okay to just close?

@ALPAC-4 ALPAC-4 merged commit f380b4a into main Dec 23, 2024
3 checks passed
@ALPAC-4 ALPAC-4 deleted the fix/minitswap-callback branch December 23, 2024 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants