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

refactor: ibc port router for app callbacks #6314

Draft
wants to merge 51 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
845e45f
feat: add intial SendPacket msgs and rpc definition to ibc core
damiannolan May 15, 2024
db5cddf
feat: add OnSendPacket callback to IBCModule interface
damiannolan May 15, 2024
385674a
chore: invoke OnSendPacket callback from msg server rpc
damiannolan May 15, 2024
5c861f4
chore: add comment
damiannolan May 15, 2024
9d4d2ea
chore: rename proto fields
damiannolan May 15, 2024
90fe8ae
chore: add OnSendPacket to ibccallbacks
damiannolan May 15, 2024
fc309f6
feat: add router_v2 while leaving current router impl in place
damiannolan May 15, 2024
d0f85db
chore: add getter and setters for AppRouter to core ibc
damiannolan May 15, 2024
588ff66
imp: implement callbacks OnSendPacket
colin-axner May 15, 2024
8bc82f6
imp: implement OnSendPacket for ics27
colin-axner May 16, 2024
f883d68
imp: implement OnSendPacket in transfer
damiannolan May 16, 2024
c5eef93
Merge branch 'main' into feat/port-router
damiannolan May 16, 2024
e626c7b
chore: start wiring up router_v2 in app.go
damiannolan May 16, 2024
45896aa
imp: add msg server handler to transfer
colin-axner May 16, 2024
20326d4
Merge branch 'feat/port-router' of github.com:cosmos/ibc-go into feat…
colin-axner May 16, 2024
3714960
refactor: enable core IBC SendPacket API and switch transfer to redir…
colin-axner May 16, 2024
b2df2f3
refactor: rewire controller to use SendPacket API
colin-axner May 16, 2024
b295949
refactor: rewire 29-fee to use SendPacket API
colin-axner May 16, 2024
2f5116e
refactor: use SendPacket API for callbacks
colin-axner May 16, 2024
16a88b4
imp: remove capability from SendPacket and add prefix routing
damiannolan May 16, 2024
67e4b5f
refactor: adapt signer to sdk.AccAddress
damiannolan May 16, 2024
3db1613
chore: rm capabilities from recv, ack, timeout packet handler
damiannolan May 16, 2024
07e8b1c
lint: make lint-fix and address
damiannolan May 16, 2024
4214201
refactor: rm SendPacket from ics4wrapper
damiannolan May 16, 2024
9610871
chore: rm callbacks var in SendPacket handler
damiannolan May 16, 2024
ef6e063
Merge branch 'main' into feat/port-router
damiannolan May 22, 2024
cf339f2
fix: rm capability arg in ibc ante handler
damiannolan May 22, 2024
4f8d319
Merge branch 'main' into feat/port-router
damiannolan Jul 11, 2024
a4a7bdd
(chore): remove capabilities from channel handsake (#7009)
bznein Aug 5, 2024
832a0fc
Adding updates to composite router and scaffolding for LegacyIBCModul…
chatton Aug 5, 2024
d701aa2
Rename IBCModule to ClassicIBCModule (#7015)
chatton Aug 5, 2024
9565e36
Merge branch 'main' of github.com:cosmos/ibc-go into feat/port-router
colin-axner Aug 6, 2024
3eaf2ce
fix: tests
colin-axner Aug 6, 2024
41c6656
Add Wrap/Unwrap Interfaces and implement OnChanOpenInit (#7059)
chatton Aug 7, 2024
9460400
Use new port router for onchanupgradetry (#7067)
chatton Aug 7, 2024
6ec1efa
Use new port router for OnChanOpenAck (#7084)
colin-axner Aug 7, 2024
dc6e072
Use new port router for OnChanUpgradeInit (#7082)
chatton Aug 8, 2024
ae43f7a
refactor: implement OnChanOpenConfirm using new port router (#7088)
colin-axner Aug 8, 2024
63dd289
chore: implement OnChanUpgradeTry (#7092)
chatton Aug 8, 2024
0c47e45
chore(api)!: move checks from Transfer to OnSendPacket (#7068)
bznein Aug 8, 2024
467819d
refactor: implement OnChanCloseInit using new port router. (#7095)
bznein Aug 8, 2024
d779697
Use new port router for OnChanUpgradeAck (#7094)
chatton Aug 8, 2024
179025d
refactor: implement onchancloseconfirm using new port router (#7096)
bznein Aug 8, 2024
62db721
Use new port router for OnChanUpgradeOpen (#7102)
chatton Aug 8, 2024
48b6a3f
refactor: replace ack interface with result type for OnRecvPacket (#7…
damiannolan Aug 8, 2024
d9c4e96
imp (api)!: convert coins to token only once in MsgTransfer (#7110)
bznein Aug 8, 2024
0ea612a
use new port router with OnAcknowledgementPacket (#7108)
colin-axner Aug 8, 2024
a9d34ba
chore: docs (#7111)
colin-axner Aug 12, 2024
ec593cb
Bznein/7023/on timeout packet (#7144)
bznein Aug 13, 2024
f5ab15b
Add convenience func to reverse callbacks and refactor other methods …
chatton Aug 13, 2024
6327b58
chore: use app router in OnTimeoutPacket handler (#7164)
chatton Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ func (im IBCMiddleware) OnChanCloseConfirm(
return nil
}

// OnSendPacket implements the IBCModule interface.
func (IBCMiddleware) OnSendPacket(
ctx sdk.Context,
portID string,
channelID string,
sequence uint64,
data []byte,
signer string,
) error {
return nil
}

// OnRecvPacket implements the IBCMiddleware interface
func (IBCMiddleware) OnRecvPacket(
ctx sdk.Context,
Expand Down
12 changes: 12 additions & 0 deletions modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ func (im IBCModule) OnChanCloseConfirm(
return im.keeper.OnChanCloseConfirm(ctx, portID, channelID)
}

// OnSendPacket implements the IBCModule interface.
func (IBCModule) OnSendPacket(
ctx sdk.Context,
portID string,
channelID string,
sequence uint64,
data []byte,
signer string,
) error {
return errorsmod.Wrap(ibcerrors.ErrInvalidRequest, "cannot send packet on icahost")
}

// OnRecvPacket implements the IBCModule interface
func (im IBCModule) OnRecvPacket(
ctx sdk.Context,
Expand Down
12 changes: 12 additions & 0 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ func (im IBCMiddleware) OnChanCloseConfirm(
return im.keeper.RefundFeesOnChannelClosure(ctx, portID, channelID)
}

// OnSendPacket implements the IBCModule interface.
func (IBCMiddleware) OnSendPacket(
ctx sdk.Context,
portID string,
channelID string,
sequence uint64,
data []byte,
signer string,
) error {
return nil
}

// OnRecvPacket implements the IBCMiddleware interface.
// If fees are not enabled, this callback will default to the ibc-core packet callback
func (im IBCMiddleware) OnRecvPacket(
Expand Down
12 changes: 12 additions & 0 deletions modules/apps/transfer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ func (IBCModule) OnChanCloseConfirm(
return nil
}

// OnSendPacket implements the IBCModule interface.
func (IBCModule) OnSendPacket(
ctx sdk.Context,
portID string,
channelID string,
sequence uint64,
data []byte,
signer string,
) error {
return nil
}

// OnRecvPacket implements the IBCModule interface. A successful acknowledgement
// is returned if the packet data is successfully decoded and the receive application
// logic returns without error.
Expand Down
888 changes: 737 additions & 151 deletions modules/core/04-channel/types/tx.pb.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions modules/core/05-port/types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ type IBCModule interface {
channelID string,
) error

OnSendPacket(
ctx sdk.Context,
portID string,
channelID string,
sequence uint64,
data []byte,
signer string,
) error

// OnRecvPacket must return an acknowledgement that implements the Acknowledgement interface.
// In the case of an asynchronous acknowledgement, nil should be returned.
// If the acknowledgement returned is successful, the state changes on callback are written,
Expand Down Expand Up @@ -159,6 +168,7 @@ type UpgradableModule interface {

// ICS4Wrapper implements the ICS4 interfaces that IBC applications use to send packets and acknowledgements.
type ICS4Wrapper interface {
// TODO: Leave in place to avoid compiler errors and incrementally work to remove. We can then delete these methods
SendPacket(
ctx sdk.Context,
chanCap *capabilitytypes.Capability,
Expand Down
34 changes: 34 additions & 0 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,40 @@ func (k *Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Ms
return &channeltypes.MsgChannelCloseConfirmResponse{}, nil
}

// SendPacket defines a rpc handler method for MsgSendPacket.
func (k *Keeper) SendPacket(goCtx context.Context, msg *channeltypes.MsgSendPacket) (*channeltypes.MsgSendPacketResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

module, capability, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId)
if err != nil {
ctx.Logger().Error("send packet failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id"))
return nil, errorsmod.Wrap(err, "could not retrieve module from port-id")
}

// Retrieve callbacks from router
cbs, ok := k.PortKeeper.Route(module)
if !ok {
ctx.Logger().Error("send packet failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module))
return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)
}

sequence, err := k.ChannelKeeper.SendPacket(ctx, capability, msg.PortId, msg.ChannelId, msg.TimeoutHeight, uint64(msg.TimeoutTimestamp.UnixNano()), msg.PacketData)
if err != nil {
ctx.Logger().Error("send packet failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", errorsmod.Wrap(err, "send packet failed"))
return nil, errorsmod.Wrapf(err, "send packet failed for module: %s", module)
}

// TODO: Make port router have list of ordered callbacks
// Loop over cbs in-order calling OnSendPacket on each IBCModule. To be done for RecvPacket handler as well in opposite order.
// Adjust app logic to account for what should be done before MsgSendPacket and what should be done in OnSendPacket.
if err := cbs.OnSendPacket(ctx, msg.PortId, msg.ChannelId, sequence, msg.PacketData, msg.Signer); err != nil {
ctx.Logger().Error("send packet callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", errorsmod.Wrap(err, "send packet callback failed"))
return nil, errorsmod.Wrapf(err, "send packet callback failed for module: %s", module)
}

return &channeltypes.MsgSendPacketResponse{Sequence: sequence}, nil
}

// RecvPacket defines a rpc handler method for MsgRecvPacket.
func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacket) (*channeltypes.MsgRecvPacketResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
Expand Down
4 changes: 4 additions & 0 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var (
maxSequence = uint64(10)
)

func (suite *KeeperTestSuite) TestHandleSendPacket() {
suite.T().Skip("todo: handle test send packet rpc")
}

// tests the IBC handler receiving a packet on ordered and unordered channels.
// It verifies that the storing of an acknowledgement on success occurs. It
// tests high level properties like ordering and basic sanity checks. More
Expand Down
25 changes: 25 additions & 0 deletions proto/ibc/core/channel/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ibc.core.channel.v1;

option go_package = "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types";

import "google/protobuf/timestamp.proto";
import "gogoproto/gogo.proto";
import "cosmos/msg/v1/msg.proto";
import "ibc/core/client/v1/client.proto";
Expand Down Expand Up @@ -33,6 +34,9 @@ service Msg {
// MsgChannelCloseConfirm.
rpc ChannelCloseConfirm(MsgChannelCloseConfirm) returns (MsgChannelCloseConfirmResponse);

// SendPacket defines a rpc handler method for MsgSendPacket.
rpc SendPacket(MsgSendPacket) returns (MsgSendPacketResponse);

// RecvPacket defines a rpc handler method for MsgRecvPacket.
rpc RecvPacket(MsgRecvPacket) returns (MsgRecvPacketResponse);

Expand Down Expand Up @@ -208,6 +212,27 @@ message MsgChannelCloseConfirm {
// type.
message MsgChannelCloseConfirmResponse {}

// MsgSendPacket sends an outgoing IBC packet
message MsgSendPacket {
option (cosmos.msg.v1.signer) = "signer";

option (gogoproto.goproto_getters) = false;

string port_id = 1;
string channel_id = 2;
ibc.core.client.v1.Height timeout_height = 3 [(gogoproto.nullable) = false];
google.protobuf.Timestamp timeout_timestamp = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
bytes packet_data = 5;
string signer = 6;
}

// MsgSendPacketReponse defines the Msg/SendPacket response type.
message MsgSendPacketResponse {
option (gogoproto.goproto_getters) = false;

uint64 sequence = 1;
}

// MsgRecvPacket receives incoming IBC packet
message MsgRecvPacket {
option (cosmos.msg.v1.signer) = "signer";
Expand Down
9 changes: 9 additions & 0 deletions testing/mock/ibc_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ type IBCApp struct {
channelID string,
) error

OnSendPacket func(
ctx sdk.Context,
portID string,
channelID string,
sequence uint64,
data []byte,
signer string,
) error

// OnRecvPacket must return an acknowledgement that implements the Acknowledgement interface.
// In the case of an asynchronous acknowledgement, nil should be returned.
// If the acknowledgement returned is successful, the state changes on callback are written,
Expand Down
9 changes: 9 additions & 0 deletions testing/mock/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ func (im IBCModule) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string
return nil
}

// OnSendPacket implements the IBCModule interface.
func (im IBCModule) OnSendPacket(ctx sdk.Context, portID string, channelID string, sequence uint64, data []byte, signer string) error {
if im.IBCApp.OnSendPacket != nil {
return im.IBCApp.OnSendPacket(ctx, portID, channelID, sequence, data, signer)
}

return nil
}

// OnRecvPacket implements the IBCModule interface.
func (im IBCModule) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) exported.Acknowledgement {
if im.IBCApp.OnRecvPacket != nil {
Expand Down
9 changes: 9 additions & 0 deletions testing/mock/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ func (im BlockUpgradeMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, cha
return nil
}

// OnSendPacket implements the IBCModule interface.
func (im BlockUpgradeMiddleware) OnSendPacket(ctx sdk.Context, portID string, channelID string, sequence uint64, data []byte, signer string) error {
if im.IBCApp.OnSendPacket != nil {
return im.IBCApp.OnSendPacket(ctx, portID, channelID, sequence, data, signer)
}

return nil
}

// OnRecvPacket implements the IBCModule interface.
func (im BlockUpgradeMiddleware) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) exported.Acknowledgement {
if im.IBCApp.OnRecvPacket != nil {
Expand Down
Loading