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(uibc): adding ICS 20 memo handler #2349

Merged
merged 10 commits into from
Dec 18, 2023
Merged

Conversation

robert-zaremba
Copy link
Member

@robert-zaremba robert-zaremba commented Dec 5, 2023

Description

  • adding proto type for memo
  • updating interfaces

Summary by CodeRabbit

  • New Features

    • Introduced a new protocol buffer for enhanced network communication.
    • Added new message type handling capabilities for inter-blockchain communication.
  • Refactor

    • Improved the codec interface with additional comments for clarity.
    • Enhanced existing functions with new parameters for better data handling.
    • Optimized import paths and function invocations for better performance and maintainability.
  • Tests

    • Added new tests to ensure reliable message marshalling.
  • Documentation

    • Updated function signatures and in-code comments for better understanding of the code base.

Copy link
Contributor

coderabbitai bot commented Dec 5, 2023

Walkthrough

The updates involve the integration of a new ICS20Memo message type within the uibc.proto file, adjustments to codec registration in codec.go, and enhancements to the uibc package with a new method for unpacking interfaces. The uibc module's IBC middleware and quota management have been refined with additional parameters and improved error handling. New test functions are added to validate message marshalling, and import paths are updated across various files to reflect these changes.

Changes

File(s) Summary
proto/umee/uibc/v1/uibc.proto Introduced new ICS20Memo message type and related code generation options.
tests/tsdk/codec.go Added comment regarding SDK interface registration.
x/uibc/ics20.go Added UnpackInterfaces method to ICS20Memo type.
x/uibc/quota/ibc_middleware.go,
x/uibc/quota/quota.go
Modified function signatures, improved error handling, and updated logic for IBC inflow recording.
x/uibc/uics20/ibc_module.go,
x/uibc/uics20/ics4_module_int_test.go,
x/uibc/uics20/ics4_wrapper_test.go
Added imports, modified ICS20Module struct and constructor, introduced new test functions, and reorganized imports.

🐇✨
In the realm of code, where bytes do roam,
A rabbit hopped through, leaving changes at home.
With a whisk of its tail and a tweak of the lines,
New features afoot, in the digital pines. 🌲🖥️

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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

x/uibc/uics20/ibc_module.go Fixed Show fixed Hide fixed
x/uibc/uics20/ibc_module.go Fixed Show fixed Hide fixed
x/uibc/uics20/ibc_module.go Fixed Show fixed Hide fixed
Copy link

codecov bot commented Dec 14, 2023

Codecov Report

Merging #2349 (701b388) into main (7f05ad4) will decrease coverage by 5.83%.
Report is 320 commits behind head on main.
The diff coverage is 66.08%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2349      +/-   ##
==========================================
- Coverage   75.38%   69.56%   -5.83%     
==========================================
  Files         100      172      +72     
  Lines        8025    12759    +4734     
==========================================
+ Hits         6050     8876    +2826     
- Misses       1589     3277    +1688     
- Partials      386      606     +220     
Files Coverage Δ
ante/ante.go 66.66% <100.00%> (+18.45%) ⬆️
ante/fee.go 80.00% <100.00%> (+1.64%) ⬆️
ante/spam_prevention.go 75.92% <ø> (ø)
app/inflation/inflation.go 100.00% <100.00%> (ø)
app/upgradev3/migrations.go 84.21% <ø> (+5.94%) ⬆️
util/coin/utoken.go 100.00% <100.00%> (ø)
util/ibc/ibc.go 58.82% <ø> (ø)
util/sdkutil/events.go 0.00% <ø> (ø)
util/store/store.go 52.06% <ø> (+10.65%) ⬆️
util/store/unmarshal.go 42.85% <ø> (ø)
... and 40 more

... and 111 files with indirect coverage changes

@robert-zaremba robert-zaremba marked this pull request as ready for review December 15, 2023 15:08
@robert-zaremba robert-zaremba requested a review from a team as a code owner December 15, 2023 15:08
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: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3d3a56d and 92b3847.
Files ignored due to filter (1)
  • x/uibc/uibc.pb.go
Files selected for processing (8)
  • proto/umee/uibc/v1/uibc.proto (1 hunks)
  • tests/tsdk/codec.go (1 hunks)
  • x/uibc/ics20.go (1 hunks)
  • x/uibc/quota/ibc_middleware.go (2 hunks)
  • x/uibc/quota/quota.go (3 hunks)
  • x/uibc/uics20/ibc_module.go (5 hunks)
  • x/uibc/uics20/ics4_module_int_test.go (1 hunks)
  • x/uibc/uics20/ics4_wrapper_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • tests/tsdk/codec.go
Additional comments: 16
proto/umee/uibc/v1/uibc.proto (1)
  • 1-16: The ICS20Memo message type is well-defined with appropriate syntax, package declaration, and imports. The comments provide clear documentation on the purpose of the messages field.
x/uibc/ics20.go (1)
  • 8-11: The implementation of the UnpackInterfaces method for ICS20Memo looks correct and aligns with the Cosmos SDK's patterns for unpacking interfaces. It's important to ensure that all types.Any fields within ICS20Memo are accounted for in this method.
x/uibc/quota/ibc_middleware.go (3)
  • 36-46: The signature of IBCOnRecvPacket has been correctly updated to include the ft ics20types.FungibleTokenPacketData parameter. Ensure that all invocations of this function across the codebase are updated to pass the new parameter.

  • 43-45: The RecordIBCInflow method is called with the packet and ft.Denom, ft.Amount from the FungibleTokenPacketData. Ensure that the RecordIBCInflow method's signature and implementation are updated to handle these arguments correctly.

Verification successful

The output from the shell script confirms that the RecordIBCInflow method in x/uibc/quota/quota.go has been updated to accept three parameters: packet channeltypes.Packet, denom, and amount string. This matches the new usage of the method in the IBCOnRecvPacket function, where it is called with packet, ft.Denom, and ft.Amount.

The method's implementation appears to handle these arguments correctly, performing checks and calculations based on the packet information and the denomination and amount from the FungibleTokenPacketData. The method returns an exported.Acknowledgement, which is consistent with the expected behavior described in the review comment.

Based on this information, the changes to the RecordIBCInflow method's signature and implementation are consistent with the new usage in the IBCOnRecvPacket function, and no issues have been found in this specific context.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the `RecordIBCInflow` method definition to ensure it matches the new usage.
ast-grep --lang go --pattern $'func ($_ Keeper) RecordIBCInflow($$$) $$$'

Length of output: 2885

* 33-46: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [15-45]

Review the entire ibc_middleware.go file to ensure that the RecordIBCInflow function and related changes are consistent with the PR's objectives, especially regarding import paths, argument names, logic, variable usage, and error handling.

Verification successful

The output from the shell script provides the definition and contents of the RecordIBCInflow function in the quota.go file. The function takes three parameters: packet of type channeltypes.Packet, denom, and amount both of type string. It returns an exported.Acknowledgement.

The function's logic includes:

  • Checking if the sender chain is the source for the IBC packet and if not, it prefixes the denomination.
  • It then tries to get token settings from the leverage module using the IBC denomination.
  • If the token is not registered, it skips recording the inflow.
  • If there's an error fetching the token settings, it logs the error and returns an error acknowledgment.
  • It fetches the exchange rate from the oracle module using the symbol denomination.
  • It calculates the inflow in USD and updates the token inflow and inflow sum accordingly.

This function's behavior seems to be consistent with the PR's objectives, which include updates to logic, variable usage, and error handling in the RecordIBCInflow function as part of enhancing the IBC functionality with the ability to handle memos.

Based on the provided information, there are no inconsistencies with the PR's objectives regarding the RecordIBCInflow function. The changes to the function seem to align with the intent to update the IBC functionality, particularly in how it records inflows, which could be related to the handling of memos in token transfers.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the `RecordIBCInflow` function definition and usage to ensure it is consistent with the PR's objectives.
ast-grep --lang go --pattern $'func ($_ Keeper) RecordIBCInflow($$$) $$$'

Length of output: 2885

x/uibc/quota/quota.go (6)
  • 9-9: The import path change from transfer/types to ics20/types aligns with the PR's objective to handle ICS 20 memos.

  • 229-253: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [232-260]

The removal of the isSourceChain parameter from the RecordIBCInflow function signature is a significant change. Ensure that all calls to this function have been updated to reflect this change, and that the new logic within the function correctly determines the source chain.

Verification successful

The shell script execution did not produce any output for both the old and new function signatures. This could mean that there are no instances of the old function signature left in the codebase, and the new function signature is not being used yet, or it could be an issue with the script itself.

Given that the script did not return any results, I cannot confirm whether all calls to the RecordIBCInflow function have been updated to reflect the removal of the isSourceChain parameter. To proceed, I will generate a new shell script to search for any calls to RecordIBCInflow throughout the codebase. This will help determine if the function is being called with the correct number of arguments.


The new shell script output shows that the RecordIBCInflow function is defined in x/uibc/quota/quota.go with the updated signature that takes three parameters. Additionally, it is being called in x/uibc/quota/ibc_middleware.go with three arguments, which matches the new signature.

This indicates that the function signature change has been correctly reflected in at least one call within the codebase. However, without further context, I cannot confirm that all calls to this function across the entire codebase have been updated accordingly. For a comprehensive verification, a manual review of the entire codebase would be required.

Based on the information available from the script execution, the change to the RecordIBCInflow function signature appears to be correctly implemented in the instances that were found.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old function signature to find omissions.
ast-grep --lang go --pattern $'func (k Keeper) RecordIBCInflow($_, $_, $_, $_) $_ { $$$ }'
# Search for the new function signature to validate usage.
ast-grep --lang go --pattern $'func (k Keeper) RecordIBCInflow($_, $_, $_) $_ { $$$ }'

Length of output: 179



Script:

#!/bin/bash
# Search for calls to the RecordIBCInflow function to ensure they match the new signature.
rg 'RecordIBCInflow\('

Length of output: 218

* 237-250: The new logic within `RecordIBCInflow` to determine the source chain and handle the `ibcDenom` appears to be correct. However, verify that the `SenderChainIsSource` function is used correctly in all contexts and that the error handling is appropriate and consistent with the rest of the codebase.
Verification successful

The usage of ics20types.SenderChainIsSource within RecordIBCInflow is unique to this function, and there is no indication of incorrect usage. The error handling with channeltypes.NewErrorAcknowledgement is consistent with other IBC-related code in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for usage of `SenderChainIsSource` to ensure it's being used correctly.
ast-grep --lang go --pattern $'ics20types.SenderChainIsSource($_, $_, $_)'
# Search for error handling patterns to ensure consistency.
rg 'channeltypes.NewErrorAcknowledgement'

Length of output: 576

* 239-243: The use of `sourcePrefix` to construct `prefixedDenom` and derive `ibcDenom` is consistent with the PR's objective to handle ICS 20 memos.
  • 260-260: The calculation of inflowInUSD using MustNewDecFromStr and the exchange rate from the oracle seems correct. However, ensure that the MustNewDecFromStr function is used safely and that the calculation accurately reflects the intended conversion to USD.

  • 247-247: The change in error handling within RecordIBCInflow to return nil for non-registered tokens instead of an error acknowledgement should be verified to ensure it aligns with the intended error handling strategy for the application.

Verification successful

Based on the search results, ErrNotRegisteredToken is a common error pattern used across various files in the codebase. However, to determine if the change in quota.go to return nil instead of an error is consistent with the application's error handling strategy, we should look for other instances where a similar approach is taken.

Let's search for instances in quota.go and related tests where a nil return is specifically used in the context of non-registered tokens.


The search results confirm that returning nil in the context of non-registered tokens is a consistent pattern within quota.go. The change in the PR where the RecordIBCInflow function returns nil instead of an error acknowledgement for non-registered tokens aligns with this established error handling strategy in the application.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for error handling patterns for non-registered tokens to ensure consistency.
rg 'ErrNotRegisteredToken'

Length of output: 2447



Script:

#!/bin/bash
# Search for instances in 'quota.go' and related tests where a nil return is used in the context of non-registered tokens.
rg -A 3 -B 3 'return nil' x/uibc/quota/quota.go
rg -A 3 -B 3 'return nil' x/uibc/quota/intest/quota_test.go

Length of output: 1634

x/uibc/uics20/ibc_module.go (3)
  • 106-108: The dispatchMemoMsgs function logs an error if there are more than two messages but does not handle the error beyond logging. Confirm if this is the intended behavior or if further error handling is required.

  • 98-156: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [140-157]

Verify that the deserializeFTData and DeserializeMemoMsgs functions do not introduce security vulnerabilities through deserialization and that all error cases are handled appropriately.

  • 53-63: The OnRecvPacket function logs an error if the memo cannot be deserialized but continues processing. Confirm if this is the intended behavior or if the transaction should be stopped when the memo is invalid.
x/uibc/uics20/ics4_module_int_test.go (1)
  • 17-37: The test TestMsgMarshalling appears to be well-structured and is testing the marshalling and unmarshalling of the ICS20Memo type. It's using assertions to validate that the original messages are equal to the messages after serialization and deserialization, which is a good practice for ensuring data integrity during the process. Ensure that this test covers all edge cases and potential error scenarios for a comprehensive validation of the marshalling logic.
x/uibc/uics20/ics4_wrapper_test.go (1)
  • 12-18: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [3-18]

The import "gotest.tools/v3/assert" appears to have been reorganized within the import block. Ensure that this reorganization does not introduce any duplicate imports and that "gotest.tools/v3/assert" is still correctly accessible within the test functions.

Verification successful

The shell script output confirms that the import "gotest.tools/v3/assert" appears only once in the file x/uibc/uics20/ics4_wrapper_test.go, which means there are no duplicate imports after the reorganization. This verifies that the import is correctly accessible within the test functions and there are no issues with the import statements as per the changes mentioned.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for duplicate imports of "gotest.tools/v3/assert" in the file.
rg 'gotest.tools/v3/assert' x/uibc/uics20/ics4_wrapper_test.go | wc -l

Length of output: 72

x/uibc/uics20/ics4_module_int_test.go Show resolved Hide resolved
x/uibc/uics20/ibc_module.go Show resolved Hide resolved
x/uibc/uics20/ibc_module.go Outdated Show resolved Hide resolved
x/uibc/uics20/ibc_module.go Outdated Show resolved Hide resolved
x/uibc/uics20/ibc_module.go 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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 92b3847 and 8bb49c4.
Files selected for processing (2)
  • app/app.go (1 hunks)
  • x/uibc/uics20/ibc_module.go (4 hunks)
Additional comments: 2
app/app.go (1)
  • 581-586: The addition of leveragekeeper.NewMsgServerImpl(app.LeverageKeeper) as an argument to NewICS20Module suggests integration with the LeverageKeeper. Verify that the LeverageKeeper is correctly integrated and that its methods are compatible with the IBC middleware stack.
Verification successful

The script did not find any instances of NewICS20Module being called with four arguments. To ensure that there are no outdated calls to NewICS20Module that need to be updated, I will generate a new script to search for calls to NewICS20Module with any number of arguments.


The executed scripts did not find any instances of NewICS20Module being called elsewhere in the codebase. This suggests that the change to include an additional argument in app/app.go is localized and does not affect other parts of the codebase. The verification process did not reveal any issues with the integration of leveragekeeper.NewMsgServerImpl(app.LeverageKeeper) in the NewICS20Module function call.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for other instances of `NewICS20Module` to ensure they are updated.
rg 'NewICS20Module' --files-with-matches | xargs -L 1 ast-grep --lang go --pattern $'NewICS20Module($_, $_, $_, $_)'

Length of output: 115



Script:

#!/bin/bash
# Search for any calls to `NewICS20Module` to ensure all instances are updated.
rg 'NewICS20Module' --files-with-matches | xargs -L 1 ast-grep --lang go --pattern $'NewICS20Module($$$)'

Length of output: 104

x/uibc/uics20/ibc_module.go (1)
  • 33-40: The constructor signature for NewICS20Module now correctly includes the leverage ltypes.MsgServer parameter as per the changes described in the PR and the AI-generated summary. This resolves the previous issue raised about the missing parameter.

x/uibc/uics20/ibc_module.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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8bb49c4 and 701b388.
Files selected for processing (2)
  • x/uibc/quota/ibc_middleware.go (2 hunks)
  • x/uibc/uics20/ibc_module.go (4 hunks)
Additional comments: 2
x/uibc/quota/ibc_middleware.go (2)
  • 36-37: The signature of IBCOnRecvPacket has been modified to include an additional parameter. Verify that all invocations of this function across the codebase have been updated to pass the new argument.
Verification successful

To verify that all invocations of the modified IBCOnRecvPacket function have been updated to pass the new argument, I will search for calls to this function throughout the codebase.


The search results indicate that the call to IBCOnRecvPacket in ibc_module.go has been updated to include the new parameter, matching the modified function signature. There are no instances of the function being called with the old signature. This suggests that the necessary updates have been made in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the old function signature to find any missed updates.
ast-grep --lang go --pattern $'func (k Keeper) IBCOnRecvPacket(packet channeltypes.Packet) exported.Acknowledgement {
  $$$
}'

# Search for the new function signature to validate usage.
ast-grep --lang go --pattern $'func (k Keeper) IBCOnRecvPacket(ft ics20types.FungibleTokenPacketData, packet channeltypes.Packet) exported.Acknowledgement {
  $$$
}'

Length of output: 1313



Script:

#!/bin/bash
# Search for calls to the IBCOnRecvPacket function to ensure they include the new parameter.
rg 'IBCOnRecvPacket' --vimgrep

Length of output: 290

* 44-44: Confirm that the `RecordIBCInflow` method's signature has been updated to accept the new arguments and that it is being used correctly in all places.
Verification successful

The RecordIBCInflow method's signature has indeed been updated to accept the new arguments as indicated by the invocation in ibc_middleware.go. The method is defined in x/uibc/quota/quota.go and is being used correctly in the place that was checked.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the `RecordIBCInflow` method definition to check its signature.
ast-grep --lang go --pattern $'func (k Keeper) RecordIBCInflow(packet channeltypes.Packet, denom string, amount string) error {
  $$$
}'

# Search for the `RecordIBCInflow` method invocation to validate usage.
ast-grep --lang go --pattern $'k.RecordIBCInflow($_, $_, $_)'

Length of output: 295



Script:

#!/bin/bash
# Adjust the pattern to search for the `RecordIBCInflow` method definition without specifying the exact parameters.
ast-grep --lang go --pattern $'func (k Keeper) RecordIBCInflow($$$) error {
  $$$
}'

Length of output: 85



Script:

#!/bin/bash
# Use ripgrep to search for the `RecordIBCInflow` method definition in the codebase.
rg 'func \(k Keeper\) RecordIBCInflow'

Length of output: 144

x/uibc/uics20/ibc_module.go Show resolved Hide resolved
x/uibc/uics20/ibc_module.go Show resolved Hide resolved
x/uibc/uics20/ibc_module.go Show resolved Hide resolved
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

@robert-zaremba robert-zaremba added this pull request to the merge queue Dec 18, 2023
Merged via the queue into main with commit 5dbe282 Dec 18, 2023
24 of 27 checks passed
@robert-zaremba robert-zaremba deleted the robert/uibc-memo-handler branch December 18, 2023 10: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