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

chore: add pluming necessary for testing CreateChannel #7406

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions modules/core/04-channel/v2/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"

clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
Expand Down
3 changes: 3 additions & 0 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down
25 changes: 25 additions & 0 deletions modules/core/packet-server/keeper/events.go
Original file line number Diff line number Diff line change
@@ -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),
),
})
}
19 changes: 19 additions & 0 deletions modules/core/packet-server/types/events.go
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason this is not a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just how we do it elsewhere. Intuition is this was for grouping relevant vars together. Will change if people feel it best.

Copy link
Contributor

Choose a reason for hiding this comment

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

feel like a const makes more sense here, we can worry about it when we move stuff over to msg_server_v2_land anyway


AttributeValueCategory = fmt.Sprintf("%s_%s", ibcexported.ModuleName, SubModuleName)
)
18 changes: 18 additions & 0 deletions testing/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ 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) {
merklePath := commitmenttypes.NewMerklePath([]byte("ibc"), []byte(""))
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably make []byte("") a var in testing values


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 = ParseChannelIDV2FromEvents(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
Expand Down
14 changes: 14 additions & 0 deletions testing/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,6 +57,19 @@ func ParseChannelIDFromEvents(events []abci.Event) (string, error) {
return "", errors.New("channel identifier event attribute not found")
}

// ParseChannelIDV2FromEvents parses events emitted from a CreateChannel
// and returns the channel identifier.
func ParseChannelIDV2FromEvents(events []abci.Event) (string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i guess I could also have done the parsing in ParseChannelIDFromEvents too, lmk if peeps prefer that

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I'd prefer to not have the V2 suffix in func names and stuff, personally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gotcha, will axe this and merge into other func

for _, ev := range events {
if ev.Type == packetservertypes.EventTypeCreateChannel {
if attribute, found := attributeByKey(ev.Attributes, packetservertypes.AttributeKeyChannelID); found {
return attribute.Value, nil
}
}
}
return "", errors.New("channel identifier event attribute not found")
}

// ParsePacketFromEvents parses events emitted from a send packet and returns
// the first EventTypeSendPacket packet found.
// Returns an error if no packet is found.
Expand Down
16 changes: 16 additions & 0 deletions testing/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, no! Will wire this up in next PR that makes changes in core handlers (currently this would just fail spectacularly if uncommented!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, it already does 😆

Copy link
Contributor Author

@DimitrisJim DimitrisJim Oct 7, 2024

Choose a reason for hiding this comment

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

I swear this linter adding a duplicate import is the bane of my existence


path.SetupCounterparties()
}

Expand Down Expand Up @@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess there's no room to get rid of V2 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we already have a CreateChannels 😬

Copy link
Contributor

Choose a reason for hiding this comment

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

Grimacing emoji indeed

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
Expand Down
Loading