From 9a601ac8a52636cf8107e10fbbb7408c6ef47032 Mon Sep 17 00:00:00 2001 From: vishal Date: Sat, 10 Aug 2024 19:53:23 +0530 Subject: [PATCH 1/8] wip --- modules/core/02-client/client/cli/cli.go | 1 + modules/core/02-client/client/cli/tx.go | 39 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/modules/core/02-client/client/cli/cli.go b/modules/core/02-client/client/cli/cli.go index 2490668f122..073b3ca56ec 100644 --- a/modules/core/02-client/client/cli/cli.go +++ b/modules/core/02-client/client/cli/cli.go @@ -50,6 +50,7 @@ func NewTxCmd() *cobra.Command { newUpgradeClientCmd(), newSubmitRecoverClientProposalCmd(), newScheduleIBCUpgradeProposalCmd(), + newMsgProvideCounterpartycmd(), ) return txCmd diff --git a/modules/core/02-client/client/cli/tx.go b/modules/core/02-client/client/cli/tx.go index 223343dbfd9..128fd734d42 100644 --- a/modules/core/02-client/client/cli/tx.go +++ b/modules/core/02-client/client/cli/tx.go @@ -450,3 +450,42 @@ func newScheduleIBCUpgradeProposalCmd() *cobra.Command { return cmd } + +// client identifier, the counterparty client identifier and the counterparty merkle path prefix +func newMsgProvideCounterpartycmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "", + Args: cobra.ExactArgs(3), + Short: "", + Long: ``, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + signer := clientCtx.FromAddress.String() + clientIdentifier := args[0] + counterPartyClientIdentifier := args[1] + counterPartyMerklePathPrefix := args[2] + + counterParty := types.NewCounterparty(counterPartyClientIdentifier, counterPartyMerklePathPrefix) + msg := types.MsgProvideCounterparty{ + ClientId: clientIdentifier, + Counterparty: counterParty, + Signer: signer, + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) + }, + } + + cmd.Flags().String(FlagAuthority, "", "The address of the client module authority (defaults to gov)") + + flags.AddTxFlagsToCmd(cmd) + govcli.AddGovPropFlagsToCmd(cmd) + err := cmd.MarkFlagRequired(govcli.FlagTitle) + if err != nil { + panic(err) + } + + return cmd +} From b9c2aff78346307c0f1253781ebcea6e5d631fe1 Mon Sep 17 00:00:00 2001 From: vishal Date: Sat, 10 Aug 2024 20:03:55 +0530 Subject: [PATCH 2/8] wip --- modules/core/02-client/client/cli/cli.go | 2 +- modules/core/02-client/client/cli/tx.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/core/02-client/client/cli/cli.go b/modules/core/02-client/client/cli/cli.go index 073b3ca56ec..71b47035c02 100644 --- a/modules/core/02-client/client/cli/cli.go +++ b/modules/core/02-client/client/cli/cli.go @@ -50,7 +50,7 @@ func NewTxCmd() *cobra.Command { newUpgradeClientCmd(), newSubmitRecoverClientProposalCmd(), newScheduleIBCUpgradeProposalCmd(), - newMsgProvideCounterpartycmd(), + newMsgProvideCounterPartycmd(), ) return txCmd diff --git a/modules/core/02-client/client/cli/tx.go b/modules/core/02-client/client/cli/tx.go index 128fd734d42..1e9333e0211 100644 --- a/modules/core/02-client/client/cli/tx.go +++ b/modules/core/02-client/client/cli/tx.go @@ -20,6 +20,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" + v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -452,7 +453,7 @@ func newScheduleIBCUpgradeProposalCmd() *cobra.Command { } // client identifier, the counterparty client identifier and the counterparty merkle path prefix -func newMsgProvideCounterpartycmd() *cobra.Command { +func newMsgProvideCounterPartycmd() *cobra.Command { cmd := &cobra.Command{ Use: "", Args: cobra.ExactArgs(3), @@ -466,9 +467,9 @@ func newMsgProvideCounterpartycmd() *cobra.Command { signer := clientCtx.FromAddress.String() clientIdentifier := args[0] counterPartyClientIdentifier := args[1] - counterPartyMerklePathPrefix := args[2] + counterPartyMerklePathPrefix := v2.NewMerklePath([]byte(args[2])) - counterParty := types.NewCounterparty(counterPartyClientIdentifier, counterPartyMerklePathPrefix) + counterParty := types.NewCounterparty(counterPartyClientIdentifier, &counterPartyMerklePathPrefix) msg := types.MsgProvideCounterparty{ ClientId: clientIdentifier, Counterparty: counterParty, From 49c266e65ff1a71ebceed0088b59d5bdb31ac833 Mon Sep 17 00:00:00 2001 From: vishal Date: Sat, 10 Aug 2024 20:07:43 +0530 Subject: [PATCH 3/8] chore: added description --- modules/core/02-client/client/cli/tx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/02-client/client/cli/tx.go b/modules/core/02-client/client/cli/tx.go index 1e9333e0211..9de3fed61c8 100644 --- a/modules/core/02-client/client/cli/tx.go +++ b/modules/core/02-client/client/cli/tx.go @@ -455,9 +455,9 @@ func newScheduleIBCUpgradeProposalCmd() *cobra.Command { // client identifier, the counterparty client identifier and the counterparty merkle path prefix func newMsgProvideCounterPartycmd() *cobra.Command { cmd := &cobra.Command{ - Use: "", + Use: "provide-counter-party [clientIdentifier] [counterPartyClientIdentifier] [counterPartyMerklePathPrefix]", Args: cobra.ExactArgs(3), - Short: "", + Short: "Submits the transaction with MsgProvideCounterparty", Long: ``, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) From e90e0d3acd700c6b94ff63cafc573509bb81b608 Mon Sep 17 00:00:00 2001 From: vishal Date: Sun, 11 Aug 2024 10:09:57 +0530 Subject: [PATCH 4/8] fix: fixed lint issues --- modules/core/02-client/client/cli/tx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/02-client/client/cli/tx.go b/modules/core/02-client/client/cli/tx.go index 9de3fed61c8..422af06c3d2 100644 --- a/modules/core/02-client/client/cli/tx.go +++ b/modules/core/02-client/client/cli/tx.go @@ -20,7 +20,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) From bb233ca34a9e5d62bfd6334c1b5449a295ee6ded Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 12 Aug 2024 08:41:47 +0200 Subject: [PATCH 5/8] address my self-review --- modules/core/02-client/client/cli/cli.go | 2 +- modules/core/02-client/client/cli/tx.go | 32 +++++++++--------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/modules/core/02-client/client/cli/cli.go b/modules/core/02-client/client/cli/cli.go index 71b47035c02..4b05f4dbac0 100644 --- a/modules/core/02-client/client/cli/cli.go +++ b/modules/core/02-client/client/cli/cli.go @@ -50,7 +50,7 @@ func NewTxCmd() *cobra.Command { newUpgradeClientCmd(), newSubmitRecoverClientProposalCmd(), newScheduleIBCUpgradeProposalCmd(), - newMsgProvideCounterPartycmd(), + newProvideCounterpartyCmd(), ) return txCmd diff --git a/modules/core/02-client/client/cli/tx.go b/modules/core/02-client/client/cli/tx.go index 422af06c3d2..b01aede13af 100644 --- a/modules/core/02-client/client/cli/tx.go +++ b/modules/core/02-client/client/cli/tx.go @@ -20,7 +20,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -452,41 +452,33 @@ func newScheduleIBCUpgradeProposalCmd() *cobra.Command { return cmd } -// client identifier, the counterparty client identifier and the counterparty merkle path prefix -func newMsgProvideCounterPartycmd() *cobra.Command { +// newProvideCounterpartyCmd defines the command to provide the counterparty to an IBC client. +func newProvideCounterpartyCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "provide-counter-party [clientIdentifier] [counterPartyClientIdentifier] [counterPartyMerklePathPrefix]", + Use: "provide-counterparty [client-identifier] [counterparty-client-identifier] [counterparty-merkle-path-prefix]", Args: cobra.ExactArgs(3), - Short: "Submits the transaction with MsgProvideCounterparty", - Long: ``, + Short: "provide the counterparty to an IBC client", + Long: `Provide the counterparty to an IBC client specified by its client ID.`, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - signer := clientCtx.FromAddress.String() + clientIdentifier := args[0] - counterPartyClientIdentifier := args[1] - counterPartyMerklePathPrefix := v2.NewMerklePath([]byte(args[2])) + counterpartyClientIdentifier := args[1] + counterpartyMerklePathPrefix := v2.NewMerklePath([]byte(args[2])) - counterParty := types.NewCounterparty(counterPartyClientIdentifier, &counterPartyMerklePathPrefix) + counterparty := types.NewCounterparty(counterpartyClientIdentifier, &counterpartyMerklePathPrefix) msg := types.MsgProvideCounterparty{ ClientId: clientIdentifier, - Counterparty: counterParty, - Signer: signer, + Counterparty: counterparty, + Signer: clientCtx.GetFromAddress().String(), } return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) }, } - cmd.Flags().String(FlagAuthority, "", "The address of the client module authority (defaults to gov)") - flags.AddTxFlagsToCmd(cmd) - govcli.AddGovPropFlagsToCmd(cmd) - err := cmd.MarkFlagRequired(govcli.FlagTitle) - if err != nil { - panic(err) - } - return cmd } From fb90437d61ab6d62d0c3c05458d46113d6544902 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 12 Aug 2024 08:55:39 +0200 Subject: [PATCH 6/8] lint --- modules/core/02-client/client/cli/tx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/02-client/client/cli/tx.go b/modules/core/02-client/client/cli/tx.go index b01aede13af..fd6eff6329e 100644 --- a/modules/core/02-client/client/cli/tx.go +++ b/modules/core/02-client/client/cli/tx.go @@ -20,7 +20,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" - v2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" + commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" "github.com/cosmos/ibc-go/v9/modules/core/exported" ) @@ -467,7 +467,7 @@ func newProvideCounterpartyCmd() *cobra.Command { clientIdentifier := args[0] counterpartyClientIdentifier := args[1] - counterpartyMerklePathPrefix := v2.NewMerklePath([]byte(args[2])) + counterpartyMerklePathPrefix := commitmenttypesv2.NewMerklePath([]byte(args[2])) counterparty := types.NewCounterparty(counterpartyClientIdentifier, &counterpartyMerklePathPrefix) msg := types.MsgProvideCounterparty{ From 88891f4eba821990e0dee036e737a6f4b31bad5b Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Fri, 23 Aug 2024 20:56:00 +0200 Subject: [PATCH 7/8] accept hex-encoded strings for merkle path prefix --- modules/core/02-client/client/cli/tx.go | 28 ++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/core/02-client/client/cli/tx.go b/modules/core/02-client/client/cli/tx.go index fd6eff6329e..884172ffac6 100644 --- a/modules/core/02-client/client/cli/tx.go +++ b/modules/core/02-client/client/cli/tx.go @@ -1,9 +1,11 @@ package cli import ( + "encoding/hex" "fmt" "os" "strconv" + "strings" "github.com/spf13/cobra" @@ -458,7 +460,9 @@ func newProvideCounterpartyCmd() *cobra.Command { Use: "provide-counterparty [client-identifier] [counterparty-client-identifier] [counterparty-merkle-path-prefix]", Args: cobra.ExactArgs(3), Short: "provide the counterparty to an IBC client", - Long: `Provide the counterparty to an IBC client specified by its client ID.`, + Long: `Provide the counterparty to an IBC client specified by its client ID. +The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded strings.`, + Example: fmt.Sprintf("%s tx %s %s provide-counterparty 07-tendermint-0 07-tendermint-1 696263,657572656b61", version.AppName, exported.ModuleName, types.SubModuleName), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { @@ -467,9 +471,12 @@ func newProvideCounterpartyCmd() *cobra.Command { clientIdentifier := args[0] counterpartyClientIdentifier := args[1] - counterpartyMerklePathPrefix := commitmenttypesv2.NewMerklePath([]byte(args[2])) + counterpartyMerklePathPrefix, err := parseMerklePathPrefix(args[2]) + if err != nil { + return err + } - counterparty := types.NewCounterparty(counterpartyClientIdentifier, &counterpartyMerklePathPrefix) + counterparty := types.NewCounterparty(counterpartyClientIdentifier, counterpartyMerklePathPrefix) msg := types.MsgProvideCounterparty{ ClientId: clientIdentifier, Counterparty: counterparty, @@ -482,3 +489,18 @@ func newProvideCounterpartyCmd() *cobra.Command { flags.AddTxFlagsToCmd(cmd) return cmd } + +// parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath. +func parseMerklePathPrefix(merklePathPrefixString string) (*commitmenttypesv2.MerklePath, error) { + var keyPath [][]byte + hexPrefixes := strings.Split(merklePathPrefixString, ",") + for _, hexPrefix := range hexPrefixes { + prefix, err := hex.DecodeString(hexPrefix) + if err != nil { + return nil, fmt.Errorf("invalid hex merkle path prefix: %w", err) + } + keyPath = append(keyPath, prefix) + } + + return &commitmenttypesv2.MerklePath{KeyPath: keyPath}, nil +} From 39bbd3ee527ff1a91eab96fae63150800874e376 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Sun, 25 Aug 2024 22:52:02 +0200 Subject: [PATCH 8/8] fix build error --- modules/core/02-client/client/cli/tx.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/02-client/client/cli/tx.go b/modules/core/02-client/client/cli/tx.go index 884172ffac6..8f4242ec6ca 100644 --- a/modules/core/02-client/client/cli/tx.go +++ b/modules/core/02-client/client/cli/tx.go @@ -491,16 +491,16 @@ The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded s } // parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath. -func parseMerklePathPrefix(merklePathPrefixString string) (*commitmenttypesv2.MerklePath, error) { +func parseMerklePathPrefix(merklePathPrefixString string) (commitmenttypesv2.MerklePath, error) { var keyPath [][]byte hexPrefixes := strings.Split(merklePathPrefixString, ",") for _, hexPrefix := range hexPrefixes { prefix, err := hex.DecodeString(hexPrefix) if err != nil { - return nil, fmt.Errorf("invalid hex merkle path prefix: %w", err) + return commitmenttypesv2.MerklePath{}, fmt.Errorf("invalid hex merkle path prefix: %w", err) } keyPath = append(keyPath, prefix) } - return &commitmenttypesv2.MerklePath{KeyPath: keyPath}, nil + return commitmenttypesv2.MerklePath{KeyPath: keyPath}, nil }