diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 216d8947438..2daf744cc75 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -16,6 +16,7 @@ import ( porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" "github.com/cosmos/ibc-go/v9/modules/core/internal/telemetry" + packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper" packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" coretypes "github.com/cosmos/ibc-go/v9/modules/core/types" ) @@ -155,6 +156,8 @@ func (k *Keeper) CreateChannel(goCtx context.Context, msg *packetservertypes.Msg k.ClientKeeper.SetCreator(ctx, channelID, msg.Signer) + packetserverkeeper.EmitCreateChannelEvent(goCtx, channelID) + return &packetservertypes.MsgCreateChannelResponse{ChannelId: channelID}, nil } diff --git a/modules/core/packet-server/keeper/events.go b/modules/core/packet-server/keeper/events.go new file mode 100644 index 00000000000..64f5c023205 --- /dev/null +++ b/modules/core/packet-server/keeper/events.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" +) + +// EmitCreateChannelEvent emits a channel create event. +func EmitCreateChannelEvent(ctx context.Context, channelID string) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + sdkCtx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + types.EventTypeCreateChannel, + sdk.NewAttribute(types.AttributeKeyChannelID, channelID), + ), + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + }) +} diff --git a/modules/core/packet-server/types/events.go b/modules/core/packet-server/types/events.go new file mode 100644 index 00000000000..6166f0422d1 --- /dev/null +++ b/modules/core/packet-server/types/events.go @@ -0,0 +1,19 @@ +package types + +import ( + "fmt" + + ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported" +) + +// IBC channel events +const ( + AttributeKeyChannelID = "channel_id" +) + +// IBC channel events vars +var ( + EventTypeCreateChannel = "create_channel" + + AttributeValueCategory = fmt.Sprintf("%s_%s", ibcexported.ModuleName, SubModuleName) +) diff --git a/testing/endpoint.go b/testing/endpoint.go index f3ef692bea6..689f71089fb 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -188,6 +188,22 @@ func (endpoint *Endpoint) ProvideCounterparty() (err error) { return err } +// CreateChannel will construct and execute a new MsgCreateChannel on the associated endpoint. +func (endpoint *Endpoint) CreateChannel() (err error) { + msg := packetservertypes.NewMsgCreateChannel(endpoint.ClientID, merklePath, endpoint.Chain.SenderAccount.GetAddress().String()) + + // create channel + res, err := endpoint.Chain.SendMsgs(msg) + if err != nil { + return err + } + + endpoint.ChannelID, err = ParseChannelIDFromEvents(res.Events) + require.NoError(endpoint.Chain.TB, err) + + return nil +} + // UpgradeChain will upgrade a chain's chainID to the next revision number. // It will also update the counterparty client. // TODO: implement actual upgrade chain functionality via scheduling an upgrade diff --git a/testing/events.go b/testing/events.go index 7c467c5e48c..0fa3cfafb73 100644 --- a/testing/events.go +++ b/testing/events.go @@ -14,6 +14,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" + packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types" ) // ParseClientIDFromEvents parses events emitted from a MsgCreateClient and returns the @@ -44,10 +45,10 @@ func ParseConnectionIDFromEvents(events []abci.Event) (string, error) { } // ParseChannelIDFromEvents parses events emitted from a MsgChannelOpenInit or -// MsgChannelOpenTry and returns the channel identifier. +// MsgChannelOpenTry or a MsgCreateChannel and returns the channel identifier. func ParseChannelIDFromEvents(events []abci.Event) (string, error) { for _, ev := range events { - if ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry { + if ev.Type == packetservertypes.EventTypeCreateChannel || ev.Type == channeltypes.EventTypeChannelOpenInit || ev.Type == channeltypes.EventTypeChannelOpenTry { if attribute, found := attributeByKey(ev.Attributes, channeltypes.AttributeKeyChannelID); found { return attribute.Value, nil } diff --git a/testing/path.go b/testing/path.go index fc9c0aac564..6cca511eded 100644 --- a/testing/path.go +++ b/testing/path.go @@ -152,6 +152,9 @@ func (path *Path) Setup() { // This is all that is necessary for path setup with the Eureka (V2) protocol func (path *Path) SetupV2() { path.SetupClients() + + // path.CreateChannelsV2() + path.SetupCounterparties() } @@ -252,6 +255,19 @@ func (path *Path) CreateChannels() { } } +// CreateChannelsV2 initializes two channel endpoints by executing CreateChannel on both chainA and chainB. +func (path *Path) CreateChannelsV2() { + err := path.EndpointA.CreateChannel() + if err != nil { + panic(err) + } + + err = path.EndpointB.CreateChannel() + if err != nil { + panic(err) + } +} + // EnableFeeOnPath enables fee on a channel given a path. func EnableFeeOnPath(path *Path) *Path { path.EndpointA.ChannelConfig.Version = ibcmock.MockFeeVersion diff --git a/testing/values.go b/testing/values.go index c5920910681..61fe31badbb 100644 --- a/testing/values.go +++ b/testing/values.go @@ -77,4 +77,5 @@ var ( prefix = commitmenttypes.NewMerklePrefix([]byte("ibc")) // unusedHash is a placeholder hash used for testing. unusedHash = tmhash.Sum([]byte{0x00}) + merklePath = commitmenttypes.NewMerklePath([]byte("ibc"), []byte("")) )