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: handle gmp message for leverage messages #2479

Merged
merged 8 commits into from
Apr 4, 2024
Merged

Conversation

gsk967
Copy link
Collaborator

@gsk967 gsk967 commented Mar 28, 2024

Description

closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • added appropriate labels to the PR
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • Refactor
    • Enhanced memo handling in packet reception for improved reliability and error logging.
    • Streamlined memo processing logic for better efficiency and maintainability.
    • Improved message type cases for better performance.
    • Removed unnecessary functions to simplify code structure.
    • Updated memo handling logic in onRecvPacketPrepare method for improved processing.
    • Adjusted handling of memo and memoPayload for better deserialization.
    • Commented out GMP handling section in the execute method for potential processing changes.
    • Renamed Message struct to Memo for consistency in ICS20 packet memo field.

Copy link
Contributor

coderabbitai bot commented Mar 28, 2024

Walkthrough

The update focuses on refining memo handling within the codebase, specifically in the Handler struct's OnRecvPacket function. It includes improvements in error management, logging, and message type handling while removing unneeded functions. Additionally, a structural change in memo handling is made in a related file, emphasizing memoPayload usage for deserialization.

Changes

Files Summary
.../oracle/keeper/historic_price.go Removed //nolint: goconst directive in CalcAndSetHistoricMedian function.
.../uibc/gmp/gmp_middleware.go, .../gmp/gmp_middleware_test.go Updated memo handling in OnRecvPacket, refined error handling and logging, modified test cases, and removed HandleGeneralMessage functions.
.../uibc/gmp/types.go Renamed Message struct to Memo for ICS20 packet memo field.

🐇✨
In the realm of code where the data packets flow,
A rabbit hopped in, with updates in tow.
"Refine and streamline," it said with a cheer,
No more general messages, let's make that clear.
With a wiggle of ears and a flick of its tail,
The memo now sails smoothly, without fail.
🎉🐰💻

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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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.
  • 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/coderabbit-overrides.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

codecov bot commented Mar 28, 2024

Codecov Report

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

Project coverage is 69.34%. Comparing base (7f05ad4) to head (41b8c26).
Report is 430 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2479      +/-   ##
==========================================
- Coverage   75.38%   69.34%   -6.05%     
==========================================
  Files         100      189      +89     
  Lines        8025    10944    +2919     
==========================================
+ Hits         6050     7589    +1539     
- Misses       1589     2727    +1138     
- Partials      386      628     +242     
Files Coverage Δ
x/uibc/gmp/gmp_middleware.go 100.00% <100.00%> (ø)
x/oracle/keeper/historic_price.go 65.80% <0.00%> (+4.69%) ⬆️
x/uibc/uics20/memo_handler.go 66.31% <53.84%> (ø)

... and 175 files with indirect coverage changes

Copy link
Member

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

  1. gmp handling must be done after the transfer - otherwise, if we execute a bank Send, before the transfer is recorded, we will miss the funds
  2. Need to add checks as we do in the normal hooks
  3. If we handle GMP, then we must abort the "normal" hooks execution
  4. Need to add GMP types and support fallback.

x/uibc/uics20/memo_handler.go Outdated Show resolved Hide resolved
x/uibc/uics20/memo_handler.go Outdated Show resolved Hide resolved
@gsk967
Copy link
Collaborator Author

gsk967 commented Apr 1, 2024

  1. gmp handling must be done after the transfer - otherwise, if we execute a bank Send, before the transfer is recorded, we will miss the funds

    1. Need to add checks as we do in the normal hooks

    2. If we handle GMP, then we must abort the "normal" hooks execution

    3. Need to add GMP types and support fallback.

  1. There is no need for separate execution for gmp handler because the incoming gmp payload is same as ibc memo and it is executing after normal ibc transfer execution
  2. The incoming payload same as ibc memo payload , so we already added checks for msgs
  3. No need to abort the hooks execution
  4. We already added GMP types https://github.com/umee-network/umee/blob/sai/handle_gmp_messages/x/uibc/gmp/types.go#L9-L15

@gsk967 gsk967 marked this pull request as ready for review April 2, 2024 13:44
@gsk967 gsk967 requested a review from a team as a code owner April 2, 2024 13:44
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.

Actionable comments posted: 3

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3b8bf2c and b8601ba.
Files selected for processing (3)
  • x/uibc/gmp/gmp_middleware.go (2 hunks)
  • x/uibc/gmp/gmp_middleware_test.go (2 hunks)
  • x/uibc/uics20/memo_handler.go (2 hunks)
Additional Context Used
GitHub Check Runs (1)
codecov/patch failure (4)

x/uibc/gmp/gmp_middleware.go: [warning] 20-20: x/uibc/gmp/gmp_middleware.go#L20
Added line #L20 was not covered by tests


x/uibc/gmp/gmp_middleware.go: [warning] 39-39: x/uibc/gmp/gmp_middleware.go#L39
Added line #L39 was not covered by tests


x/uibc/uics20/memo_handler.go: [warning] 65-68: x/uibc/uics20/memo_handler.go#L65-L68
Added lines #L65 - L68 were not covered by tests


x/uibc/uics20/memo_handler.go: [warning] 70-70: x/uibc/uics20/memo_handler.go#L70
Added line #L70 was not covered by tests

Additional comments not posted (3)
x/uibc/gmp/gmp_middleware.go (1)

17-39: The OnRecvPacket function has been updated to handle a memoStr parameter and return a Message struct along with an error. This change aligns with the PR's objective to enhance GMP message handling. However, there are a couple of points to consider:

  • The function now directly returns errors without any specific handling or logging for different error types, which might be worth adding for better error diagnostics.
  • The handling for TypeGeneralMessageWithToken simply returns msg, nil, which seems inconsistent with the other case handling. It might be beneficial to clarify the intended behavior here or add additional logic if necessary.

Additionally, the removal of HandleGeneralMessage and HandleGeneralMessageWithToken functions suggests a significant refactor. Ensure that their functionalities are either no longer needed or have been integrated elsewhere in the codebase.

-		return msg, nil
+		// Assuming additional logic or a specific return message might be required here.
+		// Placeholder for further implementation or clarification.
+		return msg, fmt.Errorf("handling for TypeGeneralMessageWithToken not implemented")
x/uibc/gmp/gmp_middleware_test.go (1)

40-67: > 📝 NOTE

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

The test cases in TestGmpMemoHandler have been updated to reflect changes in memo handling, specifically testing for "invalid memo" and "not supporting the msg" scenarios. These updates are crucial for ensuring the OnRecvPacket function behaves as expected under various conditions. However, consider the following improvements:

  • Adding more descriptive names for test cases to clearly indicate the scenario being tested.
  • Including test cases for scenarios not covered, such as receiving an empty memoStr and handling unrecognized GMP message types, to ensure comprehensive test coverage.

Consider enhancing test case names for clarity and adding additional test cases for scenarios not currently covered.

x/uibc/uics20/memo_handler.go (1)

115-118: The GMP handling section in the execute method has been commented out, potentially indicating a shift in how GMP messages are processed. Given the comments from gsk967 and the PR author's response, this change seems intentional. However, ensure that this commented-out code is either removed or replaced with an updated implementation if no longer needed, to avoid confusion and maintain code cleanliness.

Consider removing or updating the commented-out GMP handling section in the execute method for clarity and cleanliness.

x/uibc/gmp/gmp_middleware.go Outdated Show resolved Hide resolved
x/uibc/gmp/gmp_middleware.go Show resolved Hide resolved
x/uibc/uics20/memo_handler.go Outdated Show resolved Hide resolved
Copy link
Member

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

  1. Need to fix error handling
  2. Please add more tests, or list all missing tests in the subtask of the epic.

x/uibc/gmp/gmp_middleware.go Outdated Show resolved Hide resolved
x/uibc/gmp/gmp_middleware.go Outdated Show resolved Hide resolved
x/uibc/gmp/gmp_middleware_test.go Show resolved Hide resolved
x/uibc/uics20/memo_handler.go Show resolved Hide resolved
x/uibc/uics20/memo_handler.go Outdated Show resolved Hide resolved
x/uibc/uics20/memo_handler.go Outdated Show resolved Hide resolved
x/uibc/uics20/memo_handler.go Outdated Show resolved Hide resolved
x/uibc/uics20/memo_handler.go Outdated Show resolved Hide resolved
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.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b8601ba and 623ec28.
Files selected for processing (1)
  • x/uibc/gmp/gmp_middleware.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/uibc/gmp/gmp_middleware.go

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.

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 623ec28 and 5c28e71.
Files selected for processing (4)
  • x/uibc/gmp/gmp_middleware.go (2 hunks)
  • x/uibc/gmp/gmp_middleware_test.go (3 hunks)
  • x/uibc/gmp/types.go (1 hunks)
  • x/uibc/uics20/memo_handler.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/uibc/uics20/memo_handler.go
Additional comments not posted (2)
x/uibc/gmp/types.go (1)

18-19: The renaming of Message to GMPMemo is clear and aligns with the intended use within the ICS20 packet memo field. This change enhances clarity and specificity in the codebase.

x/uibc/gmp/gmp_middleware_test.go (1)

35-58: > 📝 NOTE

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

The test cases for ParseMemo function are comprehensive and cover a variety of scenarios, including empty, invalid, unsupported, and valid memos. Ensure that the payload type aligns with the Axelar documentation, as previously discussed.

x/uibc/gmp/gmp_middleware.go Outdated Show resolved Hide resolved
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.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5c28e71 and 330efe3.
Files selected for processing (3)
  • x/uibc/gmp/gmp_middleware.go (1 hunks)
  • x/uibc/gmp/gmp_middleware_test.go (4 hunks)
  • x/uibc/uics20/memo_handler.go (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/uibc/gmp/gmp_middleware.go
  • x/uibc/gmp/gmp_middleware_test.go
  • x/uibc/uics20/memo_handler.go

Copy link
Member

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

Pre-approving

x/uibc/gmp/types.go Outdated Show resolved Hide resolved
@gsk967 gsk967 requested a review from a team as a code owner April 4, 2024 08:37
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.

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 330efe3 and 41b8c26.
Files selected for processing (4)
  • x/oracle/keeper/historic_price.go (1 hunks)
  • x/uibc/gmp/gmp_middleware.go (1 hunks)
  • x/uibc/gmp/gmp_middleware_test.go (4 hunks)
  • x/uibc/gmp/types.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/uibc/gmp/gmp_middleware_test.go
  • x/uibc/gmp/types.go
Additional comments not posted (1)
x/oracle/keeper/historic_price.go (1)

48-48: Ensure the removal of the //nolint: goconst directive does not introduce any linter warnings or errors.

  • Verify that the change complies with the project's coding standards and linter configurations.
  • Consider if the repeated string "denom: "+denom could be refactored to avoid potential linter warnings about string duplication.

x/uibc/gmp/gmp_middleware.go Show resolved Hide resolved
@gsk967 gsk967 enabled auto-merge April 4, 2024 08:56
@gsk967 gsk967 added this pull request to the merge queue Apr 4, 2024
Merged via the queue into main with commit 890f106 Apr 4, 2024
25 of 27 checks passed
@gsk967 gsk967 deleted the sai/handle_gmp_messages branch April 4, 2024 08:57
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