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

packetserver: Rename Counterparty to Channel #7429

Open
wants to merge 7 commits into
base: feat/ibc-eureka
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
16 changes: 8 additions & 8 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,28 +827,28 @@ func (k *Keeper) PruneAcknowledgements(ctx context.Context, portID, channelID st
return totalPruned, totalRemaining, nil
}

// GetV2Counterparty returns a version 2 counterparty for the given port and channel ID
// by converting the channel into a version 2 counterparty
func (k *Keeper) GetV2Counterparty(ctx context.Context, portID, channelID string) (packetserver.Counterparty, bool) {
// GetV2Channel returns a version 2 channel for the given port and channel ID
// by converting the v1 channel into a version 2 channel
func (k *Keeper) GetV2Channel(ctx context.Context, portID, channelID string) (packetserver.Channel, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Can probably remove this from classic at some point later and have it fully in the v2 pkg/codepath.

channel, ok := k.GetChannel(ctx, portID, channelID)
if !ok {
return packetserver.Counterparty{}, false
return packetserver.Channel{}, false
}
// Do not allow channel to be converted into a version 2 counterparty
// if the channel is not OPEN or if it is ORDERED
if channel.State != types.OPEN || channel.Ordering == types.ORDERED {
return packetserver.Counterparty{}, false
return packetserver.Channel{}, false
}
connection, ok := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
if !ok {
return packetserver.Counterparty{}, false
return packetserver.Channel{}, false
}
merklePathPrefix := commitmentv2types.NewMerklePath(connection.Counterparty.Prefix.KeyPrefix, []byte(""))

counterparty := packetserver.Counterparty{
channelv2 := packetserver.Channel{
CounterpartyChannelId: channel.Counterparty.ChannelId,
ClientId: connection.ClientId,
MerklePathPrefix: merklePathPrefix,
}
return counterparty, true
return channelv2, true
}
10 changes: 5 additions & 5 deletions modules/core/04-channel/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (suite *KeeperTestSuite) TestUnsetParams() {
})
}

func (suite *KeeperTestSuite) TestGetV2Counterparty() {
func (suite *KeeperTestSuite) TestGetV2Channel() {
var path *ibctesting.Path

testCases := []struct {
Expand Down Expand Up @@ -608,17 +608,17 @@ func (suite *KeeperTestSuite) TestGetV2Counterparty() {

tc.malleate()

counterparty, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetV2Counterparty(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
channel, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetV2Channel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

if tc.expPass {
suite.Require().True(found)

merklePath := commitmentv2types.NewMerklePath([]byte("ibc"), []byte(""))
expCounterparty := packetservertypes.NewCounterparty(path.EndpointA.ClientID, path.EndpointB.ChannelID, merklePath)
suite.Require().Equal(counterparty, expCounterparty)
expChannel := packetservertypes.NewChannel(path.EndpointA.ClientID, path.EndpointB.ChannelID, merklePath)
suite.Require().Equal(channel, expChannel)
} else {
suite.Require().False(found)
suite.Require().Equal(counterparty, packetservertypes.Counterparty{})
suite.Require().Equal(channel, packetservertypes.Channel{})
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions modules/core/04-channel/v2/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (k *Keeper) sendPacket(
// TODO: figure out how aliasing will work when more than one packet data is sent.
counterparty, ok = k.getV1Counterparty(ctx, data[0].SourcePort, sourceID)
if !ok {
return 0, errorsmod.Wrap(types.ErrCounterpartyNotFound, sourceID)
return 0, errorsmod.Wrap(types.ErrChannelNotFound, sourceID)
}
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func (k Keeper) recvPacket(
// TODO: figure out how aliasing will work when more than one packet data is sent.
counterparty, ok = k.getV1Counterparty(ctx, packet.Data[0].DestinationPort, packet.DestinationId)
if !ok {
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationId)
return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationId)
}
}
if counterparty.ClientId != packet.SourceId {
Expand Down Expand Up @@ -193,7 +193,7 @@ func (k Keeper) timeoutPacket(
// TODO: figure out how aliasing will work when more than one packet data is sent.
counterparty, ok = k.getV1Counterparty(ctx, packet.Data[0].SourcePort, packet.SourceId)
if !ok {
return errorsmod.Wrap(types.ErrCounterpartyNotFound, packet.DestinationId)
return errorsmod.Wrap(types.ErrChannelNotFound, packet.DestinationId)
}
}

Expand Down
16 changes: 7 additions & 9 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ var (
)

// CreateClient defines a rpc handler method for MsgCreateClient.
// It stores the signer of MsgCreateClient as the creator of the client, which is afterwards
// compared against the signer of MsgProvideCounterparty.
// NOTE: The raw bytes of the concrete types encoded into protobuf.Any is passed to the client keeper.
// The 02-client handler will route to the appropriate light client module based on client type and it is the responsibility
// of the light client module to unmarshal and interpret the proto encoded bytes.
Expand Down Expand Up @@ -148,9 +146,9 @@ func (k *Keeper) CreateChannel(goCtx context.Context, msg *packetservertypes.Msg

channelID := k.ChannelKeeper.GenerateChannelIdentifier(ctx)

// Initialize counterparty with empty counterparty channel identifier.
counterparty := packetservertypes.NewCounterparty(msg.ClientId, "", msg.MerklePathPrefix)
k.PacketServerKeeper.SetCounterparty(ctx, channelID, counterparty)
// Initialize channel with empty counterparty channel identifier.
channel := packetservertypes.NewChannel(msg.ClientId, "", msg.MerklePathPrefix)
k.PacketServerKeeper.SetChannel(ctx, channelID, channel)

k.PacketServerKeeper.SetCreator(ctx, channelID, msg.Signer)

Expand All @@ -172,13 +170,13 @@ func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertyp
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "channel creator (%s) must match signer (%s)", creator, msg.Signer)
}

counterparty, ok := k.PacketServerKeeper.GetCounterparty(ctx, msg.ChannelId)
channel, ok := k.PacketServerKeeper.GetChannel(ctx, msg.ChannelId)
if !ok {
return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidCounterparty, "counterparty must exist for channel %s", msg.ChannelId)
return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidChannel, "channel must exist for channel id %s", msg.ChannelId)
}

counterparty.CounterpartyChannelId = msg.CounterpartyChannelId
k.PacketServerKeeper.SetCounterparty(ctx, msg.ChannelId, counterparty)
channel.CounterpartyChannelId = msg.CounterpartyChannelId
k.PacketServerKeeper.SetChannel(ctx, msg.ChannelId, channel)
// Delete client creator from state as it is not needed after this point.
k.PacketServerKeeper.DeleteCreator(ctx, msg.ChannelId)

Expand Down
16 changes: 8 additions & 8 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (suite *KeeperTestSuite) TestRecvPacketV2() {
// any non-nil value of packet is valid
suite.Require().NotNil(packet)
},
packetservertypes.ErrCounterpartyNotFound,
packetservertypes.ErrChannelNotFound,
false,
false,
false,
Expand Down Expand Up @@ -658,7 +658,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacketV2() {
func() {
packet.SourceChannel = "invalid-client"
},
packetservertypes.ErrCounterpartyNotFound,
packetservertypes.ErrChannelNotFound,
false,
},
{
Expand Down Expand Up @@ -984,7 +984,7 @@ func (suite *KeeperTestSuite) TestTimeoutPacketV2() {

packetKey = host.PacketReceiptKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
},
packetservertypes.ErrCounterpartyNotFound,
packetservertypes.ErrChannelNotFound,
false,
},
}
Expand Down Expand Up @@ -1217,7 +1217,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
"success",
func() {
// set it before handler
suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), msg.ChannelId, packetservertypes.NewCounterparty(path.EndpointA.ClientID, "", ibctesting.MerklePath))
suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetChannel(suite.chainA.GetContext(), msg.ChannelId, packetservertypes.NewChannel(path.EndpointA.ClientID, "", ibctesting.MerklePath))
},
nil,
},
Expand All @@ -1231,9 +1231,9 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
{
"failure: counterparty does not already exists",
func() {
suite.chainA.App.GetIBCKeeper().PacketServerKeeper.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(packetservertypes.CounterpartyKey))
suite.chainA.App.GetIBCKeeper().PacketServerKeeper.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(packetservertypes.ChannelKey))
},
packetservertypes.ErrInvalidCounterparty,
packetservertypes.ErrInvalidChannel,
},
}

Expand All @@ -1258,9 +1258,9 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
suite.Require().Nil(err)

// Assert counterparty channel id filled in and creator deleted
counterparty, found := suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCounterparty(suite.chainA.GetContext(), path.EndpointA.ChannelID)
channel, found := suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(counterparty.CounterpartyChannelId, path.EndpointB.ChannelID)
suite.Require().Equal(channel.CounterpartyChannelId, path.EndpointB.ChannelID)

_, found = suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCreator(suite.chainA.GetContext(), path.EndpointA.ClientID)
suite.Require().False(found)
Expand Down
2 changes: 1 addition & 1 deletion modules/core/packet-server/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func GetQueryCmd() *cobra.Command {
}

queryCmd.AddCommand(
getCmdQueryClient(),
getCmdQueryChannel(),
)

return queryCmd
Expand Down
12 changes: 6 additions & 6 deletions modules/core/packet-server/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"
)

// getCmdQueryClient defines the command to query the client information (creator and counterparty) for the given client ID.
func getCmdQueryClient() *cobra.Command {
// getCmdQueryChannel defines the command to query the client information (creator and channel) for the given client ID.
func getCmdQueryChannel() *cobra.Command {
cmd := &cobra.Command{
Use: "client [client-id]",
Copy link
Member

Choose a reason for hiding this comment

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

will need to update these also within v2. I don't think there's any point in refactoring them in packet-server as it will eventually be removed, right?

happy to create an issue for CLI's and queries in v2 pkg.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should be able to move the whole folder at some point and do some tweaks. Think these can be moved along with the move of the types in channel/v2?

Short: "Query the information of a client.",
Long: "Query the client information (creator and counterparty) for the provided client ID.",
Long: "Query the client information (creator and channel) for the provided client ID.",
Example: fmt.Sprintf("%s query %s %s client [client-id]", version.AppName, exported.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -28,11 +28,11 @@ func getCmdQueryClient() *cobra.Command {
}
clientID := args[0]

queryClient := types.NewQueryClient(clientCtx)
queryChannel := types.NewQueryClient(clientCtx)

req := &types.QueryClientRequest{ClientId: clientID}
req := &types.QueryChannelRequest{ChannelId: clientID}

res, err := queryClient.Client(cmd.Context(), req)
res, err := queryChannel.Channel(cmd.Context(), req)
if err != nil {
return err
}
Expand Down
11 changes: 5 additions & 6 deletions modules/core/packet-server/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import (
"github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"
)

// newProvideCounterpartyCmd defines the command to provide the counterparty to an IBC client.
// newProvideCounterpartyCmd defines the command to provide the counterparty to an IBC channel.
func newProvideCounterpartyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "provide-counterparty [channel-identifier] [counterparty-channel-identifier]",
Args: cobra.ExactArgs(2),
Short: "provide the counterparty channel to an IBC channel end",
Long: `Provide the counterparty to an IBC channel end specified by its channel ID.
The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded strings.`,
Use: "provide-counterparty [channel-identifier] [counterparty-channel-identifier]",
Args: cobra.ExactArgs(2),
Short: "provide the counterparty channel id to an IBC channel end",
Long: `Provide the counterparty channel id to an IBC channel end specified by its channel ID.`,
Example: fmt.Sprintf("%s tx %s %s provide-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
18 changes: 9 additions & 9 deletions modules/core/packet-server/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ func NewQueryServer(k *Keeper) types.QueryServer {
}
}

// Client implements the Query/Client gRPC method
func (q *queryServer) Client(ctx context.Context, req *types.QueryClientRequest) (*types.QueryClientResponse, error) {
// Channel implements the Query/Channel gRPC method
func (q *queryServer) Channel(ctx context.Context, req *types.QueryChannelRequest) (*types.QueryChannelResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

if err := host.ClientIdentifierValidator(req.ClientId); err != nil {
if err := host.ClientIdentifierValidator(req.ChannelId); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

res := types.QueryClientResponse{}
res := types.QueryChannelResponse{}

sdkCtx := sdk.UnwrapSDKContext(ctx)

creator, foundCreator := q.GetCreator(sdkCtx, req.ClientId)
counterparty, foundCounterparty := q.GetCounterparty(sdkCtx, req.ClientId)
creator, foundCreator := q.GetCreator(sdkCtx, req.ChannelId)
channel, foundChannel := q.GetChannel(sdkCtx, req.ChannelId)

if !foundCreator && !foundCounterparty {
if !foundCreator && !foundChannel {
return nil, status.Error(
codes.NotFound,
errorsmod.Wrapf(types.ErrCounterpartyNotFound, "client-id: %s", req.ClientId).Error(),
errorsmod.Wrapf(types.ErrChannelNotFound, "channel-id: %s", req.ChannelId).Error(),
)
}

res.Counterparty = counterparty
res.Channel = channel
res.Creator = creator

return &res, nil
Expand Down
Loading
Loading