From 7c773fbce87593d5d4c80052ee2a4cd14c60c4dc Mon Sep 17 00:00:00 2001 From: Reece Williams <31943163+Reecepbcups@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:43:50 -0500 Subject: [PATCH] Ability to fetch specific chain paths only (#1291) * feat: allow a relayer to fetch a specific chain only * minor: check specific path pair logic earlier --- cmd/paths.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/paths.go b/cmd/paths.go index 640414fa5..f43cd42f4 100644 --- a/cmd/paths.go +++ b/cmd/paths.go @@ -364,14 +364,25 @@ func pathsFetchCmd(a *appState) *cobra.Command { cmd := &cobra.Command{ Use: "fetch", Aliases: []string{"fch"}, - Short: "Fetches the json files necessary to setup the paths for the configured chains", - Args: withUsage(cobra.NoArgs), + Short: "Fetches the json files necessary to setup the paths for the configured chains. Passing a chain name will only fetch paths for that chain", + Args: withUsage(cobra.RangeArgs(0, 1)), Example: strings.TrimSpace(fmt.Sprintf(` $ %s paths fetch --home %s -$ %s pth fch`, appName, defaultHome, appName)), +$ %s pth fch +$ %s pth fch cosmoshub`, appName, defaultHome, appName, appName)), RunE: func(cmd *cobra.Command, args []string) error { overwrite, _ := cmd.Flags().GetBool(flagOverwriteConfig) + // allow the relayer to only pull paths for a specific chain + chainReq := "" + if len(args) > 0 { + chainReq = args[0] + _, exist := a.config.Chains[chainReq] + if !exist { + return fmt.Errorf("chain %s not found in config", chainReq) + } + } + return a.performConfigLockingOperation(cmd.Context(), func() error { chains := []string{} for chainName := range a.config.Chains { @@ -390,6 +401,11 @@ $ %s pth fch`, appName, defaultHome, appName)), if chainB < chainA { pair = chainB + "-" + chainA } + + if chainReq != "" && !strings.Contains(pair, chainReq) { + continue + } + chainCombinations[pair] = true } }