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

chore(api)!: move checks from Transfer to OnSendPacket #7068

Merged
merged 19 commits into from
Aug 8, 2024

Conversation

bznein
Copy link
Contributor

@bznein bznein commented Aug 7, 2024

Description

closes: #6949


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.

damiannolan and others added 6 commits August 7, 2024 10:37
* deps: bump cosmos-sdk to v0.50.8

* chore: update changelog

* deps: bump cosmossdk.io/client to v2.0.0-beta.3. bump x/upgrade to v0.1.4

* chore: make tidy-all

* test: bump to 3f6796fba413cca for testing purposes.

* deps: bump cosmos sdk to 0.50.9

* Update CHANGELOG.md

* chore: update CHANGELOG for submodules.

---------

Co-authored-by: DimitrisJim <d.f.hilliard@gmail.com>
@@ -391,7 +391,7 @@ func (k Keeper) iterateForwardedPackets(ctx sdk.Context, cb func(packet types.Fo

// IsBlockedAddr checks if the given address is allowed to send or receive tokens.
// The module account is always allowed to send and receive tokens.
func (k Keeper) isBlockedAddr(addr sdk.AccAddress) bool {
func (k Keeper) IsBlockedAddr(addr sdk.AccAddress) bool {
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 was needed in order to be able to call it from OnSendPacket

@@ -33,27 +29,6 @@ func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.
return nil, errorsmod.Wrapf(types.ErrSendDisabled, err.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 check was left in this function as the logic is not easy to implement on OnSendPacket, we would have to export BankKeeper but also add a lot of logic to convert coins back to tokens

Copy link
Contributor

Choose a reason for hiding this comment

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

This check is necessary to be moved. We can move it into keeper.OnSendPacket. There's already logic to convert tokens to coin there

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: going forward, users can invoke OnSendPacket without using MsgTransfer, so it's unsafe to have any necessary checks remain in MsgTransfer

@@ -169,21 +169,6 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
// },
// channeltypes.ErrInvalidPacket,
// },
{
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 test now doesn't succeed due to the following logic:

  • Transfer does not check for the version/forwarding combination anymore
  • the function that creates the packet data will ignore everything in forwarding when the version is V1.
    Note that there is still a check on OnSendPacket but it will not be triggered because Hops will not be present.

I'll open an issue to add tests specifically for OnSendPacket since we currently do not have them

Copy link
Contributor

Choose a reason for hiding this comment

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

It should? I wonder if this was not working because of the 1 -> 0 change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ouch thanks, yeah it does. I'm trying to give up coffee starting today and you can see the results :(

@bznein bznein marked this pull request as ready for review August 7, 2024 13:15
@bznein bznein added priority PRs that need prompt reviews 05-port Issues concerns the 05-port submodule feat: port-router labels Aug 7, 2024
bznein and others added 2 commits August 7, 2024 14:47
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
Comment on lines 350 to 353
if k.IsBlockedAddr(sender) {
return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "%s is not allowed to send funds", sender)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

this is an unnecessary addition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea how this got in, sorry :/

@@ -430,7 +434,7 @@ func createPacketDataBytesFromVersion(appVersion, sender, receiver, memo string,
case types.V1:
// Sanity check, tokens must always be of length 1 if using app version V1.
if len(tokens) != 1 {
return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "cannot transfer multiple coins with %s", types.V1)
return nil, errorsmod.Wrapf(types.ErrInvalidVersion, "length of tokens must be equal to 1 if using %s version", types.V1)
Copy link
Contributor

Choose a reason for hiding this comment

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

would recommend doing changes like this against main since it is unrelated to the port router changes

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 was the result of a weird merge, because we used to panic here so I added a similar change but not identical, will revert

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 work! As a side note, I noticed #7080 which came from the initial refactor, but as it was not necessary for this work I opened a separate issue

@bznein
Copy link
Contributor Author

bznein commented Aug 7, 2024

Nice work! As a side note, I noticed #7080 which came from the initial refactor, but as it was not necessary for this work I opened a separate issue

Ah! We noticed the same with Cian and were about to open an issue :D thanks!

@bznein bznein requested a review from srdtrk as a code owner August 8, 2024 08:49
Copy link
Member

Choose a reason for hiding this comment

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

there is some commented out code on L54 that can be removed now!

// packetData := types.NewFungibleTokenPacketData(
// 	fullDenomPath, msg.Token.Amount.String(), sender.String(), msg.Receiver, msg.Memo,
// )

Copy link

sonarcloud bot commented Aug 8, 2024

@bznein bznein merged commit 0c47e45 into feat/port-router Aug 8, 2024
62 of 65 checks passed
@bznein bznein deleted the bznein/6949/msgTransferWrapperToSendPacket branch August 8, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
05-port Issues concerns the 05-port submodule feat: port-router priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants