-
Notifications
You must be signed in to change notification settings - Fork 405
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I used |
||
channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" | ||
host "github.com/cosmos/ibc-go/v4/modules/core/24-host" | ||
|
||
|
@@ -34,6 +35,7 @@ type SDKMessageHandler struct { | |
|
||
func NewDefaultMessageHandler( | ||
router MessageRouter, | ||
ics4Wrapper ibctransfertypes.ICS4Wrapper, | ||
channelKeeper types.ChannelKeeper, | ||
capabilityKeeper types.CapabilityKeeper, | ||
bankKeeper types.Burner, | ||
|
@@ -47,7 +49,7 @@ func NewDefaultMessageHandler( | |
} | ||
return NewMessageHandlerChain( | ||
NewSDKMessageHandler(router, encoders), | ||
NewIBCRawPacketHandler(channelKeeper, capabilityKeeper), | ||
NewIBCRawPacketHandler(ics4Wrapper, channelKeeper, capabilityKeeper), | ||
NewBurnCoinMessageHandler(bankKeeper), | ||
) | ||
} | ||
|
@@ -142,12 +144,17 @@ func (m MessageHandlerChain) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAd | |
|
||
// IBCRawPacketHandler handels IBC.SendPacket messages which are published to an IBC channel. | ||
type IBCRawPacketHandler struct { | ||
ics4Wrapper ibctransfertypes.ICS4Wrapper | ||
channelKeeper types.ChannelKeeper | ||
capabilityKeeper types.CapabilityKeeper | ||
} | ||
|
||
func NewIBCRawPacketHandler(chk types.ChannelKeeper, cak types.CapabilityKeeper) IBCRawPacketHandler { | ||
return IBCRawPacketHandler{channelKeeper: chk, capabilityKeeper: cak} | ||
func NewIBCRawPacketHandler(ics4Wrapper ibctransfertypes.ICS4Wrapper, channelKeeper types.ChannelKeeper, capabilityKeeper types.CapabilityKeeper) IBCRawPacketHandler { | ||
return IBCRawPacketHandler{ | ||
ics4Wrapper: ics4Wrapper, | ||
channelKeeper: channelKeeper, | ||
capabilityKeeper: capabilityKeeper, | ||
} | ||
} | ||
|
||
// DispatchMsg publishes a raw IBC packet onto the channel. | ||
|
@@ -189,7 +196,7 @@ func (h IBCRawPacketHandler) DispatchMsg(ctx sdk.Context, _ sdk.AccAddress, cont | |
msg.IBC.SendPacket.Timeout.Timestamp, | ||
) | ||
|
||
if err := h.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil { | ||
if err := h.ics4Wrapper.SendPacket(ctx, channelCap, packet); err != nil { | ||
return nil, nil, sdkerrors.Wrap(err, "failed to send packet") | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above: let's move the interface into the project |
||
) | ||
|
||
// NewKeeper creates a new contract Keeper instance | ||
|
@@ -23,6 +25,7 @@ func NewKeeper( | |
bankKeeper types.BankKeeper, | ||
stakingKeeper types.StakingKeeper, | ||
distKeeper types.DistributionKeeper, | ||
ics4Wrapper ibctransfertypes.ICS4Wrapper, | ||
channelKeeper types.ChannelKeeper, | ||
portKeeper types.PortKeeper, | ||
capabilityKeeper types.CapabilityKeeper, | ||
|
@@ -52,7 +55,7 @@ func NewKeeper( | |
accountPruner: NewVestingCoinBurner(bankKeeper), | ||
portKeeper: portKeeper, | ||
capabilityKeeper: capabilityKeeper, | ||
messenger: NewDefaultMessageHandler(router, channelKeeper, capabilityKeeper, bankKeeper, cdc, portSource), | ||
messenger: NewDefaultMessageHandler(router, ics4Wrapper, channelKeeper, capabilityKeeper, bankKeeper, cdc, portSource), | ||
queryGasLimit: wasmConfig.SmartQueryGasLimit, | ||
paramSpace: paramSpace, | ||
gasRegister: NewDefaultWasmGasRegister(), | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.