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

imp (api)!: convert coins to token only once in MsgTransfer #7110

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

bznein
Copy link
Contributor

@bznein bznein commented Aug 8, 2024

Description

closes: #7080


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@@ -35,8 +35,8 @@ func (k Keeper) TokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, erro
}

// UnwindHops is a wrapper around unwindHops for testing purposes.
func (k Keeper) UnwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgTransfer, error) {
return k.unwindHops(ctx, msg)
func (k Keeper) UnwindHops(msg *types.MsgTransfer, tokens []types.Token) (*types.MsgTransfer, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an API-breaking change but since I assume the whole feature branch will this should not be an issue

Copy link
Contributor

Choose a reason for hiding this comment

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

Please correct me if I am wrong, but since this function is in a _test.go file, then it is not part of the public API, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good point, I wasn't too sure about it tbh!

@@ -130,30 +130,22 @@ func (k Keeper) unwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgT
// getUnwindHops returns the hops to be used during unwinding. If coins consists of more than
// one coin, all coins must have the exact same trace, else an error is returned. getUnwindHops
// also validates that the coins are not native to the chain.
func (k Keeper) getUnwindHops(ctx sdk.Context, coins sdk.Coins) ([]types.Hop, error) {
func (Keeper) getUnwindHops(tokens []types.Token) ([]types.Hop, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function can technically be moved out of the keeper now, since it does need to read state to convert coins to token anymore. Happy to do it if it seems the best thing to do

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense to me!

@@ -327,13 +327,6 @@ func (suite *KeeperTestSuite) TestUnwindHops() {
suite.Require().Equal(*msg, *modified, "expected msg and modified msg are different")
},
},
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe we need this test anymore, because this would have failed during the conversion we don't perform anymore

@bznein bznein marked this pull request as ready for review August 8, 2024 15:06
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Nice! Great work. The changes look good to me. It's nice to be more efficient in this approach

@bznein bznein merged commit d9c4e96 into feat/port-router Aug 8, 2024
64 of 66 checks passed
@bznein bznein deleted the bznein/7080/InefficientLoop branch August 8, 2024 15:50
Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Sorry for leaving the review after merge, but is there a reason why we couldn't merge this directly to main and then backport to v9? Then we also have these changes in the release branch. As far as I can see there is nothing in the PR that directly depends on the port router refactor, right?

@@ -35,8 +35,8 @@ func (k Keeper) TokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, erro
}

// UnwindHops is a wrapper around unwindHops for testing purposes.
func (k Keeper) UnwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgTransfer, error) {
return k.unwindHops(ctx, msg)
func (k Keeper) UnwindHops(msg *types.MsgTransfer, tokens []types.Token) (*types.MsgTransfer, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please correct me if I am wrong, but since this function is in a _test.go file, then it is not part of the public API, right?

@bznein
Copy link
Contributor Author

bznein commented Aug 9, 2024

Sorry for leaving the review after merge, but is there a reason why we couldn't merge this directly to main and then backport to v9? Then we also have these changes in the release branch. As far as I can see there is nothing in the PR that directly depends on the port router refactor, right?

You're right, I could have done it but just automatically went on "feature branch" mode :) I think it should be safe to add the same PR for main, I can do it

bznein added a commit that referenced this pull request Aug 9, 2024
* test not working

* refactored test and removed unneeded caese
@bznein
Copy link
Contributor Author

bznein commented Aug 9, 2024

Sorry for leaving the review after merge, but is there a reason why we couldn't merge this directly to main and then backport to v9? Then we also have these changes in the release branch. As far as I can see there is nothing in the PR that directly depends on the port router refactor, right?

@crodriguezvega actually scratch my previous comment. On main we don't have the inefficient looping (

coins := msg.GetCoins()
if err := k.bankKeeper.IsSendEnabledCoins(ctx, coins...); err != nil {
return nil, errorsmod.Wrapf(types.ErrSendDisabled, err.Error())
}
if k.isBlockedAddr(sender) {
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", sender)
}
if msg.Forwarding.GetUnwind() {
msg, err = k.unwindHops(ctx, msg)
if err != nil {
return nil, err
}
}
sequence, err := k.sendTransfer(
ctx, msg.SourcePort, msg.SourceChannel, coins, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp,
msg.Memo, msg.Forwarding.GetHops())
if err != nil {
return nil, err
) as we don't need to convert coins to tokens in the Transfer function since we use k.sendTransfer that takes coins).

(inside that function we still convert coins to token but we also use coins directly, so it's a bit more complex. I guess if we want this change in main we can make it but better to create another issue as it is definitely more involved.

@crodriguezvega
Copy link
Contributor

Sorry for leaving the review after merge, but is there a reason why we couldn't merge this directly to main and then backport to v9? Then we also have these changes in the release branch. As far as I can see there is nothing in the PR that directly depends on the port router refactor, right?

@crodriguezvega actually scratch my previous comment. On main we don't have the inefficient looping (

coins := msg.GetCoins()
if err := k.bankKeeper.IsSendEnabledCoins(ctx, coins...); err != nil {
return nil, errorsmod.Wrapf(types.ErrSendDisabled, err.Error())
}
if k.isBlockedAddr(sender) {
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", sender)
}
if msg.Forwarding.GetUnwind() {
msg, err = k.unwindHops(ctx, msg)
if err != nil {
return nil, err
}
}
sequence, err := k.sendTransfer(
ctx, msg.SourcePort, msg.SourceChannel, coins, sender, msg.Receiver, msg.TimeoutHeight, msg.TimeoutTimestamp,
msg.Memo, msg.Forwarding.GetHops())
if err != nil {
return nil, err

) as we don't need to convert coins to tokens in the Transfer function since we use k.sendTransfer that takes coins).
(inside that function we still convert coins to token but we also use coins directly, so it's a bit more complex. I guess if we want this change in main we can make it but better to create another issue as it is definitely more involved.

Ah, gotcha. Thank you for explaining!

@chatton
Copy link
Contributor

chatton commented Aug 12, 2024

thanks for picking this one up, LGTM

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.

4 participants