diff --git a/modules/core/04-channel/handler.go b/modules/core/04-channel/handler.go deleted file mode 100644 index 2c222a2eb7a..00000000000 --- a/modules/core/04-channel/handler.go +++ /dev/null @@ -1,186 +0,0 @@ -package channel - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - "github.com/cosmos/ibc-go/modules/core/04-channel/keeper" - "github.com/cosmos/ibc-go/modules/core/04-channel/types" -) - -// HandleMsgChannelOpenInit defines the sdk.Handler for MsgChannelOpenInit -func HandleMsgChannelOpenInit(ctx sdk.Context, k keeper.Keeper, portCap *capabilitytypes.Capability, msg *types.MsgChannelOpenInit) (*sdk.Result, string, *capabilitytypes.Capability, error) { - channelID, capKey, err := k.ChanOpenInit( - ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, - portCap, msg.Channel.Counterparty, msg.Channel.Version, - ) - if err != nil { - return nil, "", nil, sdkerrors.Wrap(err, "channel handshake open init failed") - } - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelOpenInit, - sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - sdk.NewAttribute(types.AttributeCounterpartyPortID, msg.Channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, msg.Channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, msg.Channel.ConnectionHops[0]), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) - - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, channelID, capKey, nil -} - -// HandleMsgChannelOpenTry defines the sdk.Handler for MsgChannelOpenTry -func HandleMsgChannelOpenTry(ctx sdk.Context, k keeper.Keeper, portCap *capabilitytypes.Capability, msg *types.MsgChannelOpenTry) (*sdk.Result, string, *capabilitytypes.Capability, error) { - channelID, capKey, err := k.ChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, msg.PreviousChannelId, - portCap, msg.Channel.Counterparty, msg.Channel.Version, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight, - ) - if err != nil { - return nil, "", nil, sdkerrors.Wrap(err, "channel handshake open try failed") - } - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelOpenTry, - sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), - sdk.NewAttribute(types.AttributeKeyChannelID, channelID), - sdk.NewAttribute(types.AttributeCounterpartyPortID, msg.Channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, msg.Channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, msg.Channel.ConnectionHops[0]), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) - - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, channelID, capKey, nil -} - -// HandleMsgChannelOpenAck defines the sdk.Handler for MsgChannelOpenAck -func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelOpenAck) (*sdk.Result, error) { - err := k.ChanOpenAck( - ctx, msg.PortId, msg.ChannelId, channelCap, msg.CounterpartyVersion, msg.CounterpartyChannelId, msg.ProofTry, msg.ProofHeight, - ) - if err != nil { - return nil, sdkerrors.Wrap(err, "channel handshake open ack failed") - } - - channel, _ := k.GetChannel(ctx, msg.PortId, msg.ChannelId) - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelOpenAck, - sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), - sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelId), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) - - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, nil -} - -// HandleMsgChannelOpenConfirm defines the sdk.Handler for MsgChannelOpenConfirm -func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelOpenConfirm) (*sdk.Result, error) { - err := k.ChanOpenConfirm(ctx, msg.PortId, msg.ChannelId, channelCap, msg.ProofAck, msg.ProofHeight) - if err != nil { - return nil, sdkerrors.Wrap(err, "channel handshake open confirm failed") - } - - channel, _ := k.GetChannel(ctx, msg.PortId, msg.ChannelId) - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelOpenConfirm, - sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), - sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelId), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) - - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, nil -} - -// HandleMsgChannelCloseInit defines the sdk.Handler for MsgChannelCloseInit -func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelCloseInit) (*sdk.Result, error) { - err := k.ChanCloseInit(ctx, msg.PortId, msg.ChannelId, channelCap) - if err != nil { - return nil, sdkerrors.Wrap(err, "channel handshake close init failed") - } - - channel, _ := k.GetChannel(ctx, msg.PortId, msg.ChannelId) - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelCloseInit, - sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), - sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelId), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) - - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, nil -} - -// HandleMsgChannelCloseConfirm defines the sdk.Handler for MsgChannelCloseConfirm -func HandleMsgChannelCloseConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelCloseConfirm) (*sdk.Result, error) { - err := k.ChanCloseConfirm(ctx, msg.PortId, msg.ChannelId, channelCap, msg.ProofInit, msg.ProofHeight) - if err != nil { - return nil, sdkerrors.Wrap(err, "channel handshake close confirm failed") - } - - channel, _ := k.GetChannel(ctx, msg.PortId, msg.ChannelId) - - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - types.EventTypeChannelCloseConfirm, - sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), - sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelId), - sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), - sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), - sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), - ), - sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), - ), - }) - - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, nil -} diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index 2dcfdbeddce..5f9d70ad090 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -91,6 +91,17 @@ func (k Keeper) ChanOpenInit( telemetry.IncrCounter(1, "ibc", "channel", "open-init") }() + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelOpenInit, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, connectionHops[0]), + ), + }) + return channelID, capKey, nil } @@ -232,6 +243,17 @@ func (k Keeper) ChanOpenTry( telemetry.IncrCounter(1, "ibc", "channel", "open-try") }() + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelOpenTry, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + }) + return channelID, capKey, nil } @@ -307,6 +329,17 @@ func (k Keeper) ChanOpenAck( channel.Counterparty.ChannelId = counterpartyChannelID k.SetChannel(ctx, portID, channelID, channel) + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelOpenAck, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + }) + return nil } @@ -375,6 +408,18 @@ func (k Keeper) ChanOpenConfirm( defer func() { telemetry.IncrCounter(1, "ibc", "channel", "open-confirm") }() + + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelOpenConfirm, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + }) + return nil } @@ -425,6 +470,17 @@ func (k Keeper) ChanCloseInit( channel.State = types.CLOSED k.SetChannel(ctx, portID, channelID, channel) + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelCloseInit, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + }) + return nil } @@ -492,5 +548,16 @@ func (k Keeper) ChanCloseConfirm( channel.State = types.CLOSED k.SetChannel(ctx, portID, channelID, channel) + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeChannelCloseConfirm, + sdk.NewAttribute(types.AttributeKeyPortID, portID), + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), + sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), + sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), + ), + }) + return nil } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index e1f2081046a..626a6fdee02 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -10,7 +10,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types" - channel "github.com/cosmos/ibc-go/modules/core/04-channel" + "github.com/cosmos/ibc-go/modules/core/04-channel/types" channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/modules/core/05-port/types" ) @@ -264,9 +264,12 @@ func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChan return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") } - _, channelID, cap, err := channel.HandleMsgChannelOpenInit(ctx, k.ChannelKeeper, portCap, msg) + channelID, cap, err := k.ChannelKeeper.ChanOpenInit( + ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, + portCap, msg.Channel.Counterparty, msg.Channel.Version, + ) if err != nil { - return nil, err + return nil, sdkerrors.Wrap(err, "channel handshake open init failed") } // Retrieve callbacks from router @@ -279,6 +282,13 @@ func (k Keeper) ChannelOpenInit(goCtx context.Context, msg *channeltypes.MsgChan return nil, sdkerrors.Wrap(err, "channel open init callback failed") } + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, connectiontypes.AttributeValueCategory), + ), + }) + return &channeltypes.MsgChannelOpenInitResponse{}, nil } @@ -291,9 +301,11 @@ func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChann return nil, sdkerrors.Wrap(err, "could not retrieve module from port-id") } - _, channelID, cap, err := channel.HandleMsgChannelOpenTry(ctx, k.ChannelKeeper, portCap, msg) + channelID, cap, err := k.ChannelKeeper.ChanOpenTry(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, msg.PreviousChannelId, + portCap, msg.Channel.Counterparty, msg.Channel.Version, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight, + ) if err != nil { - return nil, err + return nil, sdkerrors.Wrap(err, "channel handshake open try failed") } // Retrieve callbacks from router @@ -306,6 +318,13 @@ func (k Keeper) ChannelOpenTry(goCtx context.Context, msg *channeltypes.MsgChann return nil, sdkerrors.Wrap(err, "channel open try callback failed") } + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + return &channeltypes.MsgChannelOpenTryResponse{}, nil } @@ -325,15 +344,24 @@ func (k Keeper) ChannelOpenAck(goCtx context.Context, msg *channeltypes.MsgChann return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } - _, err = channel.HandleMsgChannelOpenAck(ctx, k.ChannelKeeper, cap, msg) + err = k.ChannelKeeper.ChanOpenAck( + ctx, msg.PortId, msg.ChannelId, cap, msg.CounterpartyVersion, msg.CounterpartyChannelId, msg.ProofTry, msg.ProofHeight, + ) if err != nil { - return nil, err + return nil, sdkerrors.Wrap(err, "channel handshake open ack failed") } if err = cbs.OnChanOpenAck(ctx, msg.PortId, msg.ChannelId, msg.CounterpartyVersion); err != nil { return nil, sdkerrors.Wrap(err, "channel open ack callback failed") } + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + return &channeltypes.MsgChannelOpenAckResponse{}, nil } @@ -353,15 +381,22 @@ func (k Keeper) ChannelOpenConfirm(goCtx context.Context, msg *channeltypes.MsgC return nil, sdkerrors.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module) } - _, err = channel.HandleMsgChannelOpenConfirm(ctx, k.ChannelKeeper, cap, msg) + err = k.ChannelKeeper.ChanOpenConfirm(ctx, msg.PortId, msg.ChannelId, cap, msg.ProofAck, msg.ProofHeight) if err != nil { - return nil, err + return nil, sdkerrors.Wrap(err, "channel handshake open confirm failed") } if err = cbs.OnChanOpenConfirm(ctx, msg.PortId, msg.ChannelId); err != nil { return nil, sdkerrors.Wrap(err, "channel open confirm callback failed") } + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + return &channeltypes.MsgChannelOpenConfirmResponse{}, nil } @@ -384,11 +419,18 @@ func (k Keeper) ChannelCloseInit(goCtx context.Context, msg *channeltypes.MsgCha return nil, sdkerrors.Wrap(err, "channel close init callback failed") } - _, err = channel.HandleMsgChannelCloseInit(ctx, k.ChannelKeeper, cap, msg) + err = k.ChannelKeeper.ChanCloseInit(ctx, msg.PortId, msg.ChannelId, cap) if err != nil { - return nil, err + return nil, sdkerrors.Wrap(err, "channel handshake close init failed") } + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + return &channeltypes.MsgChannelCloseInitResponse{}, nil } @@ -412,11 +454,18 @@ func (k Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Msg return nil, sdkerrors.Wrap(err, "channel close confirm callback failed") } - _, err = channel.HandleMsgChannelCloseConfirm(ctx, k.ChannelKeeper, cap, msg) + err = k.ChannelKeeper.ChanCloseConfirm(ctx, msg.PortId, msg.ChannelId, cap, msg.ProofInit, msg.ProofHeight) if err != nil { - return nil, err + return nil, sdkerrors.Wrap(err, "channel handshake close confirm failed") } + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) + return &channeltypes.MsgChannelCloseConfirmResponse{}, nil }