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(ibc): memo fallback address #2442

Merged
merged 8 commits into from
Mar 1, 2024
Merged

Conversation

robert-zaremba
Copy link
Member

@robert-zaremba robert-zaremba commented Feb 28, 2024

Description

  1. Try to unpack and prepare memo. If memo has a correct structure, and fallback addr is defined but malformed, we cancel the transfer (otherwise would not be able to use it correctly)
  2. If memo has a correct structure, but memo.messages can't be unpack or don't pass validation,
    then we continue with the transfer and overwrite the original receiver to fallback_addr if
    it's defined.
  3. Execute the downstream middleware and the transfer app.
  4. Execute hooks. If hook execution fails, we don't use the the fallback_addr nor ignore the transfer.
    This is because there could be other middlewares that are already executed.

NOTE: I'm not very convinced about the last point - personally I would always revert the transfer if the memo hook structure is correct but we can't handle it (validation problem, message not supported, or hook execution error). What do you think?

Summary by CodeRabbit

  • New Features
    • Introduced a fallback recipient address option for enhanced transaction flexibility.
    • Added memo processing functionality, including receiver overwrite based on specific conditions.
  • Enhancements
    • Improved message unpacking capabilities for better data handling.
    • Enhanced event logging and error reporting for more transparent operation feedback.
  • Refactor
    • Optimized memo handling logic for increased efficiency and reliability.
  • Tests
    • Expanded testing suite to cover new functionalities and ensure robustness of memo processing.

@robert-zaremba robert-zaremba requested a review from a team as a code owner February 28, 2024 18:46
Copy link
Contributor

coderabbitai bot commented Feb 28, 2024

Walkthrough

The updates introduce a new fallback_addr field in the ICS20Memo message to handle scenarios where the original recipient address might need to be overwritten. Additionally, a new function for unpacking messages, enhanced memo processing with a MemoHandler, and improved error logging and event emission in packet reception are introduced. The changes streamline memo message validation and deserialization, enhancing the overall reliability and flexibility of message handling.

Changes

Files Change Summaries
proto/umee/uibc/v1/uibc.proto Added fallback_addr field in ICS20Memo.
x/uibc/ics20.go Added GetMsgs function for unpacking messages.
x/uibc/uics20/ibc_module.go Enhanced memo processing, event emission, and error logging. Imported encoding/json.
x/uibc/uics20/memo_handler.go
x/uibc/uics20/memo_handler_test.go
Updated memo handling logic, added validation, and adjusted deserialization. Improved testing.

🐰✨📜✨🐰
In the world of code, where bytes do roam,
A rabbit hopped, making blockchain its home.
With a flick and hop, it weaved a charm,
To keep the packets safe and away from harm.
"To the future," it whispered, with a grin,
"With every commit, let the magic begin!"
🌟🐾🌟

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4ceb4c8 and 027ea07.
Files ignored due to path filters (1)
  • x/uibc/uibc.pb.go is excluded by: !**/*.pb.go
Files selected for processing (5)
  • proto/umee/uibc/v1/uibc.proto (1 hunks)
  • x/uibc/ics20.go (2 hunks)
  • x/uibc/uics20/ibc_module.go (3 hunks)
  • x/uibc/uics20/memo_handler.go (4 hunks)
  • x/uibc/uics20/memo_handler_test.go (1 hunks)
Additional comments: 4
x/uibc/ics20.go (1)
  • 16-19: The GetMsgs function is correctly implemented for unpacking messages from the ICS20Memo struct into []sdk.Msg. This addition follows the standard approach in the Cosmos SDK and is essential for processing the messages contained within the ICS20Memo.
x/uibc/uics20/memo_handler_test.go (1)
  • 122-138: The modifications to the TestMsgMarshalling function, including the change to use deserializeMemo and the addition of new assertions and tests for different deserialization inputs, are well-implemented. These changes ensure comprehensive testing of the deserialization logic, covering scenarios such as successful deserialization, handling of empty input, and improperly formatted input.
x/uibc/uics20/memo_handler.go (1)
  • 22-63: The changes in memo_handler.go, including the renaming and updating of the onRecvPacket method to onRecvPacketPre, the refactoring of dispatchMemoMsgs, the addition of the validateMemoMsg method, and the update to the deserializeMemo method, significantly improve the clarity, maintainability, and functionality of memo handling in the IBC module. These changes are well-implemented and adhere to best practices.
x/uibc/uics20/ibc_module.go (1)
  • 41-92: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [4-140]

The changes in ibc_module.go, including the addition of the encoding/json import, detailed comments in OnRecvPacket, the introduction of MemoHandler for memo processing, updated logic in OnRecvPacket for memo processing and potential receiver overwrite, added event emission, and enhanced error logging, significantly improve the functionality, modularity, and observability of the IBC module. These changes are well-implemented and adhere to best practices.

proto/umee/uibc/v1/uibc.proto Outdated Show resolved Hide resolved
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 3.33333% with 58 lines in your changes are missing coverage. Please review.

Project coverage is 69.04%. Comparing base (7f05ad4) to head (cc3598a).
Report is 390 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2442      +/-   ##
==========================================
- Coverage   75.38%   69.04%   -6.35%     
==========================================
  Files         100      183      +83     
  Lines        8025    10796    +2771     
==========================================
+ Hits         6050     7454    +1404     
- Misses       1589     2732    +1143     
- Partials      386      610     +224     
Files Coverage Δ
x/uibc/ics20.go 0.00% <0.00%> (ø)
x/uibc/uics20/ibc_module.go 0.00% <0.00%> (ø)
x/uibc/uics20/memo_handler.go 29.48% <6.66%> (ø)

... and 171 files with indirect coverage changes

Copy link
Collaborator

@gsk967 gsk967 left a comment

Choose a reason for hiding this comment

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

utAck

Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 027ea07 and cc3598a.
Files ignored due to path filters (1)
  • x/uibc/uibc.pb.go is excluded by: !**/*.pb.go
Files selected for processing (3)
  • app/app.go (1 hunks)
  • proto/umee/uibc/v1/uibc.proto (1 hunks)
  • x/uibc/uics20/ibc_module.go (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • proto/umee/uibc/v1/uibc.proto
  • x/uibc/uics20/ibc_module.go
Additional comments: 1
app/app.go (1)
  • 597-599: The comment added emphasizes the importance of positioning the uics20 module as the last middleware in the transferStack. This is crucial to ensure that no other middleware manipulates the packet between the uics20 middleware and the transfer app, which could potentially interfere with the execution of transfer hooks. This change aligns with best practices for middleware ordering in IBC transactions, ensuring that memo processing and potential receiver overwrite logic are correctly handled without interference.

@robert-zaremba robert-zaremba enabled auto-merge March 1, 2024 00:32
@robert-zaremba robert-zaremba added this pull request to the merge queue Mar 1, 2024
Merged via the queue into main with commit 01bbb48 Mar 1, 2024
26 of 28 checks passed
@robert-zaremba robert-zaremba deleted the robert/ibc-memo-fallback branch March 1, 2024 00:34
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