From c84e1e3dd1fa45ff6390ca30a95a798cde634a58 Mon Sep 17 00:00:00 2001 From: akhilkumarpilli Date: Thu, 4 Feb 2021 12:16:59 +0530 Subject: [PATCH 1/6] WIP: Fix config add-dir regression --- cmd/config.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 8f4c7cdec..7b5e42cdd 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -240,10 +240,6 @@ func cfgFilesAdd(dir string) (cfg *Config, err error) { } pthName := strings.Split(f.Name(), ".")[0] - if err = config.ValidatePath(p); err != nil { - fmt.Printf("%s: %s\n", pth, err.Error()) - continue - } if err = cfg.AddPath(pthName, p); err != nil { fmt.Printf("%s: %s\n", pth, err.Error()) continue @@ -263,6 +259,12 @@ func cfgFilesAdd(dir string) (cfg *Config, err error) { } fmt.Printf("added chain %s...\n", c.ChainID) } + for _, p := range cfg.Paths { + if err = config.ValidatePath(p); err != nil { + fmt.Println("Error occured...Config is not updated") + return nil, err + } + } return cfg, nil } From 33d674c7a089643ea9543e6130fcb820513dfe25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 4 Feb 2021 13:14:05 +0100 Subject: [PATCH 2/6] split add-dir into add-chains and add-paths --- cmd/config.go | 129 +++++++++++++++--------- configs/agoric/{ => chains}/ibc-0.json | 0 configs/agoric/{ => chains}/ibc-1.json | 0 configs/agoric/{ => paths}/demo.json | 0 configs/akash/{ => chains}/ibc-0.json | 0 configs/akash/{ => chains}/ibc-1.json | 0 configs/akash/{ => paths}/demo.json | 0 configs/demo/{ => chains}/ibc-0.json | 0 configs/demo/{ => chains}/ibc-1.json | 0 configs/demo/{ => paths}/demo.json | 0 configs/four/{ => chains}/ibc-0.json | 0 configs/four/{ => chains}/ibc-1.json | 0 configs/four/{ => chains}/ibc-2.json | 0 configs/four/{ => chains}/ibc-3.json | 0 configs/four/{ => paths}/onetwo.json | 0 configs/four/{ => paths}/threezero.json | 0 configs/four/{ => paths}/twothree.json | 0 configs/four/{ => paths}/zeroone.json | 0 configs/gaia/{ => chains}/ibc-0.json | 0 configs/gaia/{ => chains}/ibc-1.json | 0 configs/gaia/{ => paths}/demo.json | 0 configs/three/{ => chains}/ibc-0.json | 0 configs/three/{ => chains}/ibc-1.json | 0 configs/three/{ => chains}/ibc-2.json | 0 configs/three/{ => paths}/demo.json | 0 configs/three/{ => paths}/demo2.json | 0 configs/wasmd/{ => chains}/ibc-0.json | 0 configs/wasmd/{ => chains}/ibc-1.json | 0 configs/wasmd/{ => paths}/demo.json | 0 docs/commands.md | 24 ++++- scripts/nchainz | 3 +- scripts/three-chainz | 7 +- scripts/two-chainz | 5 +- scripts/two-chainz-akash | 7 +- scripts/two-chainz-wasmd | 5 +- 35 files changed, 121 insertions(+), 59 deletions(-) rename configs/agoric/{ => chains}/ibc-0.json (100%) rename configs/agoric/{ => chains}/ibc-1.json (100%) rename configs/agoric/{ => paths}/demo.json (100%) rename configs/akash/{ => chains}/ibc-0.json (100%) rename configs/akash/{ => chains}/ibc-1.json (100%) rename configs/akash/{ => paths}/demo.json (100%) rename configs/demo/{ => chains}/ibc-0.json (100%) rename configs/demo/{ => chains}/ibc-1.json (100%) rename configs/demo/{ => paths}/demo.json (100%) rename configs/four/{ => chains}/ibc-0.json (100%) rename configs/four/{ => chains}/ibc-1.json (100%) rename configs/four/{ => chains}/ibc-2.json (100%) rename configs/four/{ => chains}/ibc-3.json (100%) rename configs/four/{ => paths}/onetwo.json (100%) rename configs/four/{ => paths}/threezero.json (100%) rename configs/four/{ => paths}/twothree.json (100%) rename configs/four/{ => paths}/zeroone.json (100%) rename configs/gaia/{ => chains}/ibc-0.json (100%) rename configs/gaia/{ => chains}/ibc-1.json (100%) rename configs/gaia/{ => paths}/demo.json (100%) rename configs/three/{ => chains}/ibc-0.json (100%) rename configs/three/{ => chains}/ibc-1.json (100%) rename configs/three/{ => chains}/ibc-2.json (100%) rename configs/three/{ => paths}/demo.json (100%) rename configs/three/{ => paths}/demo2.json (100%) rename configs/wasmd/{ => chains}/ibc-0.json (100%) rename configs/wasmd/{ => chains}/ibc-1.json (100%) rename configs/wasmd/{ => paths}/demo.json (100%) diff --git a/cmd/config.go b/cmd/config.go index 7b5e42cdd..a36380273 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -51,7 +51,8 @@ func configCmd() *cobra.Command { cmd.AddCommand( configShowCmd(), configInitCmd(), - configAddDirCmd(), + configAddChainsCmd(), + configAddPathsCmd(), ) return cmd @@ -170,19 +171,17 @@ $ %s cfg i`, appName, defaultHome, appName)), return cmd } -func configAddDirCmd() *cobra.Command { +func configAddChainsCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "add-dir [dir]", - Aliases: []string{"ad"}, - Args: cobra.ExactArgs(1), - Short: `Add new chains and paths to the configuration file from a - directory full of chain and path configuration, useful for adding testnet configurations`, + Use: "add-chains [/path/to/chains/]", + Args: cobra.ExactArgs(1), + Short: `Add new chains to the configuration file from a + directory full of chain configurations, useful for adding testnet configurations`, Example: strings.TrimSpace(fmt.Sprintf(` -$ %s config add-dir configs/ -$ %s cfg ad configs/`, appName, appName)), +$ %s config add-chains configs/chains`, appName)), RunE: func(cmd *cobra.Command, args []string) (err error) { var out *Config - if out, err = cfgFilesAdd(args[0]); err != nil { + if out, err = cfgFilesAddChains(args[0]); err != nil { return err } return overWriteConfig(cmd, out) @@ -192,7 +191,27 @@ $ %s cfg ad configs/`, appName, appName)), return cmd } -func cfgFilesAdd(dir string) (cfg *Config, err error) { +func configAddPathsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-paths [/path/to/paths/]", + Args: cobra.ExactArgs(1), + Short: `Add new paths to the configuration file from a directory full of path configurations, useful for adding testnet configurations. + Chain configuration files must be added before calling this command.`, + Example: strings.TrimSpace(fmt.Sprintf(` +$ %s config add-paths configs/paths`, appName)), + RunE: func(cmd *cobra.Command, args []string) (err error) { + var out *Config + if out, err = cfgFilesAddPaths(args[0]); err != nil { + return err + } + return overWriteConfig(cmd, out) + }, + } + + return cmd +} + +func cfgFilesAddChains(dir string) (cfg *Config, err error) { dir = path.Clean(dir) files, err := ioutil.ReadDir(dir) if err != nil { @@ -218,53 +237,69 @@ func cfgFilesAdd(dir string) (cfg *Config, err error) { continue } - if c.ChainID == "" && c.Key == "" && c.RPCAddr == "" { - p := &relayer.Path{} - if err = json.Unmarshal(byt, p); err != nil { - fmt.Printf("failed to unmarshal file %s, skipping...\n", pth) - continue - } + if err = cfg.AddChain(c); err != nil { + fmt.Printf("%s: %s\n", pth, err.Error()) + continue + } + fmt.Printf("added chain %s...\n", c.ChainID) + } + return cfg, nil +} - // In the case that order isn't added to the path, add it manually - if p.Src.Order == "" || p.Dst.Order == "" { - p.Src.Order = defaultOrder - p.Dst.Order = defaultOrder - } +func cfgFilesAddPaths(dir string) (cfg *Config, err error) { + dir = path.Clean(dir) + files, err := ioutil.ReadDir(dir) + if err != nil { + return nil, err + } + cfg = config + for _, f := range files { + pth := fmt.Sprintf("%s/%s", dir, f.Name()) + if f.IsDir() { + fmt.Printf("directory at %s, skipping...\n", pth) + continue + } - // If the version isn't added to the path, add it manually - if p.Src.Version == "" { - p.Src.Version = defaultVersion - } - if p.Dst.Version == "" { - p.Dst.Version = defaultVersion - } + byt, err := ioutil.ReadFile(pth) + if err != nil { + fmt.Printf("failed to read file %s, skipping...\n", pth) + continue + } - pthName := strings.Split(f.Name(), ".")[0] - if err = cfg.AddPath(pthName, p); err != nil { - fmt.Printf("%s: %s\n", pth, err.Error()) - continue - } + p := &relayer.Path{} + if err = json.Unmarshal(byt, p); err != nil { + fmt.Printf("failed to unmarshal file %s, skipping...\n", pth) + continue + } - // For now, we assume that all chain files must have same filename as chain-id - // this is to ensure non-chain files (global config) does not get parsed into chain struct. - if c.ChainID != pthName { - fmt.Printf("Skipping non chain file: %s\n", f.Name()) - continue - } + // In the case that order isn't added to the path, add it manually + if p.Src.Order == "" || p.Dst.Order == "" { + p.Src.Order = defaultOrder + p.Dst.Order = defaultOrder } - if err = cfg.AddChain(c); err != nil { + // If the version isn't added to the path, add it manually + if p.Src.Version == "" { + p.Src.Version = defaultVersion + } + if p.Dst.Version == "" { + p.Dst.Version = defaultVersion + } + + pthName := strings.Split(f.Name(), ".")[0] + if err = config.ValidatePath(p); err != nil { fmt.Printf("%s: %s\n", pth, err.Error()) continue } - fmt.Printf("added chain %s...\n", c.ChainID) - } - for _, p := range cfg.Paths { - if err = config.ValidatePath(p); err != nil { - fmt.Println("Error occured...Config is not updated") - return nil, err + + if err = cfg.AddPath(pthName, p); err != nil { + fmt.Printf("%s: %s\n", pth, err.Error()) + continue } + + fmt.Printf("added path %s...\n", pthName) } + return cfg, nil } diff --git a/configs/agoric/ibc-0.json b/configs/agoric/chains/ibc-0.json similarity index 100% rename from configs/agoric/ibc-0.json rename to configs/agoric/chains/ibc-0.json diff --git a/configs/agoric/ibc-1.json b/configs/agoric/chains/ibc-1.json similarity index 100% rename from configs/agoric/ibc-1.json rename to configs/agoric/chains/ibc-1.json diff --git a/configs/agoric/demo.json b/configs/agoric/paths/demo.json similarity index 100% rename from configs/agoric/demo.json rename to configs/agoric/paths/demo.json diff --git a/configs/akash/ibc-0.json b/configs/akash/chains/ibc-0.json similarity index 100% rename from configs/akash/ibc-0.json rename to configs/akash/chains/ibc-0.json diff --git a/configs/akash/ibc-1.json b/configs/akash/chains/ibc-1.json similarity index 100% rename from configs/akash/ibc-1.json rename to configs/akash/chains/ibc-1.json diff --git a/configs/akash/demo.json b/configs/akash/paths/demo.json similarity index 100% rename from configs/akash/demo.json rename to configs/akash/paths/demo.json diff --git a/configs/demo/ibc-0.json b/configs/demo/chains/ibc-0.json similarity index 100% rename from configs/demo/ibc-0.json rename to configs/demo/chains/ibc-0.json diff --git a/configs/demo/ibc-1.json b/configs/demo/chains/ibc-1.json similarity index 100% rename from configs/demo/ibc-1.json rename to configs/demo/chains/ibc-1.json diff --git a/configs/demo/demo.json b/configs/demo/paths/demo.json similarity index 100% rename from configs/demo/demo.json rename to configs/demo/paths/demo.json diff --git a/configs/four/ibc-0.json b/configs/four/chains/ibc-0.json similarity index 100% rename from configs/four/ibc-0.json rename to configs/four/chains/ibc-0.json diff --git a/configs/four/ibc-1.json b/configs/four/chains/ibc-1.json similarity index 100% rename from configs/four/ibc-1.json rename to configs/four/chains/ibc-1.json diff --git a/configs/four/ibc-2.json b/configs/four/chains/ibc-2.json similarity index 100% rename from configs/four/ibc-2.json rename to configs/four/chains/ibc-2.json diff --git a/configs/four/ibc-3.json b/configs/four/chains/ibc-3.json similarity index 100% rename from configs/four/ibc-3.json rename to configs/four/chains/ibc-3.json diff --git a/configs/four/onetwo.json b/configs/four/paths/onetwo.json similarity index 100% rename from configs/four/onetwo.json rename to configs/four/paths/onetwo.json diff --git a/configs/four/threezero.json b/configs/four/paths/threezero.json similarity index 100% rename from configs/four/threezero.json rename to configs/four/paths/threezero.json diff --git a/configs/four/twothree.json b/configs/four/paths/twothree.json similarity index 100% rename from configs/four/twothree.json rename to configs/four/paths/twothree.json diff --git a/configs/four/zeroone.json b/configs/four/paths/zeroone.json similarity index 100% rename from configs/four/zeroone.json rename to configs/four/paths/zeroone.json diff --git a/configs/gaia/ibc-0.json b/configs/gaia/chains/ibc-0.json similarity index 100% rename from configs/gaia/ibc-0.json rename to configs/gaia/chains/ibc-0.json diff --git a/configs/gaia/ibc-1.json b/configs/gaia/chains/ibc-1.json similarity index 100% rename from configs/gaia/ibc-1.json rename to configs/gaia/chains/ibc-1.json diff --git a/configs/gaia/demo.json b/configs/gaia/paths/demo.json similarity index 100% rename from configs/gaia/demo.json rename to configs/gaia/paths/demo.json diff --git a/configs/three/ibc-0.json b/configs/three/chains/ibc-0.json similarity index 100% rename from configs/three/ibc-0.json rename to configs/three/chains/ibc-0.json diff --git a/configs/three/ibc-1.json b/configs/three/chains/ibc-1.json similarity index 100% rename from configs/three/ibc-1.json rename to configs/three/chains/ibc-1.json diff --git a/configs/three/ibc-2.json b/configs/three/chains/ibc-2.json similarity index 100% rename from configs/three/ibc-2.json rename to configs/three/chains/ibc-2.json diff --git a/configs/three/demo.json b/configs/three/paths/demo.json similarity index 100% rename from configs/three/demo.json rename to configs/three/paths/demo.json diff --git a/configs/three/demo2.json b/configs/three/paths/demo2.json similarity index 100% rename from configs/three/demo2.json rename to configs/three/paths/demo2.json diff --git a/configs/wasmd/ibc-0.json b/configs/wasmd/chains/ibc-0.json similarity index 100% rename from configs/wasmd/ibc-0.json rename to configs/wasmd/chains/ibc-0.json diff --git a/configs/wasmd/ibc-1.json b/configs/wasmd/chains/ibc-1.json similarity index 100% rename from configs/wasmd/ibc-1.json rename to configs/wasmd/chains/ibc-1.json diff --git a/configs/wasmd/demo.json b/configs/wasmd/paths/demo.json similarity index 100% rename from configs/wasmd/demo.json rename to configs/wasmd/paths/demo.json diff --git a/docs/commands.md b/docs/commands.md index b08c23d17..075ce07da 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -37,7 +37,8 @@ NOTE: Most of the commands have aliases that make typing them much quicker (i.e. - [rly chains list](#rly-chains-list) - [rly chains show](#rly-chains-show) - [rly config](#rly-config) - - [rly config add-dir](#rly-config-add-dir) + - [rly config add-chains](#rly-config-add-chains) + - [rly config add-paths](#rly-config-add-paths) - [rly config init](#rly-config-init) - [rly config show](#rly-config-show) - [rly development](#rly-development) @@ -253,17 +254,30 @@ Manage configuration file ### Subcommands -* [rly config add-dir](#rly-config-add-dir) - Add new chains and paths to the configuration file from a directory full of chain and path configuration, useful for adding testnet configurations +* [rly config add-chains](#rly-config-add-chains) - Add new chains to the configuration file from a directory full of chain configurations, useful for adding testnet configurations +* [rly config add-paths](#rly-config-add-paths) - Add new paths to the configuration file from a directory full of path configurations, useful for adding testnet configurations. Must be called after adding chains and keys. * [rly config init](#rly-config-init) - Creates a default home directory at path defined by --home * [rly config show](#rly-config-show) - Prints current configuration -## rly config add-dir +## rly config add-chains -Add new chains and paths to the configuration file from a directory full of chain and path configuration, useful for adding testnet configurations +Add new chains to the configuration file from a directory full of chain configurations, useful for adding testnet configurations ### Synopsis -Add new chains and paths to the configuration file from a directory full of chain and path configuration, useful for adding testnet configurations +Add new chains to the configuration file from a directory full of chain configurations, useful for adding testnet configurations + +``` +rly config add-chains [dir] [flags] +``` + +## rly config add-paths + +Add new paths to the configuration file from a directory full of path configurations, useful for adding testnet configurations. Must be called after adding chains and keys. + +### Synopsis + +Add new paths to the configuration file from a directory full of path configurations, useful for adding testnet configurations. Must be called after adding chains and keys. ``` rly config add-dir [dir] [flags] diff --git a/scripts/nchainz b/scripts/nchainz index 81c3e0472..6335142b1 100755 --- a/scripts/nchainz +++ b/scripts/nchainz @@ -446,7 +446,7 @@ clients) echo "Generating rly configurations..." rly config init - rly config add-dir "$BASEDIR/config/" + rly config add-chains "$BASEDIR/config/chains" sleep 2 @@ -467,6 +467,7 @@ clients) done SEED=$(jq -r '.secret' "$f") echo "Key $(rly keys restore $chainid testkey "$SEED") imported from $chainid to relayer..." + rly config add-paths "$BASEDIR/config/paths" try=0 f="$DATA/$chainid/n0/$DAEMON/config/genesis.json" diff --git a/scripts/three-chainz b/scripts/three-chainz index 566bb518f..6908ce6a1 100755 --- a/scripts/three-chainz +++ b/scripts/three-chainz @@ -63,7 +63,7 @@ make install echo "Generating rly configurations..." rly config init -rly config add-dir configs/three/ +rly config add-chains configs/three/chains SEED0=$(jq -r '.mnemonic' $GAIA_DATA/ibc-0/key_seed.json) SEED1=$(jq -r '.mnemonic' $GAIA_DATA/ibc-1/key_seed.json) @@ -71,8 +71,11 @@ SEED2=$(jq -r '.mnemonic' $GAIA_DATA/ibc-2/key_seed.json) echo "Key $(rly keys restore ibc-0 testkey "$SEED0") imported from ibc-0 to relayer..." echo "Key $(rly keys restore ibc-1 testkey "$SEED1") imported from ibc-1 to relayer..." echo "Key $(rly keys restore ibc-2 testkey "$SEED2") imported from ibc-2 to relayer..." + +rly config add-paths configs/three/paths + echo "Creating light clients..." sleep 3 rly light init ibc-0 -f rly light init ibc-1 -f -rly light init ibc-2 -f \ No newline at end of file +rly light init ibc-2 -f diff --git a/scripts/two-chainz b/scripts/two-chainz index d96ed7a35..4b1575476 100755 --- a/scripts/two-chainz +++ b/scripts/two-chainz @@ -60,12 +60,15 @@ make install echo "Generating rly configurations..." rly config init -rly config add-dir configs/demo/ +rly config add-chains configs/demo/chains SEED0=$(jq -r '.mnemonic' $GAIA_DATA/ibc-0/key_seed.json) SEED1=$(jq -r '.mnemonic' $GAIA_DATA/ibc-1/key_seed.json) echo "Key $(rly keys restore ibc-0 testkey "$SEED0") imported from ibc-0 to relayer..." echo "Key $(rly keys restore ibc-1 testkey "$SEED1") imported from ibc-1 to relayer..." + +rly config add-paths configs/demo/paths + echo "Creating light clients..." sleep 3 rly light init ibc-0 -f diff --git a/scripts/two-chainz-akash b/scripts/two-chainz-akash index f31bdd9a5..ecf01b7bb 100755 --- a/scripts/two-chainz-akash +++ b/scripts/two-chainz-akash @@ -69,13 +69,16 @@ make install echo "Generating rly configurations..." rly config init -rly config add-dir configs/akash/ +rly config add-chains configs/akash/chains SEED0=$(jq -r '.mnemonic' $GAIA_DATA/ibc-0/key_seed.json) SEED1=$(jq -r '.mnemonic' $GAIA_DATA/ibc-1/key_seed.json) echo "Key $(rly keys restore ibc-0 testkey "$SEED0") imported from ibc-0 to relayer..." echo "Key $(rly keys restore ibc-1 testkey "$SEED1") imported from ibc-1 to relayer..." + +rly config add-paths configs/akash/paths + echo "Creating light clients..." sleep 3 rly light init ibc-0 -f -rly light init ibc-1 -f \ No newline at end of file +rly light init ibc-1 -f diff --git a/scripts/two-chainz-wasmd b/scripts/two-chainz-wasmd index 2c2ca7233..1b566d0c3 100755 --- a/scripts/two-chainz-wasmd +++ b/scripts/two-chainz-wasmd @@ -59,12 +59,15 @@ make install echo "Generating rly configurations..." rly config init -rly config add-dir configs/wasmd/ +rly config add-chains configs/wasmd/chains SEED0=$(jq -r '.mnemonic' $WASMD_DATA/ibc-0/key_seed.json) SEED1=$(jq -r '.mnemonic' $WASMD_DATA/ibc-1/key_seed.json) echo "Key $(rly keys restore ibc-0 testkey "$SEED0") imported from ibc-0 to relayer..." echo "Key $(rly keys restore ibc-1 testkey "$SEED1") imported from ibc-1 to relayer..." + +rly config add-paths configs/wasmd/paths + echo "Creating light clients..." sleep 3 rly light init ibc-0 -f From ece2a00735ef717318746ce9e9b6d589b7596711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 4 Feb 2021 13:43:48 +0100 Subject: [PATCH 3/6] nicer error messages --- cmd/config.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index a36380273..decd28ab0 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -26,6 +26,7 @@ import ( "time" "github.com/cosmos/cosmos-sdk/client/flags" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/relayer/relayer" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -288,7 +289,7 @@ func cfgFilesAddPaths(dir string) (cfg *Config, err error) { pthName := strings.Split(f.Name(), ".")[0] if err = config.ValidatePath(p); err != nil { - fmt.Printf("%s: %s\n", pth, err.Error()) + fmt.Printf("%s: failed to validate path: %s\n", pth, err.Error()) continue } @@ -485,10 +486,10 @@ func (c *Config) ValidatePath(p *relayer.Path) (err error) { return fmt.Errorf("source must specify a version") } if err = c.ValidatePathEnd(p.Src); err != nil { - return err + return sdkerrors.Wrapf(err, "chain %s failed path validation", p.Src.ChainID) } if err = c.ValidatePathEnd(p.Dst); err != nil { - return err + return sdkerrors.Wrapf(err, "chain %s failed path validation", p.Dst.ChainID) } if _, err = p.GetStrategy(); err != nil { return err From 074e1b83f3ca22dbf5bdda40cf99e7cd87c5fe79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 4 Feb 2021 13:47:16 +0100 Subject: [PATCH 4/6] fix lint --- cmd/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/config.go b/cmd/config.go index decd28ab0..f16becd36 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -196,6 +196,7 @@ func configAddPathsCmd() *cobra.Command { cmd := &cobra.Command{ Use: "add-paths [/path/to/paths/]", Args: cobra.ExactArgs(1), + //nolint:lll Short: `Add new paths to the configuration file from a directory full of path configurations, useful for adding testnet configurations. Chain configuration files must be added before calling this command.`, Example: strings.TrimSpace(fmt.Sprintf(` From a53a0ab767ac4d742a3783666aa8ae92375e66b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 4 Feb 2021 13:58:53 +0100 Subject: [PATCH 5/6] apply @fedekunze suggestions --- cmd/config.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index f16becd36..bd4e307f1 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -230,18 +230,15 @@ func cfgFilesAddChains(dir string) (cfg *Config, err error) { byt, err := ioutil.ReadFile(pth) if err != nil { - fmt.Printf("failed to read file %s, skipping...\n", pth) - continue + return nil, fmt.Errorf("failed to read file %s: %w\n", pth, err) } if err = json.Unmarshal(byt, c); err != nil { - fmt.Printf("failed to unmarshal file %s, skipping...\n", pth) - continue + return nil, fmt.Errorf("failed to unmarshal file %s: %w\n", pth, err) } if err = cfg.AddChain(c); err != nil { - fmt.Printf("%s: %s\n", pth, err.Error()) - continue + return nil, fmt.Errorf("failed to add chain%s: %w\n", pth, err) } fmt.Printf("added chain %s...\n", c.ChainID) } @@ -264,14 +261,12 @@ func cfgFilesAddPaths(dir string) (cfg *Config, err error) { byt, err := ioutil.ReadFile(pth) if err != nil { - fmt.Printf("failed to read file %s, skipping...\n", pth) - continue + return nil, fmt.Errorf("failed to read file %s: %w\n", pth, err) } p := &relayer.Path{} if err = json.Unmarshal(byt, p); err != nil { - fmt.Printf("failed to unmarshal file %s, skipping...\n", pth) - continue + return nil, fmt.Errorf("failed to unmarshal file %s: %w\n", pth, err) } // In the case that order isn't added to the path, add it manually @@ -290,13 +285,11 @@ func cfgFilesAddPaths(dir string) (cfg *Config, err error) { pthName := strings.Split(f.Name(), ".")[0] if err = config.ValidatePath(p); err != nil { - fmt.Printf("%s: failed to validate path: %s\n", pth, err.Error()) - continue + return nil, fmt.Errorf("failed to validate path %s: %w\n", pth, err) } if err = cfg.AddPath(pthName, p); err != nil { - fmt.Printf("%s: %s\n", pth, err.Error()) - continue + return nil, fmt.Errorf("failed to add path %s: %w\n", pth, err) } fmt.Printf("added path %s...\n", pthName) @@ -508,6 +501,11 @@ func (c *Config) ValidatePathEnd(pe *relayer.PathEnd) error { return err } + // if the identifiers are empty, don't do any validation + if pe.ClientID == "" && pe.ConnectionID == "" && pe.ChannelID == "" { + return nil + } + chain, err := c.Chains.Get(pe.ChainID) if err != nil { return err From c9d0dcedefc363d94a2067694e3595d9f86bf103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 4 Feb 2021 14:02:09 +0100 Subject: [PATCH 6/6] remove newline from error --- cmd/config.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index bd4e307f1..083532d41 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -230,15 +230,15 @@ func cfgFilesAddChains(dir string) (cfg *Config, err error) { byt, err := ioutil.ReadFile(pth) if err != nil { - return nil, fmt.Errorf("failed to read file %s: %w\n", pth, err) + return nil, fmt.Errorf("failed to read file %s: %w", pth, err) } if err = json.Unmarshal(byt, c); err != nil { - return nil, fmt.Errorf("failed to unmarshal file %s: %w\n", pth, err) + return nil, fmt.Errorf("failed to unmarshal file %s: %w", pth, err) } if err = cfg.AddChain(c); err != nil { - return nil, fmt.Errorf("failed to add chain%s: %w\n", pth, err) + return nil, fmt.Errorf("failed to add chain%s: %w", pth, err) } fmt.Printf("added chain %s...\n", c.ChainID) } @@ -261,12 +261,12 @@ func cfgFilesAddPaths(dir string) (cfg *Config, err error) { byt, err := ioutil.ReadFile(pth) if err != nil { - return nil, fmt.Errorf("failed to read file %s: %w\n", pth, err) + return nil, fmt.Errorf("failed to read file %s: %w", pth, err) } p := &relayer.Path{} if err = json.Unmarshal(byt, p); err != nil { - return nil, fmt.Errorf("failed to unmarshal file %s: %w\n", pth, err) + return nil, fmt.Errorf("failed to unmarshal file %s: %w", pth, err) } // In the case that order isn't added to the path, add it manually @@ -285,11 +285,11 @@ func cfgFilesAddPaths(dir string) (cfg *Config, err error) { pthName := strings.Split(f.Name(), ".")[0] if err = config.ValidatePath(p); err != nil { - return nil, fmt.Errorf("failed to validate path %s: %w\n", pth, err) + return nil, fmt.Errorf("failed to validate path %s: %w", pth, err) } if err = cfg.AddPath(pthName, p); err != nil { - return nil, fmt.Errorf("failed to add path %s: %w\n", pth, err) + return nil, fmt.Errorf("failed to add path %s: %w", pth, err) } fmt.Printf("added path %s...\n", pthName)