Skip to content

Commit

Permalink
chore: rename channel to channel end in v2
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Oct 25, 2024
1 parent 15877e8 commit 2a1eb58
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 115 deletions.
6 changes: 3 additions & 3 deletions modules/core/04-channel/v2/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (suite *KeeperTestSuite) TestQueryChannel() {
var (
req *types.QueryChannelRequest
expCreator string
expChannel types.Channel
expChannel types.ChannelEnd
)

testCases := []struct {
Expand Down Expand Up @@ -53,7 +53,7 @@ func (suite *KeeperTestSuite) TestQueryChannel() {
{
"success: no channel",
func() {
expChannel = types.Channel{}
expChannel = types.ChannelEnd{}

suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID, expCreator)

Expand Down Expand Up @@ -96,7 +96,7 @@ func (suite *KeeperTestSuite) TestQueryChannel() {

expCreator = ibctesting.TestAccAddress
merklePathPrefix := commitmenttypes.NewMerklePath([]byte("prefix"))
expChannel = types.Channel{ClientId: ibctesting.SecondClientID, CounterpartyChannelId: ibctesting.SecondChannelID, MerklePathPrefix: merklePathPrefix}
expChannel = types.ChannelEnd{ClientId: ibctesting.SecondClientID, CounterpartyChannelId: ibctesting.SecondChannelID, MerklePathPrefix: merklePathPrefix}

tc.malleate()

Expand Down
22 changes: 11 additions & 11 deletions modules/core/04-channel/v2/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ func (k Keeper) ChannelStore(ctx context.Context, channelID string) storetypes.K
}

// SetChannel sets the Channel for a given channel identifier.
func (k *Keeper) SetChannel(ctx context.Context, channelID string, channel types.Channel) {
func (k *Keeper) SetChannel(ctx context.Context, channelID string, channel types.ChannelEnd) {
bz := k.cdc.MustMarshal(&channel)
k.ChannelStore(ctx, channelID).Set([]byte(types.ChannelKey), bz)
}

// GetChannel gets the Channel for a given channel identifier.
func (k *Keeper) GetChannel(ctx context.Context, channelID string) (types.Channel, bool) {
func (k *Keeper) GetChannel(ctx context.Context, channelID string) (types.ChannelEnd, bool) {
store := k.ChannelStore(ctx, channelID)
bz := store.Get([]byte(types.ChannelKey))
if len(bz) == 0 {
return types.Channel{}, false
return types.ChannelEnd{}, false
}

var channel types.Channel
var channel types.ChannelEnd
k.cdc.MustUnmarshal(bz, &channel)
return channel, true
}
Expand Down Expand Up @@ -215,23 +215,23 @@ func (k *Keeper) SetNextSequenceSend(ctx context.Context, channelID string, sequ

// AliasV1Channel returns a version 2 channel for the given port and channel ID
// by converting the channel into a version 2 channel.
func (k *Keeper) AliasV1Channel(ctx context.Context, portID, channelID string) (types.Channel, bool) {
func (k *Keeper) AliasV1Channel(ctx context.Context, portID, channelID string) (types.ChannelEnd, bool) {
channel, ok := k.channelKeeperV1.GetChannel(ctx, portID, channelID)
if !ok {
return types.Channel{}, false
return types.ChannelEnd{}, false
}
// Do not allow channel to be converted into a version 2 channel
// if the channel is not OPEN or if it is ORDERED
if channel.State != channeltypesv1.OPEN || channel.Ordering == channeltypesv1.ORDERED {
return types.Channel{}, false
return types.ChannelEnd{}, false
}
connection, ok := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
if !ok {
return types.Channel{}, false
return types.ChannelEnd{}, false
}
merklePathPrefix := commitmentv2types.NewMerklePath(connection.Counterparty.Prefix.KeyPrefix, []byte(""))

channelv2 := types.Channel{
channelv2 := types.ChannelEnd{
CounterpartyChannelId: channel.Counterparty.ChannelId,
ClientId: connection.ClientId,
MerklePathPrefix: merklePathPrefix,
Expand All @@ -241,12 +241,12 @@ func (k *Keeper) AliasV1Channel(ctx context.Context, portID, channelID string) (

// convertV1Channel attempts to retrieve a v1 channel from the channel keeper if it exists, then converts it
// to a v2 counterparty and stores it in the v2 channel keeper for future use
func (k *Keeper) convertV1Channel(ctx context.Context, port, id string) (types.Channel, bool) {
func (k *Keeper) convertV1Channel(ctx context.Context, port, id string) (types.ChannelEnd, bool) {
if channel, ok := k.AliasV1Channel(ctx, port, id); ok {
// we can key on just the channel here since channel ids are globally unique
k.SetChannel(ctx, id, channel)
return channel, true
}

return types.Channel{}, false
return types.ChannelEnd{}, false
}
6 changes: 3 additions & 3 deletions modules/core/04-channel/v2/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ func (suite *KeeperTestSuite) TestAliasV1Channel() {
suite.Require().Equal(channel, expChannel)
} else {
suite.Require().False(found)
suite.Require().Equal(channel, channeltypes2.Channel{})
suite.Require().Equal(channel, channeltypes2.ChannelEnd{})
}
})
}
}

func (suite *KeeperTestSuite) TestSetChannel() {
merklePathPrefix := commitmenttypes.NewMerklePath([]byte("ibc"), []byte(""))
channel := channeltypes2.Channel{
channel := channeltypes2.ChannelEnd{
ClientId: ibctesting.FirstClientID,
MerklePathPrefix: merklePathPrefix,
}
Expand All @@ -124,7 +124,7 @@ func (suite *KeeperTestSuite) TestSetChannel() {
// No channel stored under other channel identifier.
retrievedChannel, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), ibctesting.SecondChannelID)
suite.Require().False(found, "GetChannel unexpectedly returned a channel")
suite.Require().Equal(channeltypes2.Channel{}, retrievedChannel, "Channel retrieved not empty")
suite.Require().Equal(channeltypes2.ChannelEnd{}, retrievedChannel, "Channel retrieved not empty")
}

func (suite *KeeperTestSuite) TestSetCreator() {
Expand Down
10 changes: 5 additions & 5 deletions modules/core/04-channel/v2/types/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
)

// NewChannel creates a new Channel instance
func NewChannel(clientID, counterpartyChannelID string, merklePathPrefix commitmenttypes.MerklePath) Channel {
return Channel{
// NewChannel creates a new ChannelEnd instance
func NewChannel(clientID, counterpartyChannelID string, merklePathPrefix commitmenttypes.MerklePath) ChannelEnd {
return ChannelEnd{
ClientId: clientID,
CounterpartyChannelId: counterpartyChannelID,
MerklePathPrefix: merklePathPrefix,
}
}

// Validate validates the Channel
func (c Channel) Validate() error {
// Validate validates the ChannelEnd
func (c ChannelEnd) Validate() error {
if err := host.ClientIdentifierValidator(c.ClientId); err != nil {
return err
}
Expand Down
93 changes: 47 additions & 46 deletions modules/core/04-channel/v2/types/channel.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion modules/core/04-channel/v2/types/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func (s *TypesTestSuite) TestValidateChannel() {
var c types.Channel
var c types.ChannelEnd
testCases := []struct {
name string
malleate func()
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/v2/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func NewQueryChannelRequest(channelID string) *QueryChannelRequest {
}

// NewQueryChannelResponse creates and returns a new channel query response.
func NewQueryChannelResponse(creator string, channel Channel) *QueryChannelResponse {
func NewQueryChannelResponse(creator string, channel ChannelEnd) *QueryChannelResponse {
return &QueryChannelResponse{
Creator: creator,
Channel: channel,
Expand Down
Loading

0 comments on commit 2a1eb58

Please sign in to comment.