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 transfer): Register IBC denom on transfer #900

Merged
merged 26 commits into from
Jun 11, 2024

Conversation

zale144
Copy link
Contributor

@zale144 zale144 commented May 24, 2024

Description


Closes #907

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.

PR review checkboxes:

I have...

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Targeted PR against the correct branch
  • included the correct type prefix in the PR title
  • Linked to the GitHub issue with discussion and accepted design
  • Targets only one GitHub issue
  • Wrote unit and integration tests
  • Wrote relevant migration scripts if necessary
  • All CI checks have passed
  • Added relevant godoc comments
  • Updated the scripts for local run, e.g genesis_config_commands.sh if the PR changes parameters
  • Add an issue in the e2e-tests repo if necessary

SDK Checklist

  • Import/Export Genesis
  • Registered Invariants
  • Registered Events
  • Updated openapi.yaml
  • No usage of go map
  • No usage of time.Now()
  • Used fixed point arithmetic and not float arithmetic
  • Avoid panicking in Begin/End block as much as possible
  • No unexpected math Overflow
  • Used sendCoin and not SendCoins
  • Out-of-block compute is bounded
  • No serialized ID at the end of store keys
  • UInt to byte conversion should use BigEndian

Full security checklist here

----;

For Reviewer:

  • Confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • Confirmed all author checklist items have been addressed

---;

After reviewer approval:

  • In case the PR targets the main branch, PR should not be squash merge in order to keep meaningful git history.
  • In case the PR targets a release branch, PR must be rebased.

Summary by CodeRabbit

  • New Features

    • Introduced IBC middleware to migrate denom metadata to rollappp.
    • Added functionality to register and manage denom metadata within the app.
  • Bug Fixes

    • Corrected spelling from "acknowledgment" to "acknowledgement".
  • Refactor

    • Significant refactoring of IBC middleware and related handlers for improved performance and maintainability.
    • Updated method calls and middleware stack configurations for better integration with Rollapp.
  • Tests

    • Enhanced test coverage for new middleware functionalities and denom metadata handling.
    • Added tests for IBC packet handling and acknowledgment processes.

@zale144 zale144 self-assigned this May 24, 2024
@zale144 zale144 requested a review from a team as a code owner May 24, 2024 10:31
@zale144 zale144 marked this pull request as draft May 24, 2024 10:33
@zale144 zale144 marked this pull request as ready for review May 26, 2024 02:18
@danwt
Copy link
Contributor

danwt commented May 28, 2024

Please could you make and link an issue, and cross link the rdk pr?

@danwt danwt changed the title feat: Register IBC denom on transfer feat(ibc transfer): Register IBC denom on transfer May 28, 2024
@danwt
Copy link
Contributor

danwt commented May 28, 2024

e2e tests fail, is this the version mismatch that @omritoptix mentioned in today's standup?

Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

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

Architecturally:
I wonder if we can do better by decoupling the memo protection from the denom metadata concepts. We have here a package called 'transferinject' which is quite abstract and general sounding but it only specifically supports this denom metadata memo stuff

Happy to merge like that and improve later though

Security and tests

Need to test and define correct behavior for

  1. memo not included and denom meta not included (happy A)
  2. memo not included and denom meta already sent and acked (happy B)
    2.5) memo not included and denom meta already sent but not acked
  3. memo included and denom meta not included (attack)
  4. memo included and denom meta already sent and acked (attack)

etc

app/app.go Outdated Show resolved Hide resolved
x/delayedack/ibc_middleware.go Outdated Show resolved Hide resolved
x/delayedack/ibc_middleware.go Outdated Show resolved Hide resolved
x/delayedack/ibc_middleware.go Outdated Show resolved Hide resolved
x/delayedack/ibc_middleware.go Outdated Show resolved Hide resolved
x/transferinject/keeper/keeper.go Outdated Show resolved Hide resolved
x/transferinject/keeper/keeper.go Outdated Show resolved Hide resolved
x/transferinject/types/expected_keepers.go Outdated Show resolved Hide resolved
x/transferinject/types/packet_metadata.go Outdated Show resolved Hide resolved
x/transferinject/keeper/keeper.go Outdated Show resolved Hide resolved
@danwt
Copy link
Contributor

danwt commented May 28, 2024

also please stop adding 'failed to' etc to errors 😄

@danwt
Copy link
Contributor

danwt commented May 28, 2024

Btw does any proto for old messages/tx need to be deprecated? And the corresponding generated code?

app/app.go Outdated Show resolved Hide resolved
x/transferinject/keeper/keeper.go Outdated Show resolved Hide resolved
app/app.go Outdated Show resolved Hide resolved
@zale144
Copy link
Contributor Author

zale144 commented May 29, 2024

also please stop adding 'failed to' etc to errors 😄

ikr, it's a habit. Probably coming from some baggage from my upbringing. "I'm not only an error, but also a failure" 😭

app/app.go Show resolved Hide resolved
app/app.go Show resolved Hide resolved
app/app.go Outdated Show resolved Hide resolved
Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

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

approved pending resolution to Michaels comments

proto/dymension/rollapp/rollapp.proto 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: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 983dd90 and 5a66d6b.

Files ignored due to path filters (1)
  • x/rollapp/types/rollapp.pb.go is excluded by !**/*.pb.go
Files selected for processing (24)
  • CHANGELOG.md (1 hunks)
  • app/app.go (8 hunks)
  • ibctesting/delayed_ack_test.go (2 hunks)
  • ibctesting/eibc_test.go (4 hunks)
  • ibctesting/utils_test.go (2 hunks)
  • proto/dymension/rollapp/rollapp.proto (1 hunks)
  • testutil/keeper/delayedack.go (2 hunks)
  • testutil/keeper/rollapp.go (2 hunks)
  • x/delayedack/eibc.go (3 hunks)
  • x/delayedack/ibc_middleware.go (16 hunks)
  • x/delayedack/keeper/fraud_test.go (2 hunks)
  • x/delayedack/keeper/invariants_test.go (2 hunks)
  • x/delayedack/keeper/keeper.go (6 hunks)
  • x/delayedack/keeper/params_test.go (1 hunks)
  • x/delayedack/rollapp_hooks.go (2 hunks)
  • x/delayedack/types/expected_keepers.go (2 hunks)
  • x/eibc/genesis_test.go (1 hunks)
  • x/rollapp/keeper/keeper.go (4 hunks)
  • x/rollapp/keeper/util.go (1 hunks)
  • x/transferinject/ibc_middleware.go (1 hunks)
  • x/transferinject/ibc_middleware_test.go (1 hunks)
  • x/transferinject/types/codec.go (1 hunks)
  • x/transferinject/types/expected_keepers.go (1 hunks)
  • x/transferinject/types/packet_metadata.go (1 hunks)
Files skipped from review due to trivial changes (4)
  • testutil/keeper/rollapp.go
  • x/delayedack/keeper/params_test.go
  • x/eibc/genesis_test.go
  • x/transferinject/types/codec.go
Additional context used
LanguageTool
CHANGELOG.md

[uncategorized] ~85-~85: Do not mix variants of the same word (‘acknowledgement’ and ‘acknowledgment’) within a single text. (EN_WORD_COHERENCY)
Context: ....com//issues/822) Acknowledgement not written in case of ackerr - (rollap...

Additional comments not posted (29)
x/transferinject/types/expected_keepers.go (1)

16-22: Confirm the usage of ExtractRollappFromChannel method.

Verification successful

The ExtractRollappFromChannel method is consistently implemented and used across the codebase. Here are the key points:

  • The method is implemented in x/rollapp/keeper/util.go and correctly matches the interface definition.
  • It is used in x/transferinject/ibc_middleware.go to handle IBC transfers.
  • A mock implementation is provided in x/transferinject/ibc_middleware_test.go for testing purposes.

No issues were found with the addition of this method.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `ExtractRollappFromChannel` method across the codebase.

# Test: Search for the method usage. Expect: Consistent usage across the codebase.
rg --type go $'ExtractRollappFromChannel'

Length of output: 831



Script:

#!/bin/bash
# Extract the implementation of ExtractRollappFromChannel in util.go
ast-grep --lang go --pattern $'func (k Keeper) ExtractRollappFromChannel($_, $_, $_) ($_, $_) {
  $$$
}' x/rollapp/keeper/util.go

# Extract the usage of ExtractRollappFromChannel in ibc_middleware.go
rg --context 5 --type go $'ExtractRollappFromChannel' x/transferinject/ibc_middleware.go

# Extract the usage of ExtractRollappFromChannel in ibc_middleware_test.go
rg --context 5 --type go $'ExtractRollappFromChannel' x/transferinject/ibc_middleware_test.go

Length of output: 3146

x/delayedack/rollapp_hooks.go (2)

19-19: Ensure correct logic in AfterStateFinalized.

Verification successful

Ensure correct logic in AfterStateFinalized.


Ensure correct logic in AfterStateFinalized.


The AfterStateFinalized method in x/delayedack/rollapp_hooks.go correctly finalizes the rollapp packets by calculating the stateEndHeight and calling im.FinalizeRollappPackets. The method appears to interact properly with other components based on the extracted implementation.

  • x/delayedack/rollapp_hooks.go:16-20: Implementation of AfterStateFinalized.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the logic in `AfterStateFinalized` method.

# Test: Search for the method usage and related logic. Expect: Correct interaction with other components.
rg --type go $'AfterStateFinalized'

Length of output: 1035



Script:

#!/bin/bash
# Description: Verify the implementation details of `AfterStateFinalized` method in `x/delayedack/rollapp_hooks.go`.

# Extract the implementation of `AfterStateFinalized` method.
ast-grep --lang go --pattern $'func (im IBCMiddleware) AfterStateFinalized(ctx sdk.Context, rollappID string, stateInfo *rollapptypes.StateInfo) error {
  $$$
}' > after_state_finalized_impl.txt

# Extract the usage of `AfterStateFinalized` method in other files.
rg --type go 'AfterStateFinalized' > after_state_finalized_usage.txt

Length of output: 197



Script:

#!/bin/bash
# Description: Verify the implementation details of `AfterStateFinalized` method in `x/delayedack/rollapp_hooks.go`.

# Extract the implementation of `AfterStateFinalized` method.
ast-grep --lang go --pattern $'func (im IBCMiddleware) AfterStateFinalized(ctx sdk.Context, rollappID string, stateInfo *rollapptypes.StateInfo) error {
  $$$
}' x/delayedack/rollapp_hooks.go

# Extract the usage of `AfterStateFinalized` method in other files.
rg --type go 'AfterStateFinalized' > after_state_finalized_usage.txt

Length of output: 724


23-23: Confirm the handling of fraud detection in FraudSubmitted.

Verification successful

The HandleFraud method in x/delayedack/keeper/fraud.go correctly handles fraud detection by reverting pending IBC rollapp packets and updating their status to reverted. This confirms that the FraudSubmitted method in x/delayedack/rollapp_hooks.go appropriately handles fraud detection by calling HandleFraud.

  • x/delayedack/keeper/fraud.go:
    • The HandleFraud method retrieves pending packets, logs the fraud event, iterates over the packets to revert them, and updates their status to reverted.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the handling of fraud detection in `FraudSubmitted` method.

# Test: Search for the method usage and related logic. Expect: Correct fraud detection mechanisms.
rg --type go $'FraudSubmitted'

Length of output: 1062



Script:

#!/bin/bash
# Extract the definition and implementation of FraudSubmitted in x/delayedack/rollapp_hooks.go
ast-grep --lang go --pattern $'func (im IBCMiddleware) FraudSubmitted(ctx sdk.Context, rollappID string, height uint64, seqAddr string) error {
  $$$
}' x/delayedack/rollapp_hooks.go

# Extract the definition and implementation of FraudSubmitted in x/rollapp/types/hooks.go
ast-grep --lang go --pattern $'func (h MultiRollappHooks) FraudSubmitted(ctx sdk.Context, rollappID string, height uint64, seqAddr string) error {
  $$$
}' x/rollapp/types/hooks.go

# Extract the usage of FraudSubmitted in x/rollapp/keeper/fraud_handler.go
rg --context 5 'FraudSubmitted' x/rollapp/keeper/fraud_handler.go

# Extract the implementation of FraudSubmitted in x/sequencer/keeper/hook_listener.go
ast-grep --lang go --pattern $'func (hook rollapphook) FraudSubmitted(ctx sdk.Context, rollappID string, height uint64, seqAddr string) error {
  $$$
}' x/sequencer/keeper/hook_listener.go

# Extract the test cases for FraudSubmitted in x/sequencer/keeper/hooks_test.go
rg --context 5 'FraudSubmitted' x/sequencer/keeper/hooks_test.go

Length of output: 3631



Script:

#!/bin/bash
# Extract the definition and implementation of HandleFraud in x/delayedack/rollapp_hooks.go
ast-grep --lang go --pattern $'func (im IBCMiddleware) HandleFraud(ctx sdk.Context, rollappID string, module string) error {
  $$$
}' x/delayedack/rollapp_hooks.go

Length of output: 164



Script:

#!/bin/bash
# Search for the definition of HandleFraud in the entire codebase
rg 'func (im IBCMiddleware) HandleFraud' --type go

Length of output: 52



Script:

#!/bin/bash
# Search for any method containing the term Fraud in the entire codebase
rg 'func .*Fraud' --type go

Length of output: 4257



Script:

#!/bin/bash
# Extract the definition and implementation of HandleFraud in x/delayedack/keeper/fraud.go
ast-grep --lang go --pattern $'func (k Keeper) HandleFraud(ctx sdk.Context, rollappID string, ibc porttypes.IBCModule) error {
  $$$
}' x/delayedack/keeper/fraud.go

Length of output: 3006

x/transferinject/types/packet_metadata.go (3)

12-23: Confirm the structure and validation logic of TransferInject.

Verification successful

The TransferInject structure and its validation logic appear to be correctly defined and used in the codebase. The ValidateBasic method calls Validate on the DenomMetadata field, which is consistent with the expected behavior. Additionally, the references to TransferInject in error handling and parsing packet metadata indicate that it is integrated into the codebase as intended.

  • TransferInject structure is defined with a DenomMetadata field.
  • ValidateBasic method calls Validate on DenomMetadata.
  • TransferInject is used in error handling and parsing packet metadata.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the structure and validation logic of `TransferInject`.

# Test: Search for the structure usage and validation logic. Expect: Correct structure definition and validation.
rg --type go $'TransferInject'

Length of output: 1610


58-74: Confirm the logic for adding denom metadata to memo in AddDenomMetadataToMemo.

Verification successful

The logic for adding denom metadata to memo in AddDenomMetadataToMemo appears to be correctly implemented and integrated based on the following observations:

  • Implementation in packet_metadata.go:

    • The function checks if the memo already contains a transfer inject object and returns an error if it does.
    • It adds the denom metadata to the memo and marshals it back to a string.
  • Usage in ibc_middleware_test.go:

    • The helper function addDenomMetadataToPacketData uses AddDenomMetadataToMemo to add metadata to the memo, indicating that the function is tested.
  • Usage in ibc_middleware.go:

    • The function is used to add metadata to the packet memo before sending it, and errors are appropriately handled.

The logic for adding denom metadata to memo in AddDenomMetadataToMemo is verified to be correct.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the logic for adding denom metadata to memo in `AddDenomMetadataToMemo`.

# Test: Search for the function usage and related logic. Expect: Correct metadata addition.
rg --type go $'AddDenomMetadataToMemo'

Length of output: 376



Script:

#!/bin/bash
# Description: Review the usage of AddDenomMetadataToMemo in ibc_middleware_test.go and ibc_middleware.go

# Extract the relevant lines from ibc_middleware_test.go
rg -A 10 -B 10 'AddDenomMetadataToMemo' x/transferinject/ibc_middleware_test.go

# Extract the relevant lines from ibc_middleware.go
rg -A 10 -B 10 'AddDenomMetadataToMemo' x/transferinject/ibc_middleware.go

Length of output: 1638


32-45: Ensure correct error handling in ParsePacketMetadata and MemoAlreadyHasPacketMetadata.

Verification successful

The error handling in ParsePacketMetadata and MemoAlreadyHasPacketMetadata functions is correctly implemented.

  • In x/transferinject/ibc_middleware.go, errors from ParsePacketMetadata are checked and handled appropriately.
  • In x/delayedack/eibc.go, specific errors from ParsePacketMetadata are checked and handled.
  • The return value of MemoAlreadyHasPacketMetadata is checked, and an error is returned if the memo already has packet metadata.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the error handling in `ParsePacketMetadata` and `MemoAlreadyHasPacketMetadata`.

# Test: Search for the functions usage and related error handling. Expect: Proper error handling mechanisms.
rg --type go $'ParsePacketMetadata|MemoAlreadyHasPacketMetadata'

Length of output: 733



Script:

#!/bin/bash
# Description: Verify the error handling in the usage of `ParsePacketMetadata`.

# Check error handling in `x/transferinject/ibc_middleware.go`
rg -A 5 'ParsePacketMetadata' x/transferinject/ibc_middleware.go

# Check error handling in `x/delayedack/eibc.go`
rg -A 5 'ParsePacketMetadata' x/delayedack/eibc.go

Length of output: 576


Script:

#!/bin/bash
# Description: Verify the usage of `MemoAlreadyHasPacketMetadata`.

# Check usage in `x/transferinject/ibc_middleware.go`
rg -A 5 'MemoAlreadyHasPacketMetadata' x/transferinject/ibc_middleware.go

Length of output: 302

x/delayedack/types/expected_keepers.go (1)

41-46: Confirm the usage of ExtractRollappIDAndTransferPacketFromData method.

Verification successful

The method ExtractRollappIDAndTransferPacketFromData is implemented in x/rollapp/keeper/util.go and is used in x/delayedack/ibc_middleware.go and testutil/keeper/delayedack.go. The implementation aligns with its intended purpose, and the usage appears consistent across the codebase.

  • Implementation in x/rollapp/keeper/util.go:

    func (k Keeper) ExtractRollappIDAndTransferPacketFromData(
        ctx sdk.Context,
        data []byte,
        rollappPortOnHub string,
        rollappChannelOnHub string,
    ) (string, *transfertypes.FungibleTokenPacketData, error) {
        // no-op if the packet is not a fungible token packet
        packet := new(transfertypes.FungibleTokenPacketData)
        if err := types.ModuleCdc.UnmarshalJSON(data, packet); err != nil {
            return "", packet, errorsmod.Wrapf(err, "unmarshal packet data")
        }
    
        rollapp, err := k.ExtractRollappFromChannel(ctx, rollappPortOnHub, rollappChannelOnHub)
        if err != nil {
            return "", packet, err
        }
    
        if rollapp == nil {
            return "", packet, nil
        }
    
        return rollapp.RollappId, packet, nil
    }
  • Usage in x/delayedack/ibc_middleware.go:

    rollappID, transferPacketData, err := im.rollappKeeper.ExtractRollappIDAndTransferPacketFromData(
        ctx, packet.Data, rollappPortOnHub, rollappChannelOnHub)
  • Usage in testutil/keeper/delayedack.go:

    func (r RollappKeeperStub) ExtractRollappIDAndTransferPacketFromData(sdk.Context, []byte, string, string) (string, *transfertypes.FungibleTokenPacketData, error) {
        // Stub implementation
    }

The method is correctly implemented and used consistently across the codebase.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `ExtractRollappIDAndTransferPacketFromData` method across the codebase.

# Test: Search for the method usage. Expect: Consistent usage across the codebase.
rg --type go $'ExtractRollappIDAndTransferPacketFromData'

Length of output: 997



Script:

#!/bin/bash
# Description: Verify the implementation and usage of `ExtractRollappIDAndTransferPacketFromData`.

# Test: Retrieve the implementation of the method in `x/rollapp/keeper/util.go`.
ast-grep --lang go --pattern $'func (k Keeper) ExtractRollappIDAndTransferPacketFromData($_, $_, $_, $_) ($_ , $_, $_) {
  $$$
}' --json

# Test: Retrieve the usage of the method in `x/delayedack/ibc_middleware.go`.
rg --type go $'ExtractRollappIDAndTransferPacketFromData' x/delayedack/ibc_middleware.go

# Test: Retrieve the usage of the method in `testutil/keeper/delayedack.go`.
rg --type go $'ExtractRollappIDAndTransferPacketFromData' testutil/keeper/delayedack.go

Length of output: 2581

proto/dymension/rollapp/rollapp.proto (1)

44-45: Confirm the usage of registeredDenoms field in Rollapp message.

Verification successful

The registeredDenoms field in the Rollapp message is consistently used across the codebase, including in the Go files. The field is integrated and utilized correctly in various parts of the system.

  • proto/dymension/rollapp/rollapp.proto: Field definition.
  • x/rollapp/types/rollapp.pb.go: Field usage and related methods.
  • x/transferinject/ibc_middleware.go: Field usage in middleware logic.
  • x/transferinject/ibc_middleware_test.go: Field usage in tests.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `registeredDenoms` field in `Rollapp` message across the codebase.

# Test: Search for the field usage. Expect: Consistent usage across the codebase.
rg --type proto $'registeredDenoms'

Length of output: 64



Script:

#!/bin/bash
# Description: Verify the usage of `registeredDenoms` field in `Rollapp` message across the codebase.

# Test: Search for the field usage. Expect: Consistent usage across the codebase.
rg 'registeredDenoms'

Length of output: 449



Script:

#!/bin/bash
# Description: Verify the usage of `registeredDenoms` field in Go code.

# Test: Search for the field usage in Go files. Expect: Consistent usage across the codebase.
rg 'RegisteredDenoms' --type go

Length of output: 1845

x/rollapp/keeper/util.go (2)

14-38: Ensure correct implementation of ExtractRollappIDAndTransferPacketFromData.

Verification successful

The function ExtractRollappIDAndTransferPacketFromData is used in multiple contexts within the codebase, including x/delayedack/ibc_middleware.go, x/delayedack/types/expected_keepers.go, and testutil/keeper/delayedack.go. The usages appear to be consistent with the function's purpose of extracting rollapp ID and fungible token packet data.

  • In x/delayedack/ibc_middleware.go, the function is used to extract rollapp ID and transfer packet data from the packet data.
  • In x/delayedack/types/expected_keepers.go, the function is declared as part of the expected keeper interface.
  • In testutil/keeper/delayedack.go, a stub implementation of the function is provided for testing purposes.

These usages indicate that the function is correctly integrated and utilized within the codebase.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `ExtractRollappIDAndTransferPacketFromData`.

# Test: Search for the function usage and related logic. Expect: Correct implementation and interaction with other components.
rg --type go $'ExtractRollappIDAndTransferPacketFromData'

Length of output: 997



Script:

#!/bin/bash
# Description: Verify the context and correctness of `ExtractRollappIDAndTransferPacketFromData` usage.

# Check the context in `x/delayedack/ibc_middleware.go`
echo "Context in x/delayedack/ibc_middleware.go:"
rg --context 5 --type go $'ExtractRollappIDAndTransferPacketFromData' x/delayedack/ibc_middleware.go

# Check the context in `x/delayedack/types/expected_keepers.go`
echo "Context in x/delayedack/types/expected_keepers.go:"
rg --context 5 --type go $'ExtractRollappIDAndTransferPacketFromData' x/delayedack/types/expected_keepers.go

# Check the context in `testutil/keeper/delayedack.go`
echo "Context in testutil/keeper/delayedack.go:"
rg --context 5 --type go $'ExtractRollappIDAndTransferPacketFromData' testutil/keeper/delayedack.go

Length of output: 2854


40-70: Confirm the logic and error handling in ExtractRollappFromChannel.

Verification successful

To verify the logic and error handling in the ExtractRollappFromChannel function and its usage in other files, we need to inspect the relevant code sections. Let's start by examining the function itself and then proceed to check its usage in the identified files.


The logic and error handling in the ExtractRollappFromChannel function appear to be well-defined, with multiple checks and appropriate error returns. The function is used in several places, and the error handling in these usages also seems to be correctly implemented.

Key Points:

  • Function Definition: The ExtractRollappFromChannel function has multiple error checks and returns appropriate errors or nil values based on the conditions.
  • Usage in x/transferinject/types/expected_keepers.go: The function is declared in an interface, which is standard and does not involve error handling.
  • Usage in x/transferinject/ibc_middleware_test.go: The function is mocked for testing purposes, returning predefined values.
  • Usage in x/transferinject/ibc_middleware.go: The function is used twice, and in both cases, errors are appropriately wrapped and returned.

Conclusion:

The logic and error handling in the ExtractRollappFromChannel function and its usage in other files are correctly implemented.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the logic and error handling in `ExtractRollappFromChannel`.

# Test: Search for the function usage and related logic. Expect: Correct error handling and logic.
rg --type go $'ExtractRollappFromChannel'

Length of output: 831



Script:

#!/bin/bash
# Description: Verify the logic and error handling in `ExtractRollappFromChannel` and its usage in other files.

# Extract the `ExtractRollappFromChannel` function definition for detailed inspection.
ast-grep --lang go --pattern $'func (k Keeper) ExtractRollappFromChannel($_, $_, $_) ($_, $_) {
  $$$
}' x/rollapp/keeper/util.go

# Extract the usage of `ExtractRollappFromChannel` in `x/transferinject/types/expected_keepers.go`.
rg --context 5 --type go 'ExtractRollappFromChannel' x/transferinject/types/expected_keepers.go

# Extract the usage of `ExtractRollappFromChannel` in `x/transferinject/ibc_middleware_test.go`.
rg --context 5 --type go 'ExtractRollappFromChannel' x/transferinject/ibc_middleware_test.go

# Extract the usage of `ExtractRollappFromChannel` in `x/transferinject/ibc_middleware.go`.
rg --context 5 --type go 'ExtractRollappFromChannel' x/transferinject/ibc_middleware.go

Length of output: 3547

x/delayedack/keeper/fraud_test.go (2)

13-14: Changes align with the new architecture requiring rollappKeeper.


50-51: Changes align with the new architecture requiring rollappKeeper.

testutil/keeper/delayedack.go (1)

118-120: Addition of ExtractRollappIDAndTransferPacketFromData correctly mirrors changes in the RollappKeeper interface.

x/rollapp/keeper/keeper.go (1)

162-168: Addition of SetTransferKeeper is crucial for setting the TransferKeeper. Consider adding a comment to clarify that this is a required call, as suggested in a previous review.

x/delayedack/eibc.go (1)

46-48: Enhancements in error handling and security checks improve the robustness and security of eIBC demand order handling.

Also applies to: 67-67, 89-89

x/transferinject/ibc_middleware.go (1)

19-97: Addition of IBCSendMiddleware and IBCAckMiddleware is crucial for the new feature of injecting metadata into IBC packets.

Also applies to: 99-165

x/delayedack/keeper/keeper.go (3)

19-19: Added import for log from tendermint/tendermint/libs.

This import is necessary for logging within the keeper functions, enhancing debuggability and traceability.


33-35: Added rollappKeeper and sequencerKeeper to the Keeper struct.

This change aligns with the PR's objective to integrate rollappKeeper for managing rollapp-related operations and sequencerKeeper for handling sequencer-specific logic.


67-67: Refactored ics4Wrapper to ICS4Wrapper.

This change improves the consistency of naming conventions in the codebase, aligning with Go's convention of using CamelCase for exported identifiers.

x/delayedack/keeper/invariants_test.go (1)

18-19: LGTM! Ensure that the new rollappKeeper parameter is integrated correctly throughout the codebase.

Verification successful

The NewIBCMiddleware function is used with the rollappKeeper parameter in all instances found. Let's verify the correctness of the rollappKeeper parameter usage in the app/app.go file to ensure it is integrated correctly.


The rollappKeeper parameter is correctly integrated into the NewIBCMiddleware function call in the app/app.go file. The parameter is used consistently across all instances found in the codebase.

  • x/delayedack/keeper/invariants_test.go
  • x/delayedack/keeper/fraud_test.go
  • app/app.go
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new `rollappKeeper` parameter is used correctly in all relevant function calls.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'NewIBCMiddleware'

Length of output: 960



Script:

#!/bin/bash
# Description: Verify the usage of the `rollappKeeper` parameter in the `app/app.go` file.

# Test: Display the relevant lines in the `app/app.go` file.
rg --type go --context 5 $'NewIBCMiddleware' app/app.go

Length of output: 863

ibctesting/delayed_ack_test.go (1)

29-31: LGTM! Ensure that the denom metadata set here is utilized correctly in the tests.

Verification successful

The denom metadata set by SetDenomMetaData in SetupTest is indeed utilized in the tests within ibctesting/delayed_ack_test.go. The metadata for sdk.DefaultBondDenom is referenced multiple times, ensuring that the setup is correctly influencing the test cases.

  • ibctesting/delayed_ack_test.go: The metadata for sdk.DefaultBondDenom is used in various test assertions and operations.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the denom metadata set in `SetupTest` is utilized correctly in the tests.

# Test: Search for the metadata usage in tests. Expect: Metadata should be utilized in relevant tests.
rg --type go $'SetDenomMetaData'

Length of output: 1247



Script:

#!/bin/bash
# Description: Verify that the denom metadata set in `SetupTest` is utilized correctly in the tests.

# Test: Search for the usage of the metadata set by `SetDenomMetaData` in the relevant test files.
rg --type go 'sdk.DefaultBondDenom' ibctesting/delayed_ack_test.go

Length of output: 834

x/delayedack/ibc_middleware.go (2)

23-32: LGTM! The integration of rollappKeeper in the IBCMiddleware struct and its constructor is well-implemented.


Line range hint 43-102: Ensure that the new rollappKeeper methods are used correctly in packet handling.

Also applies to: 124-191, 216-282

Verification successful

To ensure the new rollappKeeper methods are used correctly in packet handling, we need to verify the definitions and usages of the following methods: ExtractRollappIDAndTransferPacketFromData, ValidateRollappId, GetProofHeight, and CheckIfFinalized.


The methods ExtractRollappIDAndTransferPacketFromData, ValidateRollappId, GetProofHeight, and CheckIfFinalized are defined and used in the relevant files. The definitions and usages align with the expected functionality in the packet handling process.

  • ExtractRollappIDAndTransferPacketFromData is defined in x/rollapp/keeper/util.go and used in x/delayedack/ibc_middleware.go.
  • ValidateRollappId is defined in x/delayedack/keeper/keeper.go and used in x/delayedack/ibc_middleware.go.
  • GetProofHeight is defined in x/delayedack/ibc_middleware.go and used in the same file.
  • CheckIfFinalized is defined in x/delayedack/ibc_middleware.go and used in the same file.

The methods are used correctly in the packet handling functions, ensuring proper extraction, validation, proof height retrieval, and finalization checks.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the new `rollappKeeper` methods are used correctly in packet handling functions.

# Test: Search for the usage of `rollappKeeper` methods in packet handling. Expect: Methods should be used correctly.
rg --type go $'rollappKeeper'

Length of output: 7749



Script:

#!/bin/bash
# Description: Verify the correct usage of `rollappKeeper` methods in packet handling functions.

# Search for the definition and usage of `ExtractRollappIDAndTransferPacketFromData`
rg --type go 'ExtractRollappIDAndTransferPacketFromData'

# Search for the definition and usage of `ValidateRollappId`
rg --type go 'ValidateRollappId'

# Search for the definition and usage of `GetProofHeight`
rg --type go 'GetProofHeight'

# Search for the definition and usage of `CheckIfFinalized`
rg --type go 'CheckIfFinalized'

Length of output: 3150

ibctesting/utils_test.go (1)

27-27: LGTM! The update to use eibctypes.ModuleCdc for unmarshalling is correctly implemented.

Verification successful

The eibctypes.ModuleCdc.UnmarshalJSON method is used in two locations: ibctesting/utils_test.go and ibctesting/eibc_test.go. Let's verify the correctness of its usage in these files.


The eibctypes.ModuleCdc.UnmarshalJSON method is used correctly in both ibctesting/utils_test.go and ibctesting/eibc_test.go. The method is used to unmarshal JSON data into the transfertypes.FungibleTokenPacketData struct, and error handling is appropriately implemented.

  • ibctesting/utils_test.go: The method is used within the GetRollappToHubIBCDenomFromPacket function, and the error is checked using suite.Require().NoError(err).
  • ibctesting/eibc_test.go: The method is used to unmarshal data from rollappPacket.Packet.GetData(), and the error is checked using suite.Require().NoError(err).

Both usages are consistent with the expected behavior for unmarshalling JSON data.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `eibctypes.ModuleCdc.UnmarshalJSON` method is used correctly in the tests.

# Test: Search for the usage of `eibctypes.ModuleCdc.UnmarshalJSON`. Expect: Method should be used correctly.
rg --type go $'eibctypes.ModuleCdc.UnmarshalJSON'

Length of output: 246



Script:

#!/bin/bash
# Description: Display the context around the usage of `eibctypes.ModuleCdc.UnmarshalJSON` in the identified files.

# Display the relevant lines in `ibctesting/utils_test.go`
rg --type go --context 5 'eibctypes.ModuleCdc.UnmarshalJSON' ibctesting/utils_test.go

# Display the relevant lines in `ibctesting/eibc_test.go`
rg --type go --context 5 'eibctypes.ModuleCdc.UnmarshalJSON' ibctesting/eibc_test.go

Length of output: 1214

CHANGELOG.md (1)

51-51: LGTM! The changelog correctly summarizes the changes made in this PR.

app/app.go (4)

622-633: Ensure correct integration of NewIBCSendMiddleware in TransferKeeper.

The integration of NewIBCSendMiddleware with TransferKeeper appears correctly implemented. This middleware is crucial for handling IBC send operations with additional logic for denom registration, aligning with the PR's objectives.


754-755: Review the integration of NewIBCAckMiddleware with delayedAckMiddleware.

The chaining of NewIBCAckMiddleware with delayedAckMiddleware is correctly implemented. This setup is essential for handling acknowledgments in the IBC middleware stack, ensuring that the Rollapp's state is correctly updated upon packet acknowledgment.


635-635: Confirm SetTransferKeeper usage.

Verification successful

The SetTransferKeeper method is correctly implemented in x/rollapp/keeper/keeper.go and is used appropriately in app/app.go.

  • The method ensures that the transferKeeper is not set twice by checking if it is already set and panicking if it is.
  • The usage in app/app.go is consistent with the method's purpose, setting the TransferKeeper for RollappKeeper.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if `SetTransferKeeper` is used correctly across the codebase.

# Test: Search for `SetTransferKeeper` usage. Expect: Correct and consistent usage across the codebase.
rg --type go $'SetTransferKeeper'

Length of output: 282



Script:

#!/bin/bash
# Description: Verify the implementation of `SetTransferKeeper` in `x/rollapp/keeper/keeper.go` and its usage in `app/app.go`.

# Extract the implementation of `SetTransferKeeper` from `x/rollapp/keeper/keeper.go`
ast-grep --lang go --pattern $'func (k *Keeper) SetTransferKeeper($_) { $$$ }' --json

# Extract the relevant code around the usage of `SetTransferKeeper` in `app/app.go`
rg --context 5 'SetTransferKeeper' app/app.go

Length of output: 1054


767-767: Clarify the role of delayedAckMiddleware in SetHooks.

Verification successful

The delayedAckMiddleware is instantiated using the NewIBCMiddleware function from the delayedackmodule package, which initializes an IBCMiddleware struct with IBCModule, Keeper, and rollappKeeper. This middleware is then passed to the NewIBCAckMiddleware function from the transferinject package, which initializes an IBCAckMiddleware struct with IBCModule and rollappKeeper.

  • delayedAckMiddleware is created in app/app.go using delayedackmodule.NewIBCMiddleware.
  • It is then used in transferinject.NewIBCAckMiddleware.

The role of delayedAckMiddleware in SetHooks is to act as a middleware component in the IBC (Inter-Blockchain Communication) stack, likely handling delayed acknowledgments in the communication process.

  • delayedackmodule.NewIBCMiddleware definition: ./x/delayedack/ibc_middleware.go:28
  • transferinject.NewIBCAckMiddleware definition: ./x/transferinject/ibc_middleware.go:108
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the role and impact of `delayedAckMiddleware` in the system.

# Test: Search for `delayedAckMiddleware` usage and its impact on system behavior. Expect: Clear understanding and documentation of its role.
rg --type go $'delayedAckMiddleware'

Length of output: 300



Script:

#!/bin/bash
# Locate the definition of `NewIBCMiddleware` in the `delayedackmodule` package
ast-grep --lang go --pattern 'func NewIBCMiddleware($_, $_, $_) $_' 

# Locate the definition of `NewIBCAckMiddleware` in the `transferinject` package
ast-grep --lang go --pattern 'func NewIBCAckMiddleware($_, $_) $_' 

# Find all usages of `delayedAckMiddleware` in the codebase to understand its context
rg 'delayedAckMiddleware'

Length of output: 1463

Comment on lines 237 to 239
// //
// Transfer initial IBC funds to fulfiller account with ibc memo, to give him some funds to use to fulfill stuff
////
// //
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove commented-out code.

Commented-out code can clutter the codebase and make maintenance harder. If this code is not needed, it should be removed to keep the codebase clean.

CHANGELOG.md Show resolved Hide resolved
Comment on lines 22 to 166
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("thanks for the sweater, grandma!", validDenomMetadata),
}),
}, {
name: "error: denom metadata already in memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: `{"transferinject":{}}`,
},
wantSentData: []byte(""),
wantErr: types.ErrMemoTransferInjectAlreadyExists,
}, {
name: "error: extract rollapp from channel",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
err: errortypes.ErrInvalidRequest,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: []byte(""),
wantErr: errortypes.ErrInvalidRequest,
}, {
name: "send unaltered: rollapp not found",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
}),
}, {
name: "send unaltered: denom metadata already in rollapp",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{
RegisteredDenoms: []string{"adym"},
},
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
}, {
name: "error: get denom metadata",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := transferinject.NewIBCSendMiddleware(tt.fields.ICS4Wrapper, tt.fields.rollappKeeper, tt.fields.bankKeeper)

data := types.ModuleCdc.MustMarshalJSON(tt.data)

_, err := m.SendPacket(
sdk.Context{},
&capabilitytypes.Capability{},
"transfer",
"channel-0",
clienttypes.Height{},
0,
data,
)
if tt.wantErr == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tt.wantErr)
}
require.Equal(t, string(tt.wantSentData), string(tt.fields.ICS4Wrapper.(*mockICS4Wrapper).sentData))
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling uses errors.Is for consistency and clarity.

- require.ErrorIs(t, err, tt.wantErr)
+ require.True(t, errors.Is(err, tt.wantErr))
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func TestIBCMiddleware_SendPacket(t *testing.T) {
type fields struct {
ICS4Wrapper porttypes.ICS4Wrapper
rollappKeeper types.RollappKeeper
bankKeeper types.BankKeeper
}
tests := []struct {
name string
fields fields
data *transfertypes.FungibleTokenPacketData
wantSentData []byte
wantErr error
}{
{
name: "success: added denom metadata to memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{
returnMetadata: validDenomMetadata,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("", validDenomMetadata),
}),
}, {
name: "success: added denom metadata to non-empty user memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{
returnMetadata: validDenomMetadata,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "thanks for the sweater, grandma!",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("thanks for the sweater, grandma!", validDenomMetadata),
}),
}, {
name: "error: denom metadata already in memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: `{"transferinject":{}}`,
},
wantSentData: []byte(""),
wantErr: types.ErrMemoTransferInjectAlreadyExists,
}, {
name: "error: extract rollapp from channel",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
err: errortypes.ErrInvalidRequest,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: []byte(""),
wantErr: errortypes.ErrInvalidRequest,
}, {
name: "send unaltered: rollapp not found",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
}),
}, {
name: "send unaltered: denom metadata already in rollapp",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{
RegisteredDenoms: []string{"adym"},
},
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
}, {
name: "error: get denom metadata",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := transferinject.NewIBCSendMiddleware(tt.fields.ICS4Wrapper, tt.fields.rollappKeeper, tt.fields.bankKeeper)
data := types.ModuleCdc.MustMarshalJSON(tt.data)
_, err := m.SendPacket(
sdk.Context{},
&capabilitytypes.Capability{},
"transfer",
"channel-0",
clienttypes.Height{},
0,
data,
)
if tt.wantErr == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tt.wantErr)
}
require.Equal(t, string(tt.wantSentData), string(tt.fields.ICS4Wrapper.(*mockICS4Wrapper).sentData))
})
}
}
if tt.wantErr == nil {
require.NoError(t, err)
} else {
require.True(t, errors.Is(err, tt.wantErr))
}

Improve subtest names to clearly describe what each test is verifying.

- name: "send unaltered: rollapp not found"
+ name: "send unaltered: rollapp not found should pass without alteration"
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func TestIBCMiddleware_SendPacket(t *testing.T) {
type fields struct {
ICS4Wrapper porttypes.ICS4Wrapper
rollappKeeper types.RollappKeeper
bankKeeper types.BankKeeper
}
tests := []struct {
name string
fields fields
data *transfertypes.FungibleTokenPacketData
wantSentData []byte
wantErr error
}{
{
name: "success: added denom metadata to memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{
returnMetadata: validDenomMetadata,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("", validDenomMetadata),
}),
}, {
name: "success: added denom metadata to non-empty user memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{
returnMetadata: validDenomMetadata,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "thanks for the sweater, grandma!",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("thanks for the sweater, grandma!", validDenomMetadata),
}),
}, {
name: "error: denom metadata already in memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: `{"transferinject":{}}`,
},
wantSentData: []byte(""),
wantErr: types.ErrMemoTransferInjectAlreadyExists,
}, {
name: "error: extract rollapp from channel",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
err: errortypes.ErrInvalidRequest,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: []byte(""),
wantErr: errortypes.ErrInvalidRequest,
}, {
name: "send unaltered: rollapp not found",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
}),
}, {
name: "send unaltered: denom metadata already in rollapp",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{
RegisteredDenoms: []string{"adym"},
},
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
}, {
name: "error: get denom metadata",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := transferinject.NewIBCSendMiddleware(tt.fields.ICS4Wrapper, tt.fields.rollappKeeper, tt.fields.bankKeeper)
data := types.ModuleCdc.MustMarshalJSON(tt.data)
_, err := m.SendPacket(
sdk.Context{},
&capabilitytypes.Capability{},
"transfer",
"channel-0",
clienttypes.Height{},
0,
data,
)
if tt.wantErr == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tt.wantErr)
}
require.Equal(t, string(tt.wantSentData), string(tt.fields.ICS4Wrapper.(*mockICS4Wrapper).sentData))
})
}
}
func TestIBCMiddleware_SendPacket(t *testing.T) {
type fields struct {
ICS4Wrapper porttypes.ICS4Wrapper
rollappKeeper types.RollappKeeper
bankKeeper types.BankKeeper
}
tests := []struct {
name string
fields fields
data *transfertypes.FungibleTokenPacketData
wantSentData []byte
wantErr error
}{
{
name: "success: added denom metadata to memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{
returnMetadata: validDenomMetadata,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("", validDenomMetadata),
}),
}, {
name: "success: added denom metadata to non-empty user memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{
returnMetadata: validDenomMetadata,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "thanks for the sweater, grandma!",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("thanks for the sweater, grandma!", validDenomMetadata),
}),
}, {
name: "error: denom metadata already in memo",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: `{"transferinject":{}}`,
},
wantSentData: []byte(""),
wantErr: types.ErrMemoTransferInjectAlreadyExists,
}, {
name: "error: extract rollapp from channel",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
err: errortypes.ErrInvalidRequest,
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: []byte(""),
wantErr: errortypes.ErrInvalidRequest,
}, {
name: "send unaltered: rollapp not found should pass without alteration",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
}),
}, {
name: "send unaltered: denom metadata already in rollapp",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{
RegisteredDenoms: []string{"adym"},
},
},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
}, {
name: "error: get denom metadata",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{},
},
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := transferinject.NewIBCSendMiddleware(tt.fields.ICS4Wrapper, tt.fields.rollappKeeper, tt.fields.bankKeeper)
data := types.ModuleCdc.MustMarshalJSON(tt.data)
_, err := m.SendPacket(
sdk.Context{},
&capabilitytypes.Capability{},
"transfer",
"channel-0",
clienttypes.Height{},
0,
data,
)
if tt.wantErr == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tt.wantErr)
}
require.Equal(t, string(tt.wantSentData), string(tt.fields.ICS4Wrapper.(*mockICS4Wrapper).sentData))
})
}
}

Comment on lines +76 to +77
if Contains(rollapp.RegisteredDenoms, packet.Denom) {
return m.ICS4Wrapper.SendPacket(ctx, chanCap, destinationPort, destinationChannel, timeoutHeight, timeoutTimestamp, data)
Copy link
Contributor

Choose a reason for hiding this comment

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

here you use packet.Denom but in the ack code you use base
Can it be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

packet.Denom is from the packet, but in the ack handler base is from the injected denom metadata, but essentially it's the same

@@ -41,12 +41,14 @@ message Rollapp {
repeated string permissionedAddresses = 5;
// tokenMetadata is a list of TokenMetadata that are registered on this rollapp
repeated TokenMetadata tokenMetadata = 6;
// registeredDenoms is a list of registered denoms on this rollapp
Copy link
Contributor

Choose a reason for hiding this comment

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

list of registered denoms

Is it a base or id or what?

@danwt
Copy link
Contributor

danwt commented Jun 4, 2024

Now that we only refer to the denom by a short string, what do we do if it get's updated in the bank? We need to ship the update or what?

Is this specced out/documented?

@zale144
Copy link
Contributor Author

zale144 commented Jun 4, 2024

Now that we only refer to the denom by a short string, what do we do if it get's updated in the bank? We need to ship the update or what?

Is this specced out/documented?

The base is the key, which doesn't get updated, but if anything else is updated, the base/key still references the same record in the bank

@zale144 zale144 requested review from mtsitrin and danwt June 4, 2024 12:37
@danwt
Copy link
Contributor

danwt commented Jun 4, 2024

So the rollapp wouldn't necessarily get the update then?

// At the first match, we assume that the rollapp already contains the metadata.
// It would be technically possible to have a race condition where the denom metadata is added to the rollapp
// from another packet before this packet is acknowledged.
if Contains(rollapp.RegisteredDenoms, packet.Denom) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@zale144 don't u need to validate it's not a token sourced from the rollapp? otherwise u register the rollapp's token as it represented on the hub, makes it wierdly duplicate record on the rollapp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the denom here is used as a key/reference, as it's found/represented on the hub (same one in the ack handler), just as an optimization, to avoid sending denom metadata in every packet. the point is to deduplicate on the hub.

Copy link
Contributor

Choose a reason for hiding this comment

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

the entire middleware should work only for tokens other than tokens sourced on the rollapp.

func ParsePacketMetadata(input string) (*TransferInject, error) {
bz := []byte(input)

var memo MemoData
Copy link
Contributor

Choose a reason for hiding this comment

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

@zale144 why sometimes u unmarshal into MemoData and sometimes into memoMap := make(map[string]any)

@danwt
Copy link
Contributor

danwt commented Jun 5, 2024

Could you please document the fact that the rollapp wont get updated if something is updated in the bank keeper but the base remains the same?

@danwt
Copy link
Contributor

danwt commented Jun 6, 2024

Conflicts

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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5a66d6b and 0e77001.

Files ignored due to path filters (1)
  • x/rollapp/types/rollapp.pb.go is excluded by !**/*.pb.go
Files selected for processing (3)
  • proto/dymension/rollapp/rollapp.proto (1 hunks)
  • x/transferinject/ibc_middleware.go (1 hunks)
  • x/transferinject/ibc_middleware_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • proto/dymension/rollapp/rollapp.proto
Files skipped from review as they are similar to previous changes (1)
  • x/transferinject/ibc_middleware.go

Comment on lines +22 to +220
rollappKeeper: &mockRollappKeeper{},
},
args: args{
destinationPort: "port",
destinationChannel: "channel",
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
},
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
}),
}, {
name: "send unaltered: receiver chain is source",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{
returnMetadata: validDenomMetadata,
},
},
args: args{
destinationPort: "transfer",
destinationChannel: "channel-56",
data: &transfertypes.FungibleTokenPacketData{
Denom: "transfer/channel-56/alex",
},
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "transfer/channel-56/alex",
}),
}, {
name: "send unaltered: denom metadata already in rollapp",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{
RegisteredDenoms: []string{"adym"},
},
},
},
args: args{
destinationPort: "port",
destinationChannel: "channel",
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
}, {
name: "error: get denom metadata",
fields: fields{
ICS4Wrapper: &mockICS4Wrapper{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{},
},
bankKeeper: mockBankKeeper{},
},
args: args{
destinationPort: "port",
destinationChannel: "channel",
data: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
},
},
wantSentData: types.ModuleCdc.MustMarshalJSON(&transfertypes.FungibleTokenPacketData{
Denom: "adym",
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := transferinject.NewIBCSendMiddleware(tt.fields.ICS4Wrapper, tt.fields.rollappKeeper, tt.fields.bankKeeper)

data := types.ModuleCdc.MustMarshalJSON(tt.args.data)

_, err := m.SendPacket(
sdk.Context{},
&capabilitytypes.Capability{},
tt.args.destinationPort,
tt.args.destinationChannel,
clienttypes.Height{},
0,
data,
)
if tt.wantErr == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tt.wantErr)
}
require.Equal(t, string(tt.wantSentData), string(tt.fields.ICS4Wrapper.(*mockICS4Wrapper).sentData))
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor test cases to improve clarity and maintainability.

  • Consider using table-driven tests with clearer names that describe the behavior being tested.
  • Use errors.Is for error comparisons to improve consistency and reliability.
- require.ErrorIs(t, err, tt.wantErr)
+ require.True(t, errors.Is(err, tt.wantErr))
  • Enhance test names to reflect the expected outcome or behavior being tested.
- name: "send unaltered: rollapp not found"
+ name: "send unaltered: rollapp not found should pass without alteration"

Comment on lines +222 to +400
IBCModule: mockIBCModule{},
},
args: args{
packetData: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: "user memo",
},
acknowledgement: okAck(),
},
wantRollapp: nil,
}, {
name: "return early: no denom metadata in memo",
fields: fields{
rollappKeeper: &mockRollappKeeper{},
IBCModule: mockIBCModule{},
},
args: args{
packetData: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: `{"transferinject":{}}`,
},
acknowledgement: okAck(),
},
wantRollapp: nil,
}, {
name: "error: extract rollapp from channel",
fields: fields{
IBCModule: mockIBCModule{},
rollappKeeper: &mockRollappKeeper{
err: errortypes.ErrInvalidRequest,
},
},
args: args{
packetData: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("", validDenomMetadata),
},
acknowledgement: okAck(),
},
wantRollapp: nil,
wantErr: errortypes.ErrInvalidRequest,
}, {
name: "error: rollapp not found",
fields: fields{
IBCModule: mockIBCModule{},
rollappKeeper: &mockRollappKeeper{},
},
args: args{
packetData: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("", validDenomMetadata),
},
acknowledgement: okAck(),
},
wantRollapp: nil,
wantErr: errortypes.ErrNotFound,
}, {
name: "return early: rollapp already has token metadata",
fields: fields{
IBCModule: mockIBCModule{},
rollappKeeper: &mockRollappKeeper{
returnRollapp: &rollapptypes.Rollapp{
RegisteredDenoms: []string{validDenomMetadata.Base},
},
},
},
args: args{
packetData: &transfertypes.FungibleTokenPacketData{
Denom: "adym",
Memo: addDenomMetadataToPacketData("", validDenomMetadata),
},
acknowledgement: okAck(),
},
wantRollapp: &rollapptypes.Rollapp{
RegisteredDenoms: []string{validDenomMetadata.Base},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := transferinject.NewIBCAckMiddleware(tt.fields.IBCModule, tt.fields.rollappKeeper)

packet := channeltypes.Packet{}

if tt.args.packetData != nil {
packet.Data = types.ModuleCdc.MustMarshalJSON(tt.args.packetData)
}

err := m.OnAcknowledgementPacket(sdk.Context{}, packet, tt.args.acknowledgement, sdk.AccAddress{})

if tt.wantErr == nil {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, tt.wantErr)
}

require.Equal(t, tt.wantRollapp, tt.fields.rollappKeeper.(*mockRollappKeeper).returnRollapp)
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent error handling and improve test case names in TestIBCMiddleware_OnAcknowledgementPacket.

  • Use errors.Is for error comparisons to ensure consistency across tests.
  • Improve test names to clearly describe the expected behavior or outcome.
- name: "return early: error acknowledgement"
+ name: "return early: error acknowledgement should handle errors gracefully"

Committable suggestion was skipped due to low confidence.

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

Outside diff range and nitpick comments (1)
x/bridging_fee/ibc_middleware.go (1)

Line range hint 31-64: Refactor BridgingFeeMiddleware to improve error handling and logging.

The implementation of OnRecvPacket could be improved by handling potential errors more gracefully and providing more detailed logging for debugging purposes. Consider adding more specific error messages and using structured logging to capture important packet and transaction details.

- logger.Error("Failed to extract rollapp id from packet", "err", err)
+ logger.Error("Failed to extract rollapp id from packet", "error", err, "packet_data", packet.Data)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0e77001 and 6ab10f2.

Files selected for processing (6)
  • app/app.go (8 hunks)
  • ibctesting/eibc_test.go (4 hunks)
  • x/bridging_fee/ibc_middleware.go (3 hunks)
  • x/delayedack/eibc.go (4 hunks)
  • x/delayedack/keeper/fraud_test.go (2 hunks)
  • x/eibc/genesis_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • x/eibc/genesis_test.go
Additional comments not posted (5)
x/delayedack/keeper/fraud_test.go (1)

13-14: Ensure proper initialization and usage of rollappKeeper in test setups.

The addition of rollappKeeper in the test setup is consistent with the changes in the middleware to accommodate the new functionality related to handling rollapp packets. This change ensures that the tests reflect the new architecture and are capable of testing the new logic effectively.

Also applies to: 50-51

app/app.go (4)

623-634: Ensure correct integration of NewIBCSendMiddleware in TransferKeeper.

The integration of NewIBCSendMiddleware with TransferKeeper appears correctly implemented. This change aligns with the PR's objective to enhance IBC transfer capabilities. However, ensure that the middleware is thoroughly tested, especially since it interacts with multiple components like IBCKeeper, RollappKeeper, and BankKeeper.


757-758: Review the integration of NewIBCAckMiddleware in the IBC middleware stack.

The integration of NewIBCAckMiddleware within the IBC middleware stack is correctly implemented. This middleware is crucial for handling acknowledgments in the IBC transfer process, especially with the new functionality related to denom metadata migration. Ensure comprehensive testing of this middleware to verify its interaction with DelayedAckMiddleware and RollappKeeper.


636-636: Correct method name to SetTransferKeeper.

- app.RollappKeeper.SetTransferKeeper(app.TransferKeeper)
+ app.RollappKeeper.SetTransferKeeper(app.TransferKeeper)

The method name SetTransferKeeper is correctly used here, aligning with the changes noted in the AI-generated summary. This ensures that the RollappKeeper is properly configured with the TransferKeeper.

Likely invalid or redundant comment.


770-770: Clarify the role of delayedAckMiddleware in the SetHooks method.

The use of delayedAckMiddleware in the SetHooks method of RollappKeeper needs clarification. It's important to understand how this middleware interacts with other components and its impact on the system, especially in the context of IBC transfers and denom metadata handling.

Verification successful

The role of delayedAckMiddleware in the SetHooks method is now clearer based on the gathered information:

  • delayedAckMiddleware is initialized using delayedackmodule.NewIBCMiddleware, which creates an IBCMiddleware instance with the provided keeper, rollappKeeper, and underlying application.
  • It is then used in transferinject.NewIBCAckMiddleware, which creates an IBCAckMiddleware that intercepts acknowledged incoming IBC packets and adds token metadata to the local rollapp record.

This middleware is part of the IBC (Inter-Blockchain Communication) stack and is responsible for handling delayed acknowledgments and ensuring that token metadata is correctly registered on the rollapp.

  • app/app.go:
    • delayedAckMiddleware is initialized and used in the IBC middleware stack.
    • It is passed to the SetHooks method, indicating its role in handling IBC packet acknowledgments and metadata registration.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the role and integration of `delayedAckMiddleware` in the `SetHooks` method.

# Test: Search for the usage of `delayedAckMiddleware` in the codebase. Expect: Clear documentation or comments explaining its role.
rg --type go $'delayedAckMiddleware'

Length of output: 300



Script:

#!/bin/bash
# Description: Gather more information about `delayedAckMiddleware` by examining its initialization and usage.

# Search for the definition of `NewIBCMiddleware` in the `delayedackmodule` package.
rg --type go --pattern 'func NewIBCMiddleware' --context 5

# Search for the definition of `NewIBCAckMiddleware` in the `transferinject` package.
rg --type go --pattern 'func NewIBCAckMiddleware' --context 5

Length of output: 948



Script:

#!/bin/bash
# Description: Gather more information about `delayedAckMiddleware` by examining its initialization and usage.

# Search for the definition of `NewIBCMiddleware` in the `delayedackmodule` package.
rg --type go 'func NewIBCMiddleware' --context 5

# Search for the definition of `NewIBCAckMiddleware` in the `transferinject` package.
rg --type go 'func NewIBCAckMiddleware' --context 5

Length of output: 2469

Comment on lines +46 to +48
feeMultiplier = im.TimeoutFee(ctx)
case commontypes.RollappPacket_ON_ACK:
feeMultiplier = im.keeper.ErrAckFee(ctx)
feeMultiplier = im.ErrAckFee(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Review and optimize the fee calculation logic in eIBCDemandOrderHandler.

The fee calculation logic could be optimized by consolidating the repeated code and ensuring that the fee calculations are accurate and efficient. Additionally, consider adding more comprehensive unit tests to cover all possible scenarios and edge cases related to fee calculations.

- feeMultiplier = im.TimeoutFee(ctx)
+ feeMultiplier = im.calculateFeeMultiplier(ctx, t)

Also applies to: 67-67, 89-89, 129-129

Committable suggestion was skipped due to low confidence.

Comment on lines +38 to +40
ConvertToApp(suite.hubChain).BankKeeper.SetDenomMetaData(suite.hubChain.GetContext(), banktypes.Metadata{
Base: sdk.DefaultBondDenom,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using a helper function for setting metadata.

To improve code readability and reusability, consider encapsulating the metadata setting logic into a helper function within the test suite. This will make the SetupTest method cleaner and more maintainable.

- ConvertToApp(suite.hubChain).BankKeeper.SetDenomMetaData(suite.hubChain.GetContext(), banktypes.Metadata{
-   Base: sdk.DefaultBondDenom,
- })
+ suite.setDenomMetaData(sdk.DefaultBondDenom)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ConvertToApp(suite.hubChain).BankKeeper.SetDenomMetaData(suite.hubChain.GetContext(), banktypes.Metadata{
Base: sdk.DefaultBondDenom,
})
suite.setDenomMetaData(sdk.DefaultBondDenom)

@@ -301,7 +306,7 @@
rollappPacket, err := delayedAckKeeper.GetRollappPacket(suite.hubChain.GetContext(), lastDemandOrder.TrackingPacketKey)
suite.Require().NoError(err)
var data transfertypes.FungibleTokenPacketData
err = transfertypes.ModuleCdc.UnmarshalJSON(rollappPacket.Packet.GetData(), &data)
err = eibctypes.ModuleCdc.UnmarshalJSON(rollappPacket.Packet.GetData(), &data)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use MustUnmarshalJSON for safer deserialization.

Using MustUnmarshalJSON instead of UnmarshalJSON can provide a safer way to handle JSON deserialization, as it panics if an error occurs, ensuring that tests fail fast if there is an issue with the data format.

- err = eibctypes.ModuleCdc.UnmarshalJSON(rollappPacket.Packet.GetData(), &data)
+ eibctypes.ModuleCdc.MustUnmarshalJSON(rollappPacket.Packet.GetData(), &data)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
err = eibctypes.ModuleCdc.UnmarshalJSON(rollappPacket.Packet.GetData(), &data)
eibctypes.ModuleCdc.MustUnmarshalJSON(rollappPacket.Packet.GetData(), &data)

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

Outside diff range and nitpick comments (1)
x/bridging_fee/ibc_middleware.go (1)

72-72: Consider revising the error message to avoid phrases like "Failed to" as per PR comments.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ab10f2 and f5c5c15.

Files selected for processing (2)
  • app/app.go (9 hunks)
  • x/bridging_fee/ibc_middleware.go (3 hunks)
Additional comments not posted (5)
x/bridging_fee/ibc_middleware.go (3)

38-50: Constructor logic is clear and correctly initializes all properties of BridgingFeeMiddleware.


49-49: Method GetFeeRecipient correctly retrieves the fee recipient address.


72-72: Verify the logic for fee calculation and ensure it aligns with business requirements.

app/app.go (2)

636-636: ### Set TransferKeeper in RollappKeeper
This line is crucial as it ensures that the RollappKeeper has a reference to the TransferKeeper. This setup is necessary for the RollappKeeper to interact with the IBC functionalities.

  • Correctness: Confirm that the TransferKeeper is correctly set in the RollappKeeper.
  • Maintainability: This change helps in maintaining clear separation and interaction between different modules.

This change is well-integrated and follows good software engineering practices by ensuring that different modules can interact through well-defined interfaces.


777-777: ### Use of delayedAckMiddleware in RollappKeeper
This line indicates the use of delayedAckMiddleware in the RollappKeeper. It's important to ensure that this middleware is compatible and does not introduce issues.

  • Compatibility: Check the compatibility of delayedAckMiddleware with RollappKeeper.
  • Correctness: Ensure that the middleware does not alter the expected behavior of RollappKeeper.

The integration appears to be done correctly, but it would be prudent to monitor this closely during testing to ensure that there are no unexpected behaviors.

app/app.go Show resolved Hide resolved
Comment on lines +748 to +755
transferStack = bridging_fee.NewIBCMiddleware(
transferMiddleware,
app.IBCKeeper.ChannelKeeper,
app.DelayedAckKeeper,
app.RollappKeeper,
app.TransferKeeper,
app.AccountKeeper.GetModuleAddress(txfeestypes.ModuleName),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Introduction of bridging_fee.NewIBCMiddleware

The introduction of a new IBC middleware for handling bridging fees is a significant addition. This middleware is expected to handle the fees associated with IBC transfers.

  • Correctness: Ensure that the middleware correctly calculates and applies bridging fees.
  • Security: Review the fee handling to ensure that there are no potential security vulnerabilities such as integer overflows or underflows.
  • Performance: Analyze the impact of this middleware on the performance of IBC transfers.

It is recommended to perform a security audit on the new bridging fee middleware to ensure that it handles fees securely and correctly.

Comment on lines +764 to +765
delayedAckMiddleware := delayedackmodule.NewIBCMiddleware(transferStack, app.DelayedAckKeeper, app.RollappKeeper)
transferStack = transferinject.NewIBCAckMiddleware(delayedAckMiddleware, app.RollappKeeper)
Copy link
Contributor

Choose a reason for hiding this comment

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

Integration of NewIBCAckMiddleware

The integration of NewIBCAckMiddleware is aimed at handling acknowledgments in IBC transfers. This is a critical part of ensuring that transfers are completed successfully.

  • Correctness: Verify that the middleware correctly handles all cases of acknowledgments.
  • Error Handling: Ensure that all error scenarios are handled properly.
  • Testing: Adding unit tests for this middleware would help in ensuring its functionality and robustness.

Consider adding unit tests for the NewIBCAckMiddleware to ensure its correct functionality and robust handling of different scenarios.

@zale144 zale144 requested a review from mtsitrin June 10, 2024 13:30
@danwt
Copy link
Contributor

danwt commented Jun 10, 2024

Is this ready to be merged @zale144 ?
Did you document the fact that this will not support updates that do not change the base?

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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f5c5c15 and 62d434d.

Files selected for processing (2)
  • CHANGELOG.md (2 hunks)
  • ibctesting/eibc_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • ibctesting/eibc_test.go

@zale144
Copy link
Contributor Author

zale144 commented Jun 11, 2024

Is this ready to be merged @zale144 ? Did you document the fact that this will not support updates that do not change the base?

@danwt I don't see why not. Just added the bit about updates to the ADR

@mtsitrin mtsitrin merged commit 78494bd into main Jun 11, 2024
55 of 88 checks passed
@mtsitrin mtsitrin deleted the zale144/POC-inject-custom-ibc-transfer-packet branch June 11, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate denom metadata from Hub to Rollapp
4 participants