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

Use ICS4Wrapper to send raw IBC packets & fix Fee middleware in wasm stack #1375

Conversation

assafmo
Copy link
Contributor

@assafmo assafmo commented May 3, 2023

This PR adds an ICS4Wrapper to the wasm keeper, which serves as the interface for sending raw IBC packets. This feature enables the chain to use middlewares with IBC-enabled contracts.

As of v0.31, the Fee middleware is only configured for incoming packets, as shown in this code snippet: link. On the other hand, for outgoing packets, the wasm keeper directly uses the IBC channel keeper, as shown here: link. Consequently, the Fee middleware is bypassed for outgoing packets. Since IBC relayer fees are paid on the sending chains, this means that a relayer can be paid for relaying IBC packets to wasmd but not for relaying packets from wasmd.

@assafmo assafmo requested a review from alpe as a code owner May 3, 2023 11:11
Copy link
Member

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Very nice work! 🌸
I added some comments to move the interface to wasmd. It would also be nice to remove SendPacket from ChannelKeeper in expected_keepers.go.

Other than this, it is good to be merged. I will port it to main when merged

@@ -9,6 +9,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
Copy link
Member

Choose a reason for hiding this comment

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

The interface was extended in v7 and moved to port/types . Why not cut this dependency and define the interface with the send method only in wasmd expected_keepers.go?

Copy link
Contributor Author

@assafmo assafmo May 4, 2023

Choose a reason for hiding this comment

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

The reason I used ibctransfertypes.ICS4Wrapper is that it only has the SendPacket function, which is all that we need. I agree that we can inline this interface into wasmd.

@@ -522,6 +522,7 @@ func NewWasmApp(
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware
Copy link
Member

@alpe alpe May 4, 2023

Choose a reason for hiding this comment

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

Good eye and the change towards the interface makes sense!
Looking deeper into the impl, the ibc fee keeper just delegates to the channel keeper that we setup with the fee keeper.

The separation is much better and packet sending can go through a wrapper.

Personally, I find it very hard to configure and chain the keepers and middlewares proper. There are 2 places that need to be configured. IMHO it would be best, if we could just pass the middleware here and let it handle the internals. Unfortunately there are some circular dependencies.

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, it's an SDK/IBC thing. I'm sure it'll get better.

@@ -11,6 +11,8 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/CosmWasm/wasmd/x/wasm/types"

ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
Copy link
Member

Choose a reason for hiding this comment

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

Same as above: let's move the interface into the project

@alpe alpe added the backport/main Backport patches to main branch label May 4, 2023
@assafmo
Copy link
Contributor Author

assafmo commented May 4, 2023

Thanks for the CR. I'll fix everything on Sunday.

Copy link
Member

@alpe alpe left a comment

Choose a reason for hiding this comment

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

I'll fix everything on Sunday.

Enjoy your weekend. I will merge the PR as it is and inline the interface in a new PR

@assafmo
Copy link
Contributor Author

assafmo commented May 7, 2023

I'll fix everything on Sunday.

Enjoy your weekend. I will merge the PR as it is and inline the interface in a new PR

Oh cool, thanks!

alpe added a commit that referenced this pull request May 8, 2023
…stack (backport #1375) (#1379)

* Use ICS4Wrapper to send raw IBC packets & fix Fee in wasm stack

(cherry picked from commit 6dfa5cb)

# Conflicts:
#	app/app.go
#	x/wasm/keeper/handler_plugin.go
#	x/wasm/keeper/keeper_cgo.go
#	x/wasm/keeper/keeper_test.go
#	x/wasm/keeper/options_test.go
#	x/wasm/keeper/test_common.go

* Fix merge conflicts

* Inline ibc packet sender interface and minor chore

* Rename IBCPacketSender

---------

Co-authored-by: Assaf Morami <assaf.morami@gmail.com>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
tubackkhoa pushed a commit to oraichain/wasmd that referenced this pull request May 9, 2023
…stack (backport CosmWasm#1375) (CosmWasm#1379)

* Use ICS4Wrapper to send raw IBC packets & fix Fee in wasm stack

(cherry picked from commit 6dfa5cb)

# Conflicts:
#	app/app.go
#	x/wasm/keeper/handler_plugin.go
#	x/wasm/keeper/keeper_cgo.go
#	x/wasm/keeper/keeper_test.go
#	x/wasm/keeper/options_test.go
#	x/wasm/keeper/test_common.go

* Fix merge conflicts

* Inline ibc packet sender interface and minor chore

* Rename IBCPacketSender

---------

Co-authored-by: Assaf Morami <assaf.morami@gmail.com>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
@assafmo assafmo deleted the use-ics4Wrapper-instead-of-channelKeeper branch May 12, 2023 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/main Backport patches to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants