Skip to content

Commit d206c5b

Browse files
committed
chore: clean up msgprovidecounterparty.
1 parent 8e9b8cc commit d206c5b

File tree

9 files changed

+78
-118
lines changed

9 files changed

+78
-118
lines changed

modules/core/keeper/msg_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *packetservertyp
177177
return nil, errorsmod.Wrapf(packetservertypes.ErrInvalidCounterparty, "counterparty must exist for channel %s", msg.ChannelId)
178178
}
179179

180-
counterparty.CounterpartyChannelId = msg.Counterparty.CounterpartyChannelId
180+
counterparty.CounterpartyChannelId = msg.CounterpartyChannelId
181181
k.PacketServerKeeper.SetCounterparty(ctx, msg.ChannelId, counterparty)
182182
// Delete client creator from state as it is not needed after this point.
183183
k.PacketServerKeeper.DeleteCreator(ctx, msg.ChannelId)

modules/core/keeper/msg_server_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
1818
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
1919
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
20-
commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
2120
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
2221
ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors"
2322
"github.com/cosmos/ibc-go/v9/modules/core/exported"
@@ -1218,7 +1217,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
12181217
"success",
12191218
func() {
12201219
// set it before handler
1221-
suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), msg.ChannelId, msg.Counterparty)
1220+
suite.chainA.App.GetIBCKeeper().PacketServerKeeper.SetCounterparty(suite.chainA.GetContext(), msg.ChannelId, packetservertypes.NewCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, ibctesting.MerklePath))
12221221
},
12231222
nil,
12241223
},
@@ -1246,8 +1245,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
12461245
suite.Require().NoError(path.EndpointA.CreateChannel())
12471246

12481247
signer := path.EndpointA.Chain.SenderAccount.GetAddress().String()
1249-
merklePrefix := commitmenttypesv2.NewMerklePath([]byte("mock-key"))
1250-
msg = packetservertypes.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, merklePrefix, signer)
1248+
msg = packetservertypes.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer)
12511249

12521250
tc.malleate()
12531251

@@ -1259,10 +1257,10 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
12591257
suite.Require().NotNil(resp)
12601258
suite.Require().Nil(err)
12611259

1262-
// Assert counterparty set and creator deleted
1260+
// Assert counterparty channel id filled in and creator deleted
12631261
counterparty, found := suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCounterparty(suite.chainA.GetContext(), path.EndpointA.ChannelID)
12641262
suite.Require().True(found)
1265-
suite.Require().Equal(counterparty, msg.Counterparty)
1263+
suite.Require().Equal(counterparty.CounterpartyChannelId, path.EndpointB.ChannelID)
12661264

12671265
_, found = suite.chainA.App.GetIBCKeeper().PacketServerKeeper.GetCreator(suite.chainA.GetContext(), path.EndpointA.ClientID)
12681266
suite.Require().False(found)
Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package cli
22

33
import (
4-
"encoding/hex"
54
"fmt"
6-
"strings"
75

86
"github.com/spf13/cobra"
97

@@ -12,38 +10,32 @@ import (
1210
"github.com/cosmos/cosmos-sdk/client/tx"
1311
"github.com/cosmos/cosmos-sdk/version"
1412

15-
commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
1613
"github.com/cosmos/ibc-go/v9/modules/core/exported"
1714
"github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"
1815
)
1916

2017
// newProvideCounterpartyCmd defines the command to provide the counterparty to an IBC client.
2118
func newProvideCounterpartyCmd() *cobra.Command {
2219
cmd := &cobra.Command{
23-
Use: "provide-counterparty [client-identifier] [counterparty-client-identifier] [counterparty-merkle-path-prefix]",
24-
Args: cobra.ExactArgs(3),
25-
Short: "provide the counterparty to an IBC client",
26-
Long: `Provide the counterparty to an IBC client specified by its client ID.
20+
Use: "provide-counterparty [channel-identifier] [counterparty-channel-identifier]",
21+
Args: cobra.ExactArgs(2),
22+
Short: "provide the counterparty channel to an IBC channel end",
23+
Long: `Provide the counterparty to an IBC channel end specified by its channel ID.
2724
The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded strings.`,
28-
Example: fmt.Sprintf("%s tx %s %s provide-counterparty 07-tendermint-0 07-tendermint-1 696263,657572656b61", version.AppName, exported.ModuleName, types.SubModuleName),
25+
Example: fmt.Sprintf("%s tx %s %s provide-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName),
2926
RunE: func(cmd *cobra.Command, args []string) error {
3027
clientCtx, err := client.GetClientTxContext(cmd)
3128
if err != nil {
3229
return err
3330
}
3431

35-
clientIdentifier := args[0]
36-
counterpartyClientIdentifier := args[1]
37-
counterpartyMerklePathPrefix, err := parseMerklePathPrefix(args[2])
38-
if err != nil {
39-
return err
40-
}
32+
channelID := args[0]
33+
counterpartyChannelID := args[1]
4134

42-
counterparty := types.NewCounterparty(clientIdentifier, counterpartyClientIdentifier, counterpartyMerklePathPrefix)
4335
msg := types.MsgProvideCounterparty{
44-
ChannelId: clientIdentifier,
45-
Counterparty: counterparty,
46-
Signer: clientCtx.GetFromAddress().String(),
36+
ChannelId: channelID,
37+
CounterpartyChannelId: counterpartyChannelID,
38+
Signer: clientCtx.GetFromAddress().String(),
4739
}
4840
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
4941
},
@@ -52,18 +44,3 @@ The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded s
5244
flags.AddTxFlagsToCmd(cmd)
5345
return cmd
5446
}
55-
56-
// parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath.
57-
func parseMerklePathPrefix(merklePathPrefixString string) (commitmenttypesv2.MerklePath, error) {
58-
var keyPath [][]byte
59-
hexPrefixes := strings.Split(merklePathPrefixString, ",")
60-
for _, hexPrefix := range hexPrefixes {
61-
prefix, err := hex.DecodeString(hexPrefix)
62-
if err != nil {
63-
return commitmenttypesv2.MerklePath{}, fmt.Errorf("invalid hex merkle path prefix: %w", err)
64-
}
65-
keyPath = append(keyPath, prefix)
66-
}
67-
68-
return commitmenttypesv2.MerklePath{KeyPath: keyPath}, nil
69-
}

modules/core/packet-server/types/msgs.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ var (
1616
)
1717

1818
// NewMsgProvideCounterparty creates a new MsgProvideCounterparty instance
19-
func NewMsgProvideCounterparty(clientID, counterpartyChannelID string, merklePathPrefix commitmenttypes.MerklePath, signer string) *MsgProvideCounterparty {
20-
counterparty := NewCounterparty(clientID, counterpartyChannelID, merklePathPrefix)
21-
19+
func NewMsgProvideCounterparty(channelID, counterpartyChannelID string, signer string) *MsgProvideCounterparty {
2220
return &MsgProvideCounterparty{
23-
Signer: signer,
24-
ChannelId: clientID,
25-
Counterparty: counterparty,
21+
Signer: signer,
22+
ChannelId: channelID,
23+
CounterpartyChannelId: counterpartyChannelID,
2624
}
2725
}
2826

@@ -36,7 +34,7 @@ func (msg *MsgProvideCounterparty) ValidateBasic() error {
3634
return err
3735
}
3836

39-
if err := msg.Counterparty.Validate(); err != nil {
37+
if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil {
4038
return err
4139
}
4240

modules/core/packet-server/types/msgs_test.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,25 @@ func (s *TypesTestSuite) TestMsgProvideCounterpartyValidateBasic() {
3232
ibcerrors.ErrInvalidAddress,
3333
},
3434
{
35-
"failure: invalid client ID",
35+
"failure: invalid channel ID",
3636
func() {
3737
msg.ChannelId = ""
3838
},
3939
host.ErrInvalidID,
4040
},
4141
{
42-
"failure: invalid counterparty client ID",
42+
"failure: invalid counterparty channel ID",
4343
func() {
44-
msg.Counterparty.ClientId = ""
44+
msg.CounterpartyChannelId = ""
4545
},
4646
host.ErrInvalidID,
4747
},
48-
{
49-
"failure: empty key path of counterparty of merkle path prefix",
50-
func() {
51-
msg.Counterparty.MerklePathPrefix.KeyPath = nil
52-
},
53-
types.ErrInvalidCounterparty,
54-
},
5548
}
5649

5750
for _, tc := range testCases {
5851
msg = types.NewMsgProvideCounterparty(
5952
ibctesting.FirstClientID,
6053
ibctesting.SecondClientID,
61-
commitmenttypes.NewMerklePath([]byte("key")),
6254
ibctesting.TestAccAddress,
6355
)
6456

modules/core/packet-server/types/tx.pb.go

Lines changed: 50 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/ibc/core/packetserver/v1/tx.proto

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ option go_package = "github.com/cosmos/ibc-go/v9/modules/core/packet-server/type
77

88
import "gogoproto/gogo.proto";
99
import "ibc/core/commitment/v2/commitment.proto";
10-
import "ibc/core/packetserver/v1/counterparty.proto";
1110
import "cosmos/msg/v1/msg.proto";
1211

1312
// Msg defines the ibc/packetserver Msg service.
@@ -31,8 +30,8 @@ message MsgProvideCounterparty {
3130

3231
// unique identifier we will use to write all packet messages sent to counterparty
3332
string channel_id = 1;
34-
// counterparty client
35-
Counterparty counterparty = 2 [(gogoproto.nullable) = false];
33+
// counterparty channel identifier
34+
string counterparty_channel_id = 2;
3635
// signer address
3736
string signer = 3;
3837
}

testing/endpoint.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ func (endpoint *Endpoint) FreezeClient() {
178178

179179
// ProvideCounterparty will construct and execute a MsgProvideCounterparty on the associated endpoint.
180180
func (endpoint *Endpoint) ProvideCounterparty() (err error) {
181-
merklePath := commitmenttypes.NewMerklePath([]byte("ibc"), []byte(""))
182-
183-
msg := packetservertypes.NewMsgProvideCounterparty(endpoint.ChannelID, endpoint.Counterparty.ChannelID, merklePath, endpoint.Chain.SenderAccount.GetAddress().String())
181+
msg := packetservertypes.NewMsgProvideCounterparty(endpoint.ChannelID, endpoint.Counterparty.ChannelID, endpoint.Chain.SenderAccount.GetAddress().String())
184182

185183
// setup counterparty
186184
_, err = endpoint.Chain.SendMsgs(msg)
@@ -190,7 +188,7 @@ func (endpoint *Endpoint) ProvideCounterparty() (err error) {
190188

191189
// CreateChannel will construct and execute a new MsgCreateChannel on the associated endpoint.
192190
func (endpoint *Endpoint) CreateChannel() (err error) {
193-
msg := packetservertypes.NewMsgCreateChannel(endpoint.ClientID, merklePath, endpoint.Chain.SenderAccount.GetAddress().String())
191+
msg := packetservertypes.NewMsgCreateChannel(endpoint.ClientID, MerklePath, endpoint.Chain.SenderAccount.GetAddress().String())
194192

195193
// create channel
196194
res, err := endpoint.Chain.SendMsgs(msg)

testing/values.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ var (
7777
prefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
7878
// unusedHash is a placeholder hash used for testing.
7979
unusedHash = tmhash.Sum([]byte{0x00})
80-
merklePath = commitmenttypes.NewMerklePath([]byte("ibc"), []byte(""))
80+
MerklePath = commitmenttypes.NewMerklePath([]byte("ibc"), []byte(""))
8181
)

0 commit comments

Comments
 (0)