Skip to content

Commit 140283e

Browse files
committed
fix merge
2 parents bfd8d4b + 68756ec commit 140283e

28 files changed

+639
-176
lines changed

modules/core/04-channel/v2/client/cli/cli.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55

66
"github.com/cosmos/cosmos-sdk/client"
77

8-
"github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"
8+
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
99
)
1010

11-
// GetQueryCmd returns the query commands for the IBC packet-server.
11+
// GetQueryCmd returns the query commands for the IBC channel/v2.
1212
func GetQueryCmd() *cobra.Command {
1313
queryCmd := &cobra.Command{
1414
Use: types.SubModuleName,
15-
Short: "IBC packet-server query subcommands",
15+
Short: "IBC channel/v2 query subcommands",
1616
DisableFlagParsing: true,
1717
SuggestionsMinimumDistance: 2,
1818
RunE: client.ValidateCmd,
@@ -25,18 +25,19 @@ func GetQueryCmd() *cobra.Command {
2525
return queryCmd
2626
}
2727

28-
// NewTxCmd returns the command to submit transactions defined for the IBC packet-server.
28+
// NewTxCmd returns the command to submit transactions defined for IBC channel/v2.
2929
func NewTxCmd() *cobra.Command {
3030
txCmd := &cobra.Command{
3131
Use: types.SubModuleName,
32-
Short: "IBC packet-server transaction subcommands",
32+
Short: "IBC channel/v2 transaction subcommands",
3333
DisableFlagParsing: true,
3434
SuggestionsMinimumDistance: 2,
3535
RunE: client.ValidateCmd,
3636
}
3737

3838
txCmd.AddCommand(
39-
newProvideCounterpartyCmd(),
39+
newCreateChannelTxCmd(),
40+
newProvideCounterpartyTxCmd(),
4041
)
4142

4243
return txCmd

modules/core/04-channel/v2/client/cli/query.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ import (
1313
"github.com/cosmos/ibc-go/v9/modules/core/exported"
1414
)
1515

16-
// getCmdQueryChannel defines the command to query the client information (creator and channel) for the given client ID.
16+
// getCmdQueryChannel defines the command to query the channel information (creator and channel) for the given channel ID.
1717
func getCmdQueryChannel() *cobra.Command {
1818
cmd := &cobra.Command{
19-
Use: "client [client-id]",
20-
Short: "Query the information of a client.",
21-
Long: "Query the client information (creator and channel) for the provided client ID.",
22-
Example: fmt.Sprintf("%s query %s %s client [client-id]", version.AppName, exported.ModuleName, types.SubModuleName),
19+
Use: "channel [channel-id]",
20+
Short: "Query the information of a channel.",
21+
Long: "Query the channel information (creator and channel) for the provided channel ID.",
22+
Example: fmt.Sprintf("%s query %s %s channel [channel-id]", version.AppName, exported.ModuleName, types.SubModuleName),
2323
Args: cobra.ExactArgs(1),
2424
RunE: func(cmd *cobra.Command, args []string) error {
2525
clientCtx, err := client.GetClientQueryContext(cmd)
2626
if err != nil {
2727
return err
2828
}
29-
clientID := args[0]
29+
channelID := args[0]
3030

3131
queryClient := types.NewQueryClient(clientCtx)
3232

33-
req := &types.QueryChannelRequest{ChannelId: clientID}
33+
req := &types.QueryChannelRequest{ChannelId: channelID}
3434

3535
res, err := queryClient.Channel(cmd.Context(), req)
3636
if err != nil {

modules/core/04-channel/v2/client/cli/tx.go

+52-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package cli
22

33
import (
4+
"encoding/hex"
45
"fmt"
6+
"strings"
57

68
"github.com/spf13/cobra"
79

@@ -11,16 +13,47 @@ import (
1113
"github.com/cosmos/cosmos-sdk/version"
1214

1315
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
16+
commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
1417
"github.com/cosmos/ibc-go/v9/modules/core/exported"
1518
)
1619

17-
// newProvideCounterpartyCmd defines the command to provide the counterparty to an IBC channel.
18-
func newProvideCounterpartyCmd() *cobra.Command {
20+
// newCreateChannelTxCmd defines the command to create an IBC channel/v2.
21+
func newCreateChannelTxCmd() *cobra.Command {
22+
cmd := &cobra.Command{
23+
Use: "create-channel [client-identifier] [merkle-path-prefix]",
24+
Args: cobra.ExactArgs(2),
25+
Short: "create an IBC channel/v2",
26+
Long: `Creates an IBC channel/v2 using the client identifier representing the counterparty chain and the hex-encoded merkle path prefix under which the counterparty stores packet flow information.`,
27+
Example: fmt.Sprintf("%s tx %s %s create-channel 07-tendermint-0 696263,657572656b61", version.AppName, exported.ModuleName, types.SubModuleName),
28+
RunE: func(cmd *cobra.Command, args []string) error {
29+
clientCtx, err := client.GetClientTxContext(cmd)
30+
if err != nil {
31+
return err
32+
}
33+
34+
clientID := args[0]
35+
merklePathPrefix, err := parseMerklePathPrefix(args[2])
36+
if err != nil {
37+
return err
38+
}
39+
40+
msg := types.NewMsgCreateChannel(clientID, merklePathPrefix, clientCtx.GetFromAddress().String())
41+
42+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
43+
},
44+
}
45+
46+
flags.AddTxFlagsToCmd(cmd)
47+
return cmd
48+
}
49+
50+
// newProvideCounterpartyCmd defines the command to provide the counterparty channel identifier to an IBC channel.
51+
func newProvideCounterpartyTxCmd() *cobra.Command {
1952
cmd := &cobra.Command{
2053
Use: "provide-counterparty [channel-identifier] [counterparty-channel-identifier]",
2154
Args: cobra.ExactArgs(2),
22-
Short: "provide the counterparty channel id to an IBC channel end",
23-
Long: `Provide the counterparty channel id to an IBC channel end specified by its channel ID.`,
55+
Short: "provide the counterparty channel id to an IBC channel",
56+
Long: `Provide the counterparty channel id to an IBC channel specified by its channel ID.`,
2457
Example: fmt.Sprintf("%s tx %s %s provide-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName),
2558
RunE: func(cmd *cobra.Command, args []string) error {
2659
clientCtx, err := client.GetClientTxContext(cmd)
@@ -43,3 +76,18 @@ func newProvideCounterpartyCmd() *cobra.Command {
4376
flags.AddTxFlagsToCmd(cmd)
4477
return cmd
4578
}
79+
80+
// parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath.
81+
func parseMerklePathPrefix(merklePathPrefixString string) (commitmenttypesv2.MerklePath, error) {
82+
var keyPath [][]byte
83+
hexPrefixes := strings.Split(merklePathPrefixString, ",")
84+
for _, hexPrefix := range hexPrefixes {
85+
prefix, err := hex.DecodeString(hexPrefix)
86+
if err != nil {
87+
return commitmenttypesv2.MerklePath{}, fmt.Errorf("invalid hex merkle path prefix: %w", err)
88+
}
89+
keyPath = append(keyPath, prefix)
90+
}
91+
92+
return commitmenttypesv2.MerklePath{KeyPath: keyPath}, nil
93+
}

modules/core/04-channel/v2/keeper/events.go

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ func EmitTimeoutPacketEvents(ctx context.Context, packet channeltypesv2.Packet)
2828
// TODO: https://github.com/cosmos/ibc-go/issues/7386
2929
}
3030

31+
// EmitWriteAcknowledgementEvents emits events for WriteAcknowledgement.
32+
func EmitWriteAcknowledgementEvents(ctx context.Context, packet channeltypesv2.Packet, ack channeltypesv2.Acknowledgement) {
33+
// TODO: https://github.com/cosmos/ibc-go/issues/7386
34+
}
35+
3136
// EmitCreateChannelEvent emits a channel create event.
3237
func (*Keeper) EmitCreateChannelEvent(ctx context.Context, channelID string) {
3338
sdkCtx := sdk.UnwrapSDKContext(ctx)

modules/core/04-channel/v2/keeper/grpc_query.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
var _ types.QueryServer = (*queryServer)(nil)
1818

19-
// queryServer implements the packet-server types.QueryServer interface.
19+
// queryServer implements the channel/v2 types.QueryServer interface.
2020
type queryServer struct {
2121
*Keeper
2222
}

modules/core/04-channel/v2/keeper/keeper.go

+20-16
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,27 @@ func (k *Keeper) GetChannel(ctx context.Context, channelID string) (types.Channe
7979
return channel, true
8080
}
8181

82-
// GetCreator returns the creator of the client.
83-
func (k *Keeper) GetCreator(ctx context.Context, clientID string) (string, bool) {
82+
// GetCreator returns the creator of the channel.
83+
func (k *Keeper) GetCreator(ctx context.Context, channelID string) (string, bool) {
8484
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917
85-
bz := k.ChannelStore(sdkCtx, clientID).Get([]byte(types.CreatorKey))
85+
bz := k.ChannelStore(sdkCtx, channelID).Get([]byte(types.CreatorKey))
8686
if len(bz) == 0 {
8787
return "", false
8888
}
8989

9090
return string(bz), true
9191
}
9292

93-
// SetCreator sets the creator of the client.
94-
func (k *Keeper) SetCreator(ctx context.Context, clientID, creator string) {
93+
// SetCreator sets the creator of the channel.
94+
func (k *Keeper) SetCreator(ctx context.Context, channelID, creator string) {
9595
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917
96-
k.ChannelStore(sdkCtx, clientID).Set([]byte(types.CreatorKey), []byte(creator))
96+
k.ChannelStore(sdkCtx, channelID).Set([]byte(types.CreatorKey), []byte(creator))
9797
}
9898

99-
// DeleteCreator deletes the creator associated with the client.
100-
func (k *Keeper) DeleteCreator(ctx context.Context, clientID string) {
99+
// DeleteCreator deletes the creator associated with the channel.
100+
func (k *Keeper) DeleteCreator(ctx context.Context, channelID string) {
101101
sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917
102-
k.ChannelStore(sdkCtx, clientID).Delete([]byte(types.CreatorKey))
102+
k.ChannelStore(sdkCtx, channelID).Delete([]byte(types.CreatorKey))
103103
}
104104

105105
// GetPacketReceipt returns the packet receipt from the packet receipt path based on the channelID and sequence.
@@ -135,6 +135,16 @@ func (k *Keeper) SetPacketReceipt(ctx context.Context, channelID string, sequenc
135135
}
136136
}
137137

138+
// GetPacketAcknowledgement fetches the packet acknowledgement from the store.
139+
func (k *Keeper) GetPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64) []byte {
140+
store := k.storeService.OpenKVStore(ctx)
141+
bz, err := store.Get(hostv2.PacketAcknowledgementKey(channelID, sequence))
142+
if err != nil {
143+
panic(err)
144+
}
145+
return bz
146+
}
147+
138148
// SetPacketAcknowledgement writes the acknowledgement hash under the acknowledgement path
139149
// This is a public path that is standardized by the IBC V2 specification.
140150
func (k *Keeper) SetPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64, ackHash []byte) {
@@ -146,13 +156,7 @@ func (k *Keeper) SetPacketAcknowledgement(ctx context.Context, channelID string,
146156

147157
// HasPacketAcknowledgement check if the packet ack hash is already on the store.
148158
func (k *Keeper) HasPacketAcknowledgement(ctx context.Context, channelID string, sequence uint64) bool {
149-
store := k.storeService.OpenKVStore(ctx)
150-
found, err := store.Has(hostv2.PacketAcknowledgementKey(channelID, sequence))
151-
if err != nil {
152-
panic(err)
153-
}
154-
155-
return found
159+
return len(k.GetPacketAcknowledgement(ctx, channelID, sequence)) > 0
156160
}
157161

158162
// GetPacketCommitment returns the packet commitment hash under the commitment path.

modules/core/04-channel/v2/keeper/keeper_test.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -121,34 +121,33 @@ func (suite *KeeperTestSuite) TestSetChannel() {
121121
suite.Require().True(found, "GetChannel does not return channel")
122122
suite.Require().Equal(channel, retrievedChannel, "Channel retrieved not equal")
123123

124-
// Channel not yet stored for another client.
125-
retrievedChannel, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), ibctesting.SecondClientID)
124+
// No channel stored under other channel identifier.
125+
retrievedChannel, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), ibctesting.SecondChannelID)
126126
suite.Require().False(found, "GetChannel unexpectedly returned a channel")
127127
suite.Require().Equal(channeltypes2.Channel{}, retrievedChannel, "Channel retrieved not empty")
128128
}
129129

130130
func (suite *KeeperTestSuite) TestSetCreator() {
131-
clientID := ibctesting.FirstClientID
132131
expectedCreator := "test-creator"
133132

134133
// Set the creator for the client
135-
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), clientID, expectedCreator)
134+
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID, expectedCreator)
136135

137136
// Retrieve the creator from the store
138-
retrievedCreator, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), clientID)
137+
retrievedCreator, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID)
139138

140139
// Verify that the retrieved creator matches the expected creator
141140
suite.Require().True(found, "GetCreator did not return stored creator")
142141
suite.Require().Equal(expectedCreator, retrievedCreator, "Creator is not retrieved correctly")
143142

144-
// Verify non stored creator is not found
145-
retrievedCreator, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.SecondClientID)
143+
// Verify that the creator is deleted from the store
144+
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID)
145+
retrievedCreator, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID)
146146
suite.Require().False(found, "GetCreator unexpectedly returned a creator")
147147
suite.Require().Empty(retrievedCreator, "Creator is not empty")
148148

149-
// Verify that the creator is deleted from the store
150-
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), clientID)
151-
retrievedCreator, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), clientID)
149+
// Verify non stored creator is not found
150+
retrievedCreator, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), ibctesting.SecondChannelID)
152151
suite.Require().False(found, "GetCreator unexpectedly returned a creator")
153152
suite.Require().Empty(retrievedCreator, "Creator is not empty")
154153
}

0 commit comments

Comments
 (0)