Skip to content

Commit

Permalink
Merge PR cosmos#557: Pull chain data from Chain Registry, Add paths n…
Browse files Browse the repository at this point in the history
…ew cmd, & Improve CLI experience/quick-start guide

* use chain registry + formatting fixes

* remove fetch commands and add chain and path fetching behind chains and paths cmd trees

* actually fetch a chains assetlist.json file from chain registry

* fix quick-start guide

* small fixes to README.md

* more small fixes to README.md

* fix tabs in README.md

* fix tabs in README.md

* undo last changes

* minor changes to readme

* added ds_store

* Merge PR cosmos#564: Add command for creating a new blank path

* add command to create a new blank path in the config

* add retries & cleanup CreateClients

* use tagged lens version

Co-authored-by: Dan Kanefsky <[email protected]>
Co-authored-by: Jack Zampolin <[email protected]>
  • Loading branch information
3 people authored Feb 4, 2022
1 parent 54f5f9c commit b11c34f
Show file tree
Hide file tree
Showing 19 changed files with 566 additions and 450 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ two-chains/ibc-*
two-chains/.relayer
two-chains/*.log
test/setup/valkeys/*.json
test/keys/
test/keys/
.DS_Store
86 changes: 55 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,58 @@ To quickly setup the IBC relayer on a canonical path (i.e. path being actively u

```
$ git clone [email protected]:cosmos/relayer.git
$ git checkout v1.0.0
$ git checkout v2.0.0
$ cd relayer && make install
```

2. Initialize the relayer's configuration.
2. Initialize the relayer's configuration directory/file

```shell
$ rly config init
```

3. Ensure the chains you want to configure have the pertinent config files [here](https://github.com/cosmos/relayer/tree/main/interchain/chains). Don't see the chain you want to relay on? Please open a PR to add this metadata to the GitHub repo!
3. Ensure the chains you want to configure have the pertinent config files [here](https://github.com/cosmos/chain-registry).

> **NOTE:** Don't see the chain you want to relay on?
> Please open a PR to add this metadata to the GitHub repo!
4. In our example we will configure the relayer to operate between the Cosmos Hub & Osmosis. The fetch cmd will retrieve the relevant chain configurations from [GitHub](https://github.com/cosmos/relayer/tree/main/interchain/chains) & add them to the relayers config file.
4. In our example we will configure the relayer to operate between the Cosmos Hub & Osmosis.
The `chains add` cmd will retrieve the relevant chain configurations from [chain-registry](https://github.com/cosmos/chain-registry) & add them to the relayers config file.
```shell
$ rly fetch chain cosmoshub-4
$ rly fetch chain osmosis-1
$ rly chains add cosmoshub osmosis
```
5. The relayer connects to a node on the respective networks, via the configured RPC endpoints for each chain. Ensure the `rpc-addr` field for both chains in `config.yaml` points to a valid RPC endpoint.
> **NOTE:** Strangelove maintains archive nodes for a number of networks and provides them for public usage. Chains that we maintain endpoints for are preconfigured.
> **NOTE:** Strangelove maintains archive nodes for a number of networks and provides them for public usage. Chains that we maintain endpoints for are preconfigured.
6. Either import or create new keys for the relayer to use when signing and relaying transactions.
> **NOTE:** `key-name` is an identifier of your choosing.
6. Either import or create new keys for the relayer to use when signing and
relaying transactions.
`key-name` is an identifier of your choosing.
**Create**(add):
```shell
$ rly keys add cosmoshub-4 [key-name]
$ rly keys add osmosis-1 [key-name]
```
OR
7. Edit the relayer's config file to assign the chain-specific keys created or imported above to the
specific chain's configuration. Default file location is `~/.relayer/config/config.yaml`
`key-name` is the same as Step 7.
**Import**(restore):
```shell
$ rly keys restore cosmoshub-4 [key-name] "mnemonic words here"
$ rly keys restore osmosis-1 [key-name] "mnemonic words here"
```
7. Edit the relayer's "key:" values in the config file to match the `key-name`'s chosen above. This step is necessary if you chose a `key-name` other than "default"
> **NOTE:** Default file location is `~/.relayer/config/config.yaml`.
8. Both relayer accounts, i.e. the two keys we just added or imported, need to be
funded with tokens on the appropriate network in order to successfully relay transactions
between the IBC-connected networks. How this occurs depends on the network,
context and environment, e.g. local or test networks can use a faucet.
between the IBC-connected networks.
How this occurs depends on the network, context and environment, e.g. local or test networks can use a faucet.
9. Ensure both relayer accounts are funded by querying each.
Expand All @@ -88,14 +100,18 @@ To quickly setup the IBC relayer on a canonical path (i.e. path being actively u
$ rly q balance osmosis-1
```
10. Fetch and configure the relevant path configuration files for the two chains.
10. Fetch and configure the relevant path configuration files for the two chains.
`paths fetch` will check for the relevant `path.json` files for all configured chains in the [interchain](https://github.com/cosmos/relayer/tree/main/interchain) directory
> **NOTE:** Don't see the path metadata for paths you want to relay on?
> Please open a PR to add this metadata to the GitHub repo!

```shell
$ rly fetch paths
$ rly paths fetch
```

11. Finally, we start the relayer on the path. The relayer will periodically update
the clients and listen for IBC messages to relay.
11. Finally, we start the relayer on the path.
The relayer will periodically update the clients and listen for IBC messages to relay.

```shell
$ rly paths list
Expand All @@ -111,7 +127,7 @@ steps are typically performed:

```
$ git clone [email protected]:cosmos/relayer.git
$ git checkout v1.0.0-rc2
$ git checkout v2.0.0
$ cd relayer && make install
```

Expand All @@ -121,26 +137,34 @@ steps are typically performed:
$ rly config init
```
3. Add relevant chain configurations to the relayer's configuration. See the
[Chain](https://pkg.go.dev/github.com/cosmos/relayer/relayer#Chain) type for
more information.
3. Add relevant chain configurations to the relayer's configuration.
See the [Chain](https://pkg.go.dev/github.com/strangelove-ventures/relayer/relayer#Chain) type for more information.

e.g. chain configuration:

```shell
# chain_a_config.json
# cosmoshub-4.json
{
"chain-id": "chain-a",
"rpc-addr": "http://127.0.0.1:26657",
"account-prefix": "cosmos",
"gas-adjustment": 1.5,
"gas-prices": "0.001umuon",
"trusting-period": "10m"
"type": "cosmos",
"value": {
"key": "test-key",
"chain-id": "cosmoshub-4",
"rpc-addr": "https://cosmoshub-4.technofractal.com:443",
"grpc-addr": "https://gprc.cosmoshub-4.technofractal.com:443",
"account-prefix": "cosmos",
"keyring-backend": "test",
"gas-adjustment": 1.3,
"gas-prices": "0.025uatom",
"debug": true,
"timeout": "10s",
"output-format": "json",
"sign-mode": "direct"
}
}
```

```shell
$ rly chains add -f chain_a_config.json
$ rly chains add -f cosmoshub-4.json
$ rly chains add -f chain_b_config.json
```

Expand Down
131 changes: 120 additions & 11 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
Expand All @@ -14,6 +15,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/cosmos/relayer/relayer"
registry "github.com/strangelove-ventures/lens/client/chain_registry"
)

const (
Expand All @@ -25,11 +27,12 @@ func chainsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "chains",
Aliases: []string{"ch"},
Short: "manage chain configurations",
Short: "Manage chain configurations",
}

cmd.AddCommand(
chainsListCmd(),
chainsRegistryList(),
chainsDeleteCmd(),
chainsAddCmd(),
chainsShowCmd(),
Expand Down Expand Up @@ -132,6 +135,56 @@ $ %s ch d ibc-0`, appName, appName)),
return cmd
}

func chainsRegistryList() *cobra.Command {
cmd := &cobra.Command{
Use: "registry-list",
Args: cobra.NoArgs,
Aliases: []string{"rl"},
Short: "List chains available for configuration from the registry",
RunE: func(cmd *cobra.Command, args []string) error {
jsn, err := cmd.Flags().GetBool(flagJSON)
if err != nil {
return err
}

yml, err := cmd.Flags().GetBool(flagYAML)
if err != nil {
return err
}

chains, err := registry.DefaultChainRegistry().ListChains()
if err != nil {
return err
}

switch {
case yml && jsn:
return fmt.Errorf("can't pass both --json and --yaml, must pick one")
case yml:
out, err := yaml.Marshal(chains)
if err != nil {
return err
}
fmt.Println(string(out))
return nil
case jsn:
out, err := json.Marshal(chains)
if err != nil {
return err
}
fmt.Println(string(out))
return nil
default:
for _, chain := range chains {
fmt.Println(chain)
}
}
return nil
},
}
return yamlFlag(jsonFlag(cmd))
}

func chainsListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Expand Down Expand Up @@ -201,16 +254,15 @@ $ %s ch l`, appName, appName)),

func chainsAddCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add",
Use: "add [[chain-name]]",
Aliases: []string{"a"},
Short: "Add a new chain to the configuration file by passing a file (-f) or url (-u), or user input",
Args: cobra.RangeArgs(0, 1),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s chains add
$ %s ch a [filename]
$ %s chains add --file chains/ibc0.json
$ %s chains add --url https://relayer.com/ibc0.json
`, appName, appName, appName, appName)),
Short: "Add a new chain to the configuration file by fetching chain metadata from \n" +
" the chain-registry or passing a file (-f) or url (-u)",
Args: cobra.MinimumNArgs(0),
Example: fmt.Sprintf(` $ %s chains add cosmoshub
$ %s chains add cosmoshub osmosis
$ %s chains add --file chains/ibc0.json
$ %s chains add --url https://relayer.com/ibc0.json`, appName, appName, appName, appName),
RunE: func(cmd *cobra.Command, args []string) error {
var out *Config

Expand All @@ -219,6 +271,8 @@ func chainsAddCmd() *cobra.Command {
return err
}

// default behavior fetch from chain registry
// still allow for adding config from url or file
switch {
case file != "":
if out, err = fileInputAdd(file); err != nil {
Expand All @@ -229,7 +283,7 @@ func chainsAddCmd() *cobra.Command {
return err
}
default:
if out, err = fileInputAdd(args[0]); err != nil {
if out, err = chainRegistryAdd(args); err != nil {
return err
}
}
Expand Down Expand Up @@ -332,3 +386,58 @@ func urlInputAdd(rawurl string) (cfg *Config, err error) {
}
return config, err
}

func chainRegistryAdd(chains []string) (*Config, error) {
chainRegistry := registry.DefaultChainRegistry()
allChains, err := chainRegistry.ListChains()
if err != nil {
return nil, err
}

for _, chain := range chains {
found := false
for _, possibleChain := range allChains {
if chain == possibleChain {
found = true
}

if !found {
log.Printf("unable to find chain %s in %s", chain, chainRegistry.SourceLink())
continue
}

chainInfo, err := chainRegistry.GetChain(chain)
if err != nil {
log.Printf("error getting chain: %s", err)
continue
}

chainConfig, err := chainInfo.GetChainConfig()
if err != nil {
log.Printf("error generating chain config: %s", err)
continue
}

// build the ChainProvider
prov, err := chainConfig.NewProvider(homePath, debug)
if err != nil {
log.Printf("failed to build ChainProvider for %s. Err: %v", chainConfig.ChainID, err)
continue
}

// build the chain
c := &relayer.Chain{ChainProvider: prov}

// add to config
if err = config.AddChain(c); err != nil {
log.Printf("failed to add chaiin %s to config. Err: %v", chain, err)
return nil, err
}

// found the correct chain so move on to next chain in chains
break
}
}

return config, err
}
Loading

0 comments on commit b11c34f

Please sign in to comment.