From a7aef3e5e1a22c314b308f1307730a235cc2ae26 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:00:57 +0200 Subject: [PATCH] feat!: remove the ignite `relayer` and `tools` commands with all ts-relayer logic (backport #4076) (#4226) * feat!: remove the ignite `realyer` and `tools` commands with all ts-realyer logic (#4076) * remove ts relayer * remove unused commands * remove ts relayer * fix hermes relayer cmd for integration tests * add relayer command ad default * remove unused function * Update changelog.md * bump default hermes plugin version * bump relayer into the tests * run go mod tidy * rollback relayer command into the integration tests --------- Co-authored-by: Pantani (cherry picked from commit 77b665f52715391cd4b1c15fb108201b2fb9c3de) # Conflicts: # go.mod # go.sum # ignite/cmd/relayer.go # ignite/cmd/relayer_configure.go # ignite/cmd/relayer_connect.go # ignite/cmd/tools.go # ignite/pkg/nodetime/programs/ts-relayer/tsrelayer.go # ignite/pkg/relayer/chain.go # ignite/pkg/relayer/config/config.go # ignite/pkg/relayer/relayer.go * fix merge conflicts * fix changelog * bump hermes version * bump hermes to future version for don't break the default plugin path * remove unused commands * rollback integration/plugin/testdata/example-plugin/go.mod * rollback ignite/internal/plugin/testdata * rollback integration/plugin/testdata/example-plugin/go.mod --------- Co-authored-by: Danilo Pantani --- changelog.md | 1 + ignite/cmd/cmd.go | 6 - ignite/cmd/plugin_default.go | 24 +- ignite/cmd/plugin_default_test.go | 2 + ignite/cmd/relayer.go | 33 -- ignite/cmd/relayer_configure.go | 514 ------------------ ignite/cmd/relayer_connect.go | 120 ---- ignite/cmd/tools.go | 68 --- ignite/internal/tools/gen-cli-docs/main.go | 13 +- ignite/pkg/nodetime/nodetime.go | 9 - .../nodetime/programs/ts-relayer/tsrelayer.go | 69 --- ignite/pkg/relayer/chain.go | 310 ----------- ignite/pkg/relayer/config/config.go | 99 ---- ignite/pkg/relayer/relayer.go | 288 ---------- integration/relayer/cmd_relayer_test.go | 83 ++- 15 files changed, 66 insertions(+), 1573 deletions(-) delete mode 100644 ignite/cmd/relayer.go delete mode 100644 ignite/cmd/relayer_configure.go delete mode 100644 ignite/cmd/relayer_connect.go delete mode 100644 ignite/cmd/tools.go delete mode 100644 ignite/pkg/nodetime/programs/ts-relayer/tsrelayer.go delete mode 100644 ignite/pkg/relayer/chain.go delete mode 100644 ignite/pkg/relayer/config/config.go delete mode 100644 ignite/pkg/relayer/relayer.go diff --git a/changelog.md b/changelog.md index 0e326fd005..03a0c25f5f 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ ### Features - [#4183](https://github.com/ignite/cli/pull/4183) Set `chain-id` in the client.toml +- [#4076](https://github.com/ignite/cli/pull/4076) Remove the ignite `relayer` and `tools` commands with all ts-relayer logic - [#4133](https://github.com/ignite/cli/pull/4133) Improve buf rate limit ### Changes diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 012f4ad8da..b21e2b75f0 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -77,8 +77,6 @@ To get started, create a blockchain: NewGenerate(), NewNode(), NewAccount(), - NewRelayer(), - NewTools(), NewDocs(), NewVersion(), NewApp(), @@ -207,10 +205,6 @@ func checkNewVersion(ctx context.Context) { fmt.Printf("⬆️ Ignite CLI %s is available! To upgrade: https://docs.ignite.com/welcome/install#upgrade", next) } -func printSection(session *cliui.Session, title string) error { - return session.Printf("------\n%s\n------\n\n", title) -} - func newCache(cmd *cobra.Command) (cache.Storage, error) { cacheRootDir, err := config.DirPath() if err != nil { diff --git a/ignite/cmd/plugin_default.go b/ignite/cmd/plugin_default.go index 60c6b62ff2..4f0e65dcf4 100644 --- a/ignite/cmd/plugin_default.go +++ b/ignite/cmd/plugin_default.go @@ -18,21 +18,31 @@ type defaultPlugin struct { const ( PluginNetworkVersion = "v0.2.2" PluginNetworkPath = "github.com/ignite/cli-plugin-network@" + PluginNetworkVersion + PluginRelayerVersion = "hermes/v0.2.4" + PluginRelayerPath = "github.com/ignite/apps/hermes@" + PluginRelayerVersion ) // defaultPlugins holds the plugin that are considered trustable and for which // a command will added if the plugin is not already installed. // When the user executes that command, the plugin is automatically installed. var defaultPlugins = []defaultPlugin{ - { - use: "network", - short: "Launch a blockchain in production", - aliases: []string{"n"}, - path: PluginNetworkPath, - }, + // TODO uncomment after fix SPN. Don't forget to un-skip TestEnsureDefaultPlugins. + // { + // use: "network", + // short: "Launch a blockchain in production", + // aliases: []string{"n"}, + // path: PluginNetworkPath, + // }, + // TODO uncomment after launch the `hermes/v0.2.4`. Don't forget to un-skip TestEnsureDefaultPlugins. + // { + // use: "relayer", + // short: "Connect blockchains with an IBC relayer", + // aliases: []string{"r"}, + // path: PluginRelayerPath, + // }, } -// ensureDefaultPlugins ensures that all defaultPlugins are wether registered +// ensureDefaultPlugins ensures that all defaultPlugins are whether registered // in cfg OR have an install command added to rootCmd. func ensureDefaultPlugins(rootCmd *cobra.Command, cfg *pluginsconfig.Config) { for _, dp := range defaultPlugins { diff --git a/ignite/cmd/plugin_default_test.go b/ignite/cmd/plugin_default_test.go index d7b4bc0ae8..c231ff7acf 100644 --- a/ignite/cmd/plugin_default_test.go +++ b/ignite/cmd/plugin_default_test.go @@ -10,6 +10,8 @@ import ( ) func TestEnsureDefaultPlugins(t *testing.T) { + t.Skip("skip till we have default plugins again") + tests := []struct { name string cfg *pluginsconfig.Config diff --git a/ignite/cmd/relayer.go b/ignite/cmd/relayer.go deleted file mode 100644 index 2e72dd1093..0000000000 --- a/ignite/cmd/relayer.go +++ /dev/null @@ -1,33 +0,0 @@ -package ignitecmd - -import ( - "github.com/spf13/cobra" - - "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" - "github.com/ignite/cli/v28/ignite/pkg/errors" -) - -// NewRelayer returns a new relayer command. -func NewRelayer() *cobra.Command { - c := &cobra.Command{ - Use: "relayer", - Aliases: []string{"r"}, - Short: "Connect blockchains with an IBC relayer", - } - - c.AddCommand( - NewRelayerConfigure(), - NewRelayerConnect(), - ) - - return c -} - -func handleRelayerAccountErr(err error) error { - var accountErr *cosmosaccount.AccountDoesNotExistError - if !errors.As(err, &accountErr) { - return err - } - - return errors.Wrap(accountErr, `make sure to create or import your account through "ignite account" commands`) -} diff --git a/ignite/cmd/relayer_configure.go b/ignite/cmd/relayer_configure.go deleted file mode 100644 index 9bd736d001..0000000000 --- a/ignite/cmd/relayer_configure.go +++ /dev/null @@ -1,514 +0,0 @@ -package ignitecmd - -import ( - "fmt" - - "github.com/gookit/color" - "github.com/spf13/cobra" - - "github.com/ignite/cli/v28/ignite/pkg/cliui" - "github.com/ignite/cli/v28/ignite/pkg/cliui/cliquiz" - "github.com/ignite/cli/v28/ignite/pkg/cliui/entrywriter" - "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" - "github.com/ignite/cli/v28/ignite/pkg/errors" - "github.com/ignite/cli/v28/ignite/pkg/relayer" - relayerconfig "github.com/ignite/cli/v28/ignite/pkg/relayer/config" -) - -const ( - flagAdvanced = "advanced" - flagSourceAccount = "source-account" - flagTargetAccount = "target-account" - flagSourceRPC = "source-rpc" - flagTargetRPC = "target-rpc" - flagSourceFaucet = "source-faucet" - flagTargetFaucet = "target-faucet" - flagSourcePort = "source-port" - flagSourceVersion = "source-version" - flagTargetPort = "target-port" - flagTargetVersion = "target-version" - flagSourceGasPrice = "source-gasprice" - flagTargetGasPrice = "target-gasprice" - flagSourceGasLimit = "source-gaslimit" - flagTargetGasLimit = "target-gaslimit" - flagSourceAddressPrefix = "source-prefix" - flagTargetAddressPrefix = "target-prefix" - flagOrdered = "ordered" - flagReset = "reset" - flagSourceClientID = "source-client-id" - flagTargetClientID = "target-client-id" - - RelayerSource = "source" - RelayerTarget = "target" - - defaultSourceRPCAddress = "http://localhost:26657" - defaultTargetRPCAddress = "https://rpc.cosmos.directory:443/cosmoshub" - - defautSourceGasPrice = "0.00025stake" - defautTargetGasPrice = "0.025uatom" - defautSourceGasLimit = 300000 - defautTargetGasLimit = 300000 - defautSourceAddressPrefix = "cosmos" - defautTargetAddressPrefix = "cosmos" -) - -// NewRelayerConfigure returns a new relayer configure command. -// faucet addresses are optional and connect command will try to guess the address -// when not provided. even if auto retrieving coins fails, connect command will complete with success. -func NewRelayerConfigure() *cobra.Command { - c := &cobra.Command{ - Use: "configure", - Short: "Configure source and target chains for relaying", - Aliases: []string{"conf"}, - RunE: relayerConfigureHandler, - } - - c.Flags().BoolP(flagAdvanced, "a", false, "advanced configuration options for custom IBC modules") - c.Flags().String(flagSourceRPC, "", "RPC address of the source chain") - c.Flags().String(flagTargetRPC, "", "RPC address of the target chain") - c.Flags().String(flagSourceFaucet, "", "faucet address of the source chain") - c.Flags().String(flagTargetFaucet, "", "faucet address of the target chain") - c.Flags().String(flagSourcePort, "", "IBC port ID on the source chain") - c.Flags().String(flagSourceVersion, "", "module version on the source chain") - c.Flags().String(flagTargetPort, "", "IBC port ID on the target chain") - c.Flags().String(flagTargetVersion, "", "module version on the target chain") - c.Flags().String(flagSourceGasPrice, "", "gas price used for transactions on source chain") - c.Flags().String(flagTargetGasPrice, "", "gas price used for transactions on target chain") - c.Flags().Int64(flagSourceGasLimit, 0, "gas limit used for transactions on source chain") - c.Flags().Int64(flagTargetGasLimit, 0, "gas limit used for transactions on target chain") - c.Flags().String(flagSourceAddressPrefix, "", "address prefix of the source chain") - c.Flags().String(flagTargetAddressPrefix, "", "address prefix of the target chain") - c.Flags().String(flagSourceAccount, "", "source Account") - c.Flags().String(flagTargetAccount, "", "target Account") - c.Flags().Bool(flagOrdered, false, "set the channel as ordered") - c.Flags().BoolP(flagReset, "r", false, "reset the relayer config") - c.Flags().String(flagSourceClientID, "", "use a custom client id for source") - c.Flags().String(flagTargetClientID, "", "use a custom client id for target") - c.Flags().AddFlagSet(flagSetKeyringBackend()) - c.Flags().AddFlagSet(flagSetKeyringDir()) - - return c -} - -func relayerConfigureHandler(cmd *cobra.Command, _ []string) (err error) { - defer func() { - err = handleRelayerAccountErr(err) - }() - - session := cliui.New() - defer session.End() - - ca, err := cosmosaccount.New( - cosmosaccount.WithKeyringBackend(getKeyringBackend(cmd)), - cosmosaccount.WithHome(getKeyringDir(cmd)), - ) - if err != nil { - return err - } - - if err := ca.EnsureDefaultAccount(); err != nil { - return err - } - - if err := printSection(session, "Setting up chains"); err != nil { - return err - } - - // basic configuration - var ( - sourceAccount string - targetAccount string - sourceRPCAddress string - targetRPCAddress string - sourceFaucetAddress string - targetFaucetAddress string - sourceGasPrice string - targetGasPrice string - sourceGasLimit int64 - targetGasLimit int64 - sourceAddressPrefix string - targetAddressPrefix string - ) - - // advanced configuration for the channel - var ( - sourcePort string - sourceVersion string - targetPort string - targetVersion string - ) - - // questions - var ( - questionSourceAccount = cliquiz.NewQuestion( - "Source Account", - &sourceAccount, - cliquiz.DefaultAnswer(cosmosaccount.DefaultAccount), - cliquiz.Required(), - ) - questionTargetAccount = cliquiz.NewQuestion( - "Target Account", - &targetAccount, - cliquiz.DefaultAnswer(cosmosaccount.DefaultAccount), - cliquiz.Required(), - ) - questionSourceRPCAddress = cliquiz.NewQuestion( - "Source RPC", - &sourceRPCAddress, - cliquiz.DefaultAnswer(defaultSourceRPCAddress), - cliquiz.Required(), - ) - questionSourceFaucet = cliquiz.NewQuestion( - "Source Faucet", - &sourceFaucetAddress, - ) - questionTargetRPCAddress = cliquiz.NewQuestion( - "Target RPC", - &targetRPCAddress, - cliquiz.DefaultAnswer(defaultTargetRPCAddress), - cliquiz.Required(), - ) - questionTargetFaucet = cliquiz.NewQuestion( - "Target Faucet", - &targetFaucetAddress, - ) - questionSourcePort = cliquiz.NewQuestion( - "Source Port", - &sourcePort, - cliquiz.DefaultAnswer(relayer.TransferPort), - cliquiz.Required(), - ) - questionSourceVersion = cliquiz.NewQuestion( - "Source Version", - &sourceVersion, - cliquiz.DefaultAnswer(relayer.TransferVersion), - cliquiz.Required(), - ) - questionTargetPort = cliquiz.NewQuestion( - "Target Port", - &targetPort, - cliquiz.DefaultAnswer(relayer.TransferPort), - cliquiz.Required(), - ) - questionTargetVersion = cliquiz.NewQuestion( - "Target Version", - &targetVersion, - cliquiz.DefaultAnswer(relayer.TransferVersion), - cliquiz.Required(), - ) - questionSourceGasPrice = cliquiz.NewQuestion( - "Source Gas Price", - &sourceGasPrice, - cliquiz.DefaultAnswer(defautSourceGasPrice), - cliquiz.Required(), - ) - questionTargetGasPrice = cliquiz.NewQuestion( - "Target Gas Price", - &targetGasPrice, - cliquiz.DefaultAnswer(defautTargetGasPrice), - cliquiz.Required(), - ) - questionSourceGasLimit = cliquiz.NewQuestion( - "Source Gas Limit", - &sourceGasLimit, - cliquiz.DefaultAnswer(defautSourceGasLimit), - cliquiz.Required(), - ) - questionTargetGasLimit = cliquiz.NewQuestion( - "Target Gas Limit", - &targetGasLimit, - cliquiz.DefaultAnswer(defautTargetGasLimit), - cliquiz.Required(), - ) - questionSourceAddressPrefix = cliquiz.NewQuestion( - "Source Address Prefix", - &sourceAddressPrefix, - cliquiz.DefaultAnswer(defautSourceAddressPrefix), - cliquiz.Required(), - ) - questionTargetAddressPrefix = cliquiz.NewQuestion( - "Target Address Prefix", - &targetAddressPrefix, - cliquiz.DefaultAnswer(defautTargetAddressPrefix), - cliquiz.Required(), - ) - ) - - // Get flags - advanced, err := cmd.Flags().GetBool(flagAdvanced) - if err != nil { - return err - } - sourceAccount, err = cmd.Flags().GetString(flagSourceAccount) - if err != nil { - return err - } - targetAccount, err = cmd.Flags().GetString(flagTargetAccount) - if err != nil { - return err - } - sourceRPCAddress, err = cmd.Flags().GetString(flagSourceRPC) - if err != nil { - return err - } - sourceFaucetAddress, err = cmd.Flags().GetString(flagSourceFaucet) - if err != nil { - return err - } - targetRPCAddress, err = cmd.Flags().GetString(flagTargetRPC) - if err != nil { - return err - } - targetFaucetAddress, err = cmd.Flags().GetString(flagTargetFaucet) - if err != nil { - return err - } - sourcePort, err = cmd.Flags().GetString(flagSourcePort) - if err != nil { - return err - } - sourceVersion, err = cmd.Flags().GetString(flagSourceVersion) - if err != nil { - return err - } - targetPort, err = cmd.Flags().GetString(flagTargetPort) - if err != nil { - return err - } - targetVersion, err = cmd.Flags().GetString(flagTargetVersion) - if err != nil { - return err - } - sourceGasPrice, err = cmd.Flags().GetString(flagSourceGasPrice) - if err != nil { - return err - } - targetGasPrice, err = cmd.Flags().GetString(flagTargetGasPrice) - if err != nil { - return err - } - sourceGasLimit, err = cmd.Flags().GetInt64(flagSourceGasLimit) - if err != nil { - return err - } - targetGasLimit, err = cmd.Flags().GetInt64(flagTargetGasLimit) - if err != nil { - return err - } - sourceAddressPrefix, err = cmd.Flags().GetString(flagSourceAddressPrefix) - if err != nil { - return err - } - targetAddressPrefix, err = cmd.Flags().GetString(flagTargetAddressPrefix) - if err != nil { - return err - } - ordered, err := cmd.Flags().GetBool(flagOrdered) - if err != nil { - return err - } - var ( - sourceClientID, _ = cmd.Flags().GetString(flagSourceClientID) - targetClientID, _ = cmd.Flags().GetString(flagTargetClientID) - reset, _ = cmd.Flags().GetBool(flagReset) - - questions []cliquiz.Question - ) - - // get information from prompt if flag not provided - if sourceAccount == "" { - questions = append(questions, questionSourceAccount) - } - if targetAccount == "" { - questions = append(questions, questionTargetAccount) - } - if sourceRPCAddress == "" { - questions = append(questions, questionSourceRPCAddress) - } - if sourceFaucetAddress == "" { - questions = append(questions, questionSourceFaucet) - } - if targetRPCAddress == "" { - questions = append(questions, questionTargetRPCAddress) - } - if targetFaucetAddress == "" { - questions = append(questions, questionTargetFaucet) - } - if sourceGasPrice == "" { - questions = append(questions, questionSourceGasPrice) - } - if targetGasPrice == "" { - questions = append(questions, questionTargetGasPrice) - } - if sourceGasLimit == 0 { - questions = append(questions, questionSourceGasLimit) - } - if targetGasLimit == 0 { - questions = append(questions, questionTargetGasLimit) - } - if sourceAddressPrefix == "" { - questions = append(questions, questionSourceAddressPrefix) - } - if targetAddressPrefix == "" { - questions = append(questions, questionTargetAddressPrefix) - } - // advanced information - if advanced { - if sourcePort == "" { - questions = append(questions, questionSourcePort) - } - if sourceVersion == "" { - questions = append(questions, questionSourceVersion) - } - if targetPort == "" { - questions = append(questions, questionTargetPort) - } - if targetVersion == "" { - questions = append(questions, questionTargetVersion) - } - } - - session.PauseSpinner() - if len(questions) > 0 { - if err := session.Ask(questions...); err != nil { - return err - } - } - - if reset { - if err := relayerconfig.Delete(); err != nil { - return err - } - } - - session.StartSpinner("Fetching chain info...") - - session.Println() - r := relayer.New(ca) - - // initialize the chains - sourceChain, err := InitChain( - cmd, - r, - session, - RelayerSource, - sourceAccount, - sourceRPCAddress, - sourceFaucetAddress, - sourceGasPrice, - sourceGasLimit, - sourceAddressPrefix, - sourceClientID, - ) - if err != nil { - return err - } - - if err := sourceChain.EnsureChainSetup(cmd.Context()); err != nil { - return err - } - - targetChain, err := InitChain( - cmd, - r, - session, - RelayerTarget, - targetAccount, - targetRPCAddress, - targetFaucetAddress, - targetGasPrice, - targetGasLimit, - targetAddressPrefix, - targetClientID, - ) - if err != nil { - return err - } - - if err := targetChain.EnsureChainSetup(cmd.Context()); err != nil { - return err - } - - session.StartSpinner("Configuring...") - - // sets advanced channel options - var channelOptions []relayer.ChannelOption - if advanced { - channelOptions = append(channelOptions, - relayer.SourcePort(sourcePort), - relayer.SourceVersion(sourceVersion), - relayer.TargetPort(targetPort), - relayer.TargetVersion(targetVersion), - ) - - if ordered { - channelOptions = append(channelOptions, relayer.Ordered()) - } - } - - // create the connection configuration - id, err := sourceChain.Connect(targetChain, channelOptions...) - if err != nil { - return err - } - - return session.Printf("⛓ Configured chains: %s\n\n", color.Green.Sprint(id)) -} - -// InitChain initializes chain information for the relayer connection. -func InitChain( - cmd *cobra.Command, - r relayer.Relayer, - session *cliui.Session, - name, - accountName, - rpcAddr, - faucetAddr, - gasPrice string, - gasLimit int64, - addressPrefix, - clientID string, -) (*relayer.Chain, error) { - defer session.StopSpinner() - session.StartSpinner(fmt.Sprintf("Initializing chain %s...", name)) - - c, account, err := r.NewChain( - accountName, - rpcAddr, - relayer.WithFaucet(faucetAddr), - relayer.WithGasPrice(gasPrice), - relayer.WithGasLimit(gasLimit), - relayer.WithAddressPrefix(addressPrefix), - relayer.WithClientID(clientID), - ) - if err != nil { - return nil, errors.Wrapf(err, "cannot resolve %s", name) - } - - accountAddr, err := account.Address(addressPrefix) - if err != nil { - return nil, err - } - - session.StopSpinner() - session.Printf("🔐 Account on %q is %s(%s)\n \n", name, accountName, accountAddr) - session.StartSpinner(color.Yellow.Sprintf("trying to receive tokens from a faucet...")) - - coins, err := c.TryRetrieve(cmd.Context()) - - session.StopSpinner() - session.Print(" |· ") - if err != nil { - session.Println(color.Yellow.Sprintf(err.Error())) - } else { - session.Println(color.Green.Sprintf("received coins from a faucet")) - } - - balance := coins.String() - if balance == "" { - balance = entrywriter.None - } - session.Printf(" |· (balance: %s)\n\n", balance) - - return c, nil -} diff --git a/ignite/cmd/relayer_connect.go b/ignite/cmd/relayer_connect.go deleted file mode 100644 index 409a5faf37..0000000000 --- a/ignite/cmd/relayer_connect.go +++ /dev/null @@ -1,120 +0,0 @@ -package ignitecmd - -import ( - "bytes" - "fmt" - "text/tabwriter" - - "github.com/spf13/cobra" - - "github.com/ignite/cli/v28/ignite/pkg/cliui" - "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" - "github.com/ignite/cli/v28/ignite/pkg/relayer" -) - -// NewRelayerConnect returns a new relayer connect command to link all or some relayer paths and start -// relaying txs in between. -// if not paths are specified, all paths are linked. -func NewRelayerConnect() *cobra.Command { - c := &cobra.Command{ - Use: "connect [,...]", - Short: "Link chains associated with paths and start relaying tx packets in between", - RunE: relayerConnectHandler, - } - - c.Flags().AddFlagSet(flagSetKeyringBackend()) - c.Flags().AddFlagSet(flagSetKeyringDir()) - - return c -} - -func relayerConnectHandler(cmd *cobra.Command, args []string) (err error) { - defer func() { - err = handleRelayerAccountErr(err) - }() - - session := cliui.New() - defer session.End() - - ca, err := cosmosaccount.New( - cosmosaccount.WithKeyringBackend(getKeyringBackend(cmd)), - cosmosaccount.WithHome(getKeyringDir(cmd)), - ) - if err != nil { - return err - } - - if err := ca.EnsureDefaultAccount(); err != nil { - return err - } - - var ( - use []string - ids = args - r = relayer.New(ca) - ) - - all, err := r.ListPaths(cmd.Context()) - if err != nil { - return err - } - - // if no path ids provided, then we connect all of them otherwise, - // only connect the specified ones. - if len(ids) == 0 { - for _, path := range all { - use = append(use, path.ID) - } - } else { - for _, id := range ids { - for _, path := range all { - if id == path.ID { - use = append(use, path.ID) - break - } - } - } - } - - if len(use) == 0 { - return session.Println("No chains found to connect.") - } - - session.StartSpinner("Creating links between chains...") - - if err := r.LinkPaths(cmd.Context(), use...); err != nil { - return err - } - - session.StopSpinner() - - if err := printSection(session, "Paths"); err != nil { - return err - } - - for _, id := range use { - session.StartSpinner("Loading...") - - path, err := r.GetPath(cmd.Context(), id) - if err != nil { - return err - } - - session.StopSpinner() - - var buf bytes.Buffer - w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', tabwriter.TabIndent) - fmt.Fprintf(w, "%s:\n", path.ID) - fmt.Fprintf(w, " \t%s\t>\t(port: %s)\t(channel: %s)\n", path.Src.ChainID, path.Src.PortID, path.Src.ChannelID) - fmt.Fprintf(w, " \t%s\t>\t(port: %s)\t(channel: %s)\n", path.Dst.ChainID, path.Dst.PortID, path.Dst.ChannelID) - fmt.Fprintln(w) - w.Flush() - session.Print(buf.String()) - } - - if err := printSection(session, "Listening and relaying packets between chains..."); err != nil { - return err - } - - return r.StartPaths(cmd.Context(), use...) -} diff --git a/ignite/cmd/tools.go b/ignite/cmd/tools.go deleted file mode 100644 index 803adf8ae6..0000000000 --- a/ignite/cmd/tools.go +++ /dev/null @@ -1,68 +0,0 @@ -package ignitecmd - -import ( - "context" - "os" - - "github.com/spf13/cobra" - - "github.com/ignite/cli/v28/ignite/pkg/cmdrunner" - "github.com/ignite/cli/v28/ignite/pkg/cmdrunner/step" - "github.com/ignite/cli/v28/ignite/pkg/nodetime" -) - -// NewTools returns a command where various tools (binaries) are attached as sub commands -// for advanced users. -func NewTools() *cobra.Command { - c := &cobra.Command{ - Use: "tools", - Short: "Tools for advanced users", - } - c.AddCommand( - NewToolsIBCSetup(), - NewToolsIBCRelayer(), - ) - return c -} - -func NewToolsIBCSetup() *cobra.Command { - return &cobra.Command{ - Use: "ibc-setup [--] [...]", - Short: "Collection of commands to quickly setup a relayer", - RunE: toolsNodetimeProxy(nodetime.CommandIBCSetup), - Example: `ignite tools ibc-setup -- -h -ignite tools ibc-setup -- init --src relayer_test_1 --dest relayer_test_2`, - } -} - -func NewToolsIBCRelayer() *cobra.Command { - return &cobra.Command{ - Use: "ibc-relayer [--] [...]", - Short: "TypeScript implementation of an IBC relayer", - RunE: toolsNodetimeProxy(nodetime.CommandIBCRelayer), - Example: `ignite tools ibc-relayer -- -h`, - } -} - -func toolsNodetimeProxy(c nodetime.CommandName) func(cmd *cobra.Command, args []string) error { - return func(cmd *cobra.Command, args []string) error { - command, cleanup, err := nodetime.Command(c) - if err != nil { - return err - } - defer cleanup() - - return toolsProxy(cmd.Context(), append(command, args...)) - } -} - -func toolsProxy(ctx context.Context, command []string) error { - return cmdrunner.New().Run( - ctx, - step.New( - step.Exec(command[0], command[1:]...), - step.Stdout(os.Stdout), - step.Stderr(os.Stderr), - ), - ) -} diff --git a/ignite/internal/tools/gen-cli-docs/main.go b/ignite/internal/tools/gen-cli-docs/main.go index 1259908c02..33c59c30c5 100644 --- a/ignite/internal/tools/gen-cli-docs/main.go +++ b/ignite/internal/tools/gen-cli-docs/main.go @@ -58,10 +58,15 @@ func run(outPath string) error { if err != nil { return err } - cfg.Apps = append(cfg.Apps, pluginsconfig.Plugin{ - // Add network plugin - Path: ignitecmd.PluginNetworkPath, - }) + // cfg.Apps = append( + // cfg.Apps, + // TODO uncomment after fix SPN. + // Add network plugin. + // pluginsconfig.Plugin{Path: ignitecmd.PluginNetworkPath}, + // TODO uncomment after launch the `hermes/v0.2.4`. + // Add relayer plugin. + // pluginsconfig.Plugin{Path: ignitecmd.PluginRelayerPath}, + // ) if err := cfg.Save(); err != nil { return err } diff --git a/ignite/pkg/nodetime/nodetime.go b/ignite/pkg/nodetime/nodetime.go index 65569fbf7d..44556ad352 100644 --- a/ignite/pkg/nodetime/nodetime.go +++ b/ignite/pkg/nodetime/nodetime.go @@ -25,15 +25,6 @@ const ( // CommandSwaggerCombine is https://www.npmjs.com/package/swagger-combine. CommandSwaggerCombine CommandName = "swagger-combine" - - // CommandIBCSetup is https://github.com/confio/ts-relayer/blob/main/spec/ibc-setup.md. - CommandIBCSetup = "ibc-setup" - - // CommandIBCRelayer is https://github.com/confio/ts-relayer/blob/main/spec/ibc-relayer.md. - CommandIBCRelayer = "ibc-relayer" - - // CommandXRelayer is a relayer wrapper for Ignite CLI made using the confio relayer. - CommandXRelayer = "xrelayer" ) // CommandName represents a high level command under nodetime. diff --git a/ignite/pkg/nodetime/programs/ts-relayer/tsrelayer.go b/ignite/pkg/nodetime/programs/ts-relayer/tsrelayer.go deleted file mode 100644 index 9710d8fdd4..0000000000 --- a/ignite/pkg/nodetime/programs/ts-relayer/tsrelayer.go +++ /dev/null @@ -1,69 +0,0 @@ -package tsrelayer - -import ( - "bufio" - "bytes" - "context" - "fmt" - "io" - - "github.com/gorilla/rpc/v2/json2" - "golang.org/x/sync/errgroup" - - "github.com/ignite/cli/v28/ignite/pkg/cmdrunner" - "github.com/ignite/cli/v28/ignite/pkg/cmdrunner/step" - "github.com/ignite/cli/v28/ignite/pkg/errors" - "github.com/ignite/cli/v28/ignite/pkg/nodetime" -) - -// Call calls a method in the ts relayer wrapper lib with args and fills reply from the returned value. -func Call(ctx context.Context, method string, args, reply interface{}) error { - command, cleanup, err := nodetime.Command(nodetime.CommandXRelayer) - if err != nil { - return err - } - defer cleanup() - - req, err := json2.EncodeClientRequest(method, args) - if err != nil { - return err - } - - r, w := io.Pipe() - - g, ctx := errgroup.WithContext(ctx) - g.Go(func() error { - defer w.Close() - - return cmdrunner.New().Run( - ctx, - step.New( - step.Exec(command[0], command[1:]...), - step.Write(req), - step.Stdout(w), - ), - ) - }) - - // regular logs can be printed to the stdout by the other process before a jsonrpc response is emitted. - // differentiate both kinds and simulate printing regular logs if there are any. - sc := bufio.NewScanner(r) - for sc.Scan() { - err = json2.DecodeClientResponse(bytes.NewReader(sc.Bytes()), reply) - - var e *json2.Error - if errors.As(err, &e) || errors.Is(err, json2.ErrNullResult) { // jsonrpc returned with a server-side error. - return err - } - - if err != nil { // a line printed to the stdout by the other process. - fmt.Println(sc.Text()) - } - } - - if err := sc.Err(); err != nil { - return err - } - - return g.Wait() -} diff --git a/ignite/pkg/relayer/chain.go b/ignite/pkg/relayer/chain.go deleted file mode 100644 index 619a2d10d4..0000000000 --- a/ignite/pkg/relayer/chain.go +++ /dev/null @@ -1,310 +0,0 @@ -package relayer - -import ( - "context" - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/imdario/mergo" - - "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" - "github.com/ignite/cli/v28/ignite/pkg/cosmosclient" - "github.com/ignite/cli/v28/ignite/pkg/cosmosfaucet" - "github.com/ignite/cli/v28/ignite/pkg/errors" - relayerconfig "github.com/ignite/cli/v28/ignite/pkg/relayer/config" -) - -const ( - TransferPort = "transfer" - TransferVersion = "ics20-1" - OrderingUnordered = "ORDER_UNORDERED" - OrderingOrdered = "ORDER_ORDERED" -) - -var errEndpointExistsWithDifferentChainID = errors.New("rpc endpoint already exists with a different chain id") - -// Chain represents a chain in relayer. -type Chain struct { - // ID is id of the chain. - ID string - - // accountName is account used on the chain. - accountName string - - // rpcAddress is the node address of tm. - rpcAddress string - - // faucetAddress is the faucet address to get tokens for relayer accounts. - faucetAddress string - - // gasPrice is the gas price used when sending transactions to the chain - gasPrice string - - // gasLimit is the gas limit used when sending transactions to the chain - gasLimit int64 - - // addressPrefix is the address prefix of the chain. - addressPrefix string - - // clientID is the client id of the chain for relayer connection. - clientID string - - r Relayer -} - -// Account represents an account in relayer. -type Account struct { - // Address of the account. - Address string `json:"address"` -} - -// Option is used to configure Chain. -type Option func(*Chain) - -// WithFaucet provides a faucet address for chain to get tokens from. -// when it isn't provided. -func WithFaucet(address string) Option { - return func(c *Chain) { - c.faucetAddress = address - } -} - -// WithGasPrice gives the gas price to use to send ibc transactions to the chain. -func WithGasPrice(gasPrice string) Option { - return func(c *Chain) { - c.gasPrice = gasPrice - } -} - -// WithGasLimit gives the gas limit to use to send ibc transactions to the chain. -func WithGasLimit(limit int64) Option { - return func(c *Chain) { - c.gasLimit = limit - } -} - -// WithAddressPrefix configures the account key prefix used on the chain. -func WithAddressPrefix(addressPrefix string) Option { - return func(c *Chain) { - c.addressPrefix = addressPrefix - } -} - -// WithClientID configures the chain client id. -func WithClientID(clientID string) Option { - return func(c *Chain) { - c.clientID = clientID - } -} - -// NewChain creates a new chain on relayer or uses the existing matching chain. -func (r Relayer) NewChain(accountName, rpcAddress string, options ...Option) ( - *Chain, cosmosaccount.Account, error, -) { - c := &Chain{ - accountName: accountName, - rpcAddress: fixRPCAddress(rpcAddress), - r: r, - } - - // apply user options. - for _, o := range options { - o(c) - } - - account, err := r.ca.GetByName(accountName) - if err != nil { - return nil, cosmosaccount.Account{}, err - } - - return c, account, nil -} - -// TryRetrieve tries to receive some coins to the account and returns the total balance. -func (c *Chain) TryRetrieve(ctx context.Context) (sdk.Coins, error) { - acc, err := c.r.ca.GetByName(c.accountName) - if err != nil { - return nil, err - } - - addr, err := acc.Address(c.addressPrefix) - if err != nil { - return nil, err - } - - if err = cosmosfaucet.TryRetrieve(ctx, c.ID, c.rpcAddress, c.faucetAddress, addr); err != nil { - return nil, err - } - return c.r.balance(ctx, c.rpcAddress, c.accountName, c.addressPrefix) -} - -func (c *Chain) Config() relayerconfig.Chain { - return relayerconfig.Chain{ - ID: c.ID, - Account: c.accountName, - AddressPrefix: c.addressPrefix, - RPCAddress: c.rpcAddress, - GasPrice: c.gasPrice, - GasLimit: c.gasLimit, - ClientID: c.clientID, - } -} - -// channelOptions represents options for configuring the IBC channel between two chains. -type channelOptions struct { - sourcePort string - sourceVersion string - targetPort string - targetVersion string - ordering string -} - -// newChannelOptions returns default channel options. -func newChannelOptions() channelOptions { - return channelOptions{ - sourcePort: TransferPort, - sourceVersion: TransferVersion, - targetPort: TransferPort, - targetVersion: TransferVersion, - ordering: OrderingUnordered, - } -} - -// ChannelOption is used to configure relayer IBC connection. -type ChannelOption func(*channelOptions) - -// SourcePort configures the source port of the new channel. -func SourcePort(port string) ChannelOption { - return func(c *channelOptions) { - c.sourcePort = port - } -} - -// TargetPort configures the target port of the new channel. -func TargetPort(port string) ChannelOption { - return func(c *channelOptions) { - c.targetPort = port - } -} - -// SourceVersion configures the source version of the new channel. -func SourceVersion(version string) ChannelOption { - return func(c *channelOptions) { - c.sourceVersion = version - } -} - -// TargetVersion configures the target version of the new channel. -func TargetVersion(version string) ChannelOption { - return func(c *channelOptions) { - c.targetVersion = version - } -} - -// Ordered sets the new channel as ordered. -func Ordered() ChannelOption { - return func(c *channelOptions) { - c.ordering = OrderingOrdered - } -} - -// Connect connects dst chain to c chain and creates a path in between in offline mode. -// it returns the path id on success otherwise, returns with a non-nil error. -func (c *Chain) Connect(dst *Chain, options ...ChannelOption) (id string, err error) { - channelOptions := newChannelOptions() - - for _, apply := range options { - apply(&channelOptions) - } - - conf, err := relayerconfig.Get() - if err != nil { - return "", err - } - - // determine a unique path name from chain ids with incremental numbers. e.g.: - // - src-dst - // - src-dst-2 - pathID := PathID(c.ID, dst.ID) - var suffix string - i := 2 - for { - guess := pathID + suffix - if _, err := conf.PathByID(guess); err != nil { // guess is unique. - pathID = guess - break - } - suffix = fmt.Sprintf("-%d", i) - i++ - } - - confPath := relayerconfig.Path{ - ID: pathID, - Ordering: channelOptions.ordering, - Src: relayerconfig.PathEnd{ - ChainID: c.ID, - PortID: channelOptions.sourcePort, - Version: channelOptions.sourceVersion, - }, - Dst: relayerconfig.PathEnd{ - ChainID: dst.ID, - PortID: channelOptions.targetPort, - Version: channelOptions.targetVersion, - }, - } - - conf.Paths = append(conf.Paths, confPath) - - if err := relayerconfig.Save(conf); err != nil { - return "", err - } - - return pathID, nil -} - -// EnsureChainSetup sets up the new or existing chain. -func (c *Chain) EnsureChainSetup(ctx context.Context) error { - client, err := cosmosclient.New(ctx, cosmosclient.WithNodeAddress(c.rpcAddress)) - if err != nil { - return err - } - status, err := client.RPC.Status(ctx) - if err != nil { - return err - } - c.ID = status.NodeInfo.Network - - confChain := c.Config() - conf, err := relayerconfig.Get() - if err != nil { - return err - } - - var found bool - - for i, chain := range conf.Chains { - if chain.ID == c.ID { - if chain.RPCAddress != c.rpcAddress { - return errEndpointExistsWithDifferentChainID - } - - if err := mergo.Merge(&conf.Chains[i], confChain, mergo.WithOverride); err != nil { - return err - } - - found = true - break - } - } - - if !found { - conf.Chains = append(conf.Chains, confChain) - } - - return relayerconfig.Save(conf) -} - -// PathID creates path name from chain ids. -func PathID(srcChainID, dstChainID string) string { - return fmt.Sprintf("%s-%s", srcChainID, dstChainID) -} diff --git a/ignite/pkg/relayer/config/config.go b/ignite/pkg/relayer/config/config.go deleted file mode 100644 index 8e872835cd..0000000000 --- a/ignite/pkg/relayer/config/config.go +++ /dev/null @@ -1,99 +0,0 @@ -package relayerconf - -import ( - "os" - "reflect" - - "github.com/ignite/cli/v28/ignite/pkg/confile" - "github.com/ignite/cli/v28/ignite/pkg/errors" -) - -const SupportVersion = "2" - -var configPath = os.ExpandEnv("$HOME/.ignite/relayer/config.yml") - -var ( - ErrChainCannotBeFound = errors.New("chain cannot be found") - ErrPathCannotBeFound = errors.New("path cannot be found") -) - -type Config struct { - Version string `json:"version" yaml:"version"` - Chains []Chain `json:"chains" yaml:"chains,omitempty"` - Paths []Path `json:"paths" yaml:"paths,omitempty"` -} - -func (c Config) ChainByID(id string) (Chain, error) { - for _, chain := range c.Chains { - if chain.ID == id { - return chain, nil - } - } - return Chain{}, errors.Wrap(ErrChainCannotBeFound, id) -} - -func (c Config) PathByID(id string) (Path, error) { - for _, path := range c.Paths { - if path.ID == id { - return path, nil - } - } - return Path{}, errors.Wrap(ErrPathCannotBeFound, id) -} - -func (c Config) UpdatePath(path Path) error { - for i, p := range c.Paths { - if p.ID == path.ID { - c.Paths[i] = path - return nil - } - } - return errors.Wrap(ErrPathCannotBeFound, path.ID) -} - -type Chain struct { - ID string `json:"id" yaml:"id"` - Account string `json:"account" yaml:"account"` - AddressPrefix string `json:"address_prefix" yaml:"address_prefix"` - RPCAddress string `json:"rpc_address" yaml:"rpc_address"` - GasPrice string `json:"gas_price" yaml:"gas_price,omitempty"` - GasLimit int64 `json:"gas_limit" yaml:"gas_limit,omitempty"` - ClientID string `json:"client_id" yaml:"client_id,omitempty"` -} - -type Path struct { - ID string `json:"id" yaml:"id"` - Ordering string `json:"ordering" yaml:"ordering,omitempty"` - Src PathEnd `json:"src" yaml:"src"` - Dst PathEnd `json:"dst" yaml:"dst"` -} - -type PathEnd struct { - ChainID string `json:"chain_id" yaml:"chain_id"` - ConnectionID string `json:"connection_id" yaml:"connection_id,omitempty"` - ChannelID string `json:"channel_id" yaml:"channel_id,omitempty"` - PortID string `json:"port_id" yaml:"port_id"` - Version string `json:"version" yaml:"version,omitempty"` - PacketHeight int64 `json:"packet_height" yaml:"packet_height,omitempty"` - AckHeight int64 `json:"ack_height" yaml:"ack_height,omitempty"` -} - -func Get() (Config, error) { - c := Config{} - if err := confile.New(confile.DefaultYAMLEncodingCreator, configPath).Load(&c); err != nil { - return c, err - } - if !reflect.DeepEqual(c, Config{}) && c.Version != SupportVersion { - return c, errors.Errorf("your relayer setup is outdated. run 'rm %s' and configure relayer again", configPath) - } - return c, nil -} - -func Save(c Config) error { - c.Version = SupportVersion - return confile.New(confile.DefaultYAMLEncodingCreator, configPath).Save(c) -} - -func Delete() error { - return os.RemoveAll(configPath) -} diff --git a/ignite/pkg/relayer/relayer.go b/ignite/pkg/relayer/relayer.go deleted file mode 100644 index 932d449ccc..0000000000 --- a/ignite/pkg/relayer/relayer.go +++ /dev/null @@ -1,288 +0,0 @@ -package relayer - -import ( - "context" - "encoding/hex" - "strings" - "sync" - "time" - - "github.com/cosmos/cosmos-sdk/crypto" - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "golang.org/x/sync/errgroup" - - "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" - "github.com/ignite/cli/v28/ignite/pkg/cosmosclient" - "github.com/ignite/cli/v28/ignite/pkg/ctxticker" - "github.com/ignite/cli/v28/ignite/pkg/errors" - tsrelayer "github.com/ignite/cli/v28/ignite/pkg/nodetime/programs/ts-relayer" - relayerconf "github.com/ignite/cli/v28/ignite/pkg/relayer/config" - "github.com/ignite/cli/v28/ignite/pkg/xurl" -) - -const ( - algoSecp256k1 = "secp256k1" - ibcSetupGas int64 = 2256000 - relayDuration = time.Second * 5 -) - -// ErrLinkedPath indicates that an IBC path is already liked. -var ErrLinkedPath = errors.New("path already linked") - -// Relayer is an IBC relayer. -type Relayer struct { - ca cosmosaccount.Registry -} - -// New creates a new IBC relayer and uses ca to access accounts. -func New(ca cosmosaccount.Registry) Relayer { - return Relayer{ - ca: ca, - } -} - -// LinkPaths links all chains that has a path from config file to each other. -// paths are optional and acts as a filter to only link some chains. -// calling Link multiple times for the same paths does not have any side effects. -func (r Relayer) LinkPaths( - ctx context.Context, - pathIDs ...string, -) error { - conf, err := relayerconf.Get() - if err != nil { - return err - } - - for _, id := range pathIDs { - conf, err = r.Link(ctx, conf, id) - if err != nil { - // Continue with next path when current one is already linked - if errors.Is(err, ErrLinkedPath) { - continue - } - return err - } - if err := relayerconf.Save(conf); err != nil { - return err - } - } - return nil -} - -// Link links chain path to each other. -func (r Relayer) Link( - ctx context.Context, - conf relayerconf.Config, - pathID string, -) (relayerconf.Config, error) { - path, err := conf.PathByID(pathID) - if err != nil { - return conf, err - } - - if path.Src.ChannelID != "" { - return conf, errors.Errorf("%w: %s", ErrLinkedPath, path.ID) - } - - if path, err = r.call(ctx, conf, path, "link"); err != nil { - return conf, err - } - - return conf, conf.UpdatePath(path) -} - -// StartPaths relays packets for linked paths from config file until ctx is canceled. -func (r Relayer) StartPaths(ctx context.Context, pathIDs ...string) error { - conf, err := relayerconf.Get() - if err != nil { - return err - } - - g, ctx := errgroup.WithContext(ctx) - - var m sync.Mutex // protects relayerconf.Path. - for _, id := range pathIDs { - id := id - g.Go(func() error { - return r.Start(ctx, conf, id, func(path relayerconf.Config) error { - m.Lock() - defer m.Unlock() - return relayerconf.Save(conf) - }) - }) - } - return g.Wait() -} - -// Start relays packets for linked path until ctx is canceled. -func (r Relayer) Start( - ctx context.Context, - conf relayerconf.Config, - pathID string, - postExecute func(path relayerconf.Config) error, -) error { - return ctxticker.DoNow(ctx, relayDuration, func() error { - path, err := conf.PathByID(pathID) - if err != nil { - return err - } - path, err = r.call(ctx, conf, path, "start") - if err != nil { - return err - } - if err := conf.UpdatePath(path); err != nil { - return err - } - if postExecute != nil { - return postExecute(conf) - } - return nil - }) -} - -func (r Relayer) call( - ctx context.Context, - conf relayerconf.Config, - path relayerconf.Path, - action string, -) ( - reply relayerconf.Path, err error, -) { - srcChain, srcKey, err := r.prepare(ctx, conf, path.Src.ChainID) - if err != nil { - return relayerconf.Path{}, err - } - - dstChain, dstKey, err := r.prepare(ctx, conf, path.Dst.ChainID) - if err != nil { - return relayerconf.Path{}, err - } - - args := []interface{}{ - path, - srcChain, - dstChain, - srcKey, - dstKey, - } - return reply, tsrelayer.Call(ctx, action, args, &reply) -} - -func (r Relayer) prepare(ctx context.Context, conf relayerconf.Config, chainID string) ( - chain relayerconf.Chain, privKey string, err error, -) { - chain, err = conf.ChainByID(chainID) - if err != nil { - return relayerconf.Chain{}, "", err - } - - coins, err := r.balance(ctx, chain.RPCAddress, chain.Account, chain.AddressPrefix) - if err != nil { - return relayerconf.Chain{}, "", err - } - - gasPrice, err := sdk.ParseCoinNormalized(chain.GasPrice) - if err != nil { - return relayerconf.Chain{}, "", err - } - - account, err := r.ca.GetByName(chain.Account) - if err != nil { - return relayerconf.Chain{}, "", err - } - - addr, err := account.Address(chain.AddressPrefix) - if err != nil { - return relayerconf.Chain{}, "", err - } - - errMissingBalance := errors.Errorf(`account "%s(%s)" on %q chain does not have enough balances`, - addr, - chain.Account, - chain.ID, - ) - - if len(coins) == 0 { - return relayerconf.Chain{}, "", errMissingBalance - } - - for _, coin := range coins { - if gasPrice.Denom != coin.Denom { - continue - } - - if gasPrice.Amount.Int64()*ibcSetupGas > coin.Amount.Int64() { - return relayerconf.Chain{}, "", errMissingBalance - } - } - - // Get the key in ASCII armored format - passphrase := "" - key, err := r.ca.Export(chain.Account, passphrase) - if err != nil { - return relayerconf.Chain{}, "", err - } - - // Unarmor the key to be able to read it as bytes - priv, algo, err := crypto.UnarmorDecryptPrivKey(key, passphrase) - if err != nil { - return relayerconf.Chain{}, "", err - } - - // Check the algorithm because the TS relayer expects a secp256k1 private key - if algo != algoSecp256k1 { - return relayerconf.Chain{}, "", errors.Errorf("private key algorithm must be secp256k1 instead of %s", algo) - } - - return chain, hex.EncodeToString(priv.Bytes()), nil -} - -func (r Relayer) balance(ctx context.Context, rpcAddress, account, addressPrefix string) (sdk.Coins, error) { - client, err := cosmosclient.New(ctx, cosmosclient.WithNodeAddress(rpcAddress)) - if err != nil { - return nil, err - } - - acc, err := r.ca.GetByName(account) - if err != nil { - return nil, err - } - - addr, err := acc.Address(addressPrefix) - if err != nil { - return nil, err - } - - queryClient := banktypes.NewQueryClient(client.Context()) - res, err := queryClient.AllBalances(ctx, &banktypes.QueryAllBalancesRequest{Address: addr}) - if err != nil { - return nil, err - } - - return res.Balances, nil -} - -// GetPath returns a path by its id. -func (r Relayer) GetPath(_ context.Context, id string) (relayerconf.Path, error) { - conf, err := relayerconf.Get() - if err != nil { - return relayerconf.Path{}, err - } - - return conf.PathByID(id) -} - -// ListPaths list all the paths. -func (r Relayer) ListPaths(_ context.Context) ([]relayerconf.Path, error) { - conf, err := relayerconf.Get() - if err != nil { - return nil, err - } - - return conf.Paths, nil -} - -func fixRPCAddress(rpcAddress string) string { - return strings.TrimSuffix(xurl.HTTPEnsurePort(rpcAddress), "/") -} diff --git a/integration/relayer/cmd_relayer_test.go b/integration/relayer/cmd_relayer_test.go index 4dcbf7d0b0..337f049b48 100644 --- a/integration/relayer/cmd_relayer_test.go +++ b/integration/relayer/cmd_relayer_test.go @@ -16,7 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "github.com/ignite/cli/v28/ignite/config/chain" "github.com/ignite/cli/v28/ignite/config/chain/base" @@ -24,8 +24,9 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/availableport" "github.com/ignite/cli/v28/ignite/pkg/cmdrunner" "github.com/ignite/cli/v28/ignite/pkg/cmdrunner/step" + "github.com/ignite/cli/v28/ignite/pkg/errors" "github.com/ignite/cli/v28/ignite/pkg/goanalysis" - yamlmap "github.com/ignite/cli/v28/ignite/pkg/yaml" + xyaml "github.com/ignite/cli/v28/ignite/pkg/yaml" envtest "github.com/ignite/cli/v28/integration" ) @@ -38,11 +39,6 @@ var ( marsConfig = v1.Config{ Config: base.Config{ Version: 1, - Build: base.Build{ - Proto: base.Proto{ - Path: "proto", - }, - }, Accounts: []base.Account{ { Name: "alice", @@ -50,7 +46,7 @@ var ( Mnemonic: "slide moment original seven milk crawl help text kick fluid boring awkward doll wonder sure fragile plate grid hard next casual expire okay body", }, { - Name: "bob", + Name: bobName, Coins: []string{"100000000000token", "10000000000000000000stake"}, Mnemonic: "trap possible liquid elite embody host segment fantasy swim cable digital eager tiny broom burden diary earn hen grow engine pigeon fringe claim program", }, @@ -65,21 +61,21 @@ var ( Coins: []string{"500token", "100000000stake"}, Host: ":4501", }, - Genesis: yamlmap.Map{"chain_id": "mars-1"}, + Genesis: xyaml.Map{"chain_id": "mars-1"}, }, Validators: []v1.Validator{ { Name: "alice", Bonded: "100000000stake", - Client: yamlmap.Map{"keyring-backend": keyring.BackendTest}, - App: yamlmap.Map{ - "api": yamlmap.Map{"address": ":1318"}, - "grpc": yamlmap.Map{"address": ":9092"}, - "grpc-web": yamlmap.Map{"address": ":9093"}, + Client: xyaml.Map{"keyring-backend": keyring.BackendTest}, + App: xyaml.Map{ + "api": xyaml.Map{"address": ":1318"}, + "grpc": xyaml.Map{"address": ":9092"}, + "grpc-web": xyaml.Map{"address": ":9093"}, }, - Config: yamlmap.Map{ - "p2p": yamlmap.Map{"laddr": ":26658"}, - "rpc": yamlmap.Map{"laddr": ":26658", "pprof_laddr": ":6061"}, + Config: xyaml.Map{ + "p2p": xyaml.Map{"laddr": ":26658"}, + "rpc": xyaml.Map{"laddr": ":26658", "pprof_laddr": ":6061"}, }, Home: "$HOME/.mars", }, @@ -88,11 +84,6 @@ var ( earthConfig = v1.Config{ Config: base.Config{ Version: 1, - Build: base.Build{ - Proto: base.Proto{ - Path: "proto", - }, - }, Accounts: []base.Account{ { Name: "alice", @@ -100,7 +91,7 @@ var ( Mnemonic: "slide moment original seven milk crawl help text kick fluid boring awkward doll wonder sure fragile plate grid hard next casual expire okay body", }, { - Name: "bob", + Name: bobName, Coins: []string{"100000000000token", "10000000000000000000stake"}, Mnemonic: "trap possible liquid elite embody host segment fantasy swim cable digital eager tiny broom burden diary earn hen grow engine pigeon fringe claim program", }, @@ -115,21 +106,21 @@ var ( Coins: []string{"500token", "100000000stake"}, Host: ":4500", }, - Genesis: yamlmap.Map{"chain_id": "earth-1"}, + Genesis: xyaml.Map{"chain_id": "earth-1"}, }, Validators: []v1.Validator{ { Name: "alice", Bonded: "100000000stake", - Client: yamlmap.Map{"keyring-backend": keyring.BackendTest}, - App: yamlmap.Map{ - "api": yamlmap.Map{"address": ":1317"}, - "grpc": yamlmap.Map{"address": ":9090"}, - "grpc-web": yamlmap.Map{"address": ":9091"}, + Client: xyaml.Map{"keyring-backend": keyring.BackendTest}, + App: xyaml.Map{ + "api": xyaml.Map{"address": ":1317"}, + "grpc": xyaml.Map{"address": ":9090"}, + "grpc-web": xyaml.Map{"address": ":9091"}, }, - Config: yamlmap.Map{ - "p2p": yamlmap.Map{"laddr": ":26656"}, - "rpc": yamlmap.Map{"laddr": ":26656", "pprof_laddr": ":6060"}, + Config: xyaml.Map{ + "p2p": xyaml.Map{"laddr": ":26656"}, + "rpc": xyaml.Map{"laddr": ":26656", "pprof_laddr": ":6060"}, }, Home: "$HOME/.earth", }, @@ -258,11 +249,11 @@ func runChain( cfg.Validators[0].Home = homePath cfg.Faucet.Host = genAddr(ports[0]) - cfg.Validators[0].App["api"] = yamlmap.Map{"address": genAddr(ports[1])} - cfg.Validators[0].App["grpc"] = yamlmap.Map{"address": genAddr(ports[2])} - cfg.Validators[0].App["grpc-web"] = yamlmap.Map{"address": genAddr(ports[3])} - cfg.Validators[0].Config["p2p"] = yamlmap.Map{"laddr": genAddr(ports[4])} - cfg.Validators[0].Config["rpc"] = yamlmap.Map{ + cfg.Validators[0].App["api"] = xyaml.Map{"address": genAddr(ports[1])} + cfg.Validators[0].App["grpc"] = xyaml.Map{"address": genAddr(ports[2])} + cfg.Validators[0].App["grpc-web"] = xyaml.Map{"address": genAddr(ports[3])} + cfg.Validators[0].Config["p2p"] = xyaml.Map{"laddr": genAddr(ports[4])} + cfg.Validators[0].Config["rpc"] = xyaml.Map{ "laddr": genAddr(ports[5]), "pprof_laddr": genAddr(ports[6]), } @@ -444,7 +435,7 @@ func TestBlogIBC(t *testing.T) { "install", "-g", // filepath.Join(goenv.GoPath(), "src/github.com/ignite/apps/hermes"), // Local path for test proposals - "github.com/ignite/apps/hermes@hermes/v0.2.1", + "github.com/ignite/apps/hermes@hermes/v0.2.2", ), )), )) @@ -501,14 +492,14 @@ func TestBlogIBC(t *testing.T) { return execErr } if err := json.Unmarshal(queryOutput.Bytes(), &queryResponse); err != nil { - return fmt.Errorf("unmarshling tx response: %w", err) + return errors.Errorf("unmarshling tx response: %w", err) } if len(queryResponse.Channels) == 0 || len(queryResponse.Channels[0].ConnectionHops) == 0 { - return fmt.Errorf("channel not found") + return errors.Errorf("channel not found") } if queryResponse.Channels[0].State != "STATE_OPEN" { - return fmt.Errorf("channel is not open") + return errors.Errorf("channel is not open") } return nil }), @@ -552,7 +543,7 @@ func TestBlogIBC(t *testing.T) { return execErr } if err := json.Unmarshal(txOutput.Bytes(), &txResponse); err != nil { - return fmt.Errorf("unmarshling tx response: %w", err) + return errors.Errorf("unmarshling tx response: %w", err) } return cmdrunner.New().Run(ctx, step.New( step.Exec( @@ -617,13 +608,13 @@ func TestBlogIBC(t *testing.T) { output := balanceOutput.Bytes() defer balanceOutput.Reset() if err := json.Unmarshal(output, &balanceResponse); err != nil { - return fmt.Errorf("unmarshalling query response error: %w, response: %s", err, string(output)) + return errors.Errorf("unmarshalling query response error: %w, response: %s", err, string(output)) } if balanceResponse.Balances.Empty() { - return fmt.Errorf("empty balances") + return errors.Errorf("empty balances") } if !strings.HasPrefix(balanceResponse.Balances[0].Denom, "ibc/") { - return fmt.Errorf("invalid ibc balance: %v", balanceResponse.Balances[0]) + return errors.Errorf("invalid ibc balance: %v", balanceResponse.Balances[0]) } return nil @@ -635,5 +626,5 @@ func TestBlogIBC(t *testing.T) { // TODO test ibc using the blog post methods: // step.Exec(app.Binary(), "tx", "blog", "send-ibc-post", "transfer", "channel-0", "Hello", "Hello_Mars-Alice_from_Earth", "--chain-id", earthChainID, "--from", "alice", "--node", earthGRPC, "--output", "json", "--log_format", "json", "--yes") // TODO test ibc using the hermes ft-transfer: - // step.Exec(envtest.IgniteApp, "relayer", "hermes", "exec", "--", "--config", earthConfig, "tx", "ft-transfer", "--timeout-seconds", "1000", "--dst-chain", earthChainID, "--src-chain", marsChainID, "--src-port", "transfer", "--src-channel", "channel-0", "--amount", "100000", "--denom", "stake", "--output", "json", "--log_format", "json", "--yes") + // step.Exec(envtest.IgniteApp, "hermes", "exec", "--", "--config", earthConfig, "tx", "ft-transfer", "--timeout-seconds", "1000", "--dst-chain", earthChainID, "--src-chain", marsChainID, "--src-port", "transfer", "--src-channel", "channel-0", "--amount", "100000", "--denom", "stake", "--output", "json", "--log_format", "json", "--yes") }