Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make golang relayer optional #95

Merged
merged 6 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#91](https://github.com/crypto-com/pystarport/pull/91) replace block with sync broadcast mode
- [#93](https://github.com/crypto-com/pystarport/pull/93) add default gas prices for golang relayer
- [#94](https://github.com/crypto-com/pystarport/pull/94) allow custom broadcast mode when create node
- [#95](https://github.com/crypto-com/pystarport/pull/95) make golang relayer optional

*Feb 7, 2023*

Expand Down
148 changes: 80 additions & 68 deletions pystarport/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
import threading
import time
from enum import IntEnum
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -987,6 +988,10 @@ def relayer_chain_config_rly(data_dir, chain, relayer_chains_config):
}


class Relayer(IntEnum):
(HERMES, RLY) = range(2)


def init_cluster(
data_dir,
config_path,
Expand All @@ -995,6 +1000,7 @@ def init_cluster(
image=IMAGE,
cmd=None,
gen_compose_file=False,
relayer=Relayer.HERMES,
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
):
extension = Path(config_path).suffix
if extension == ".jsonnet":
Expand All @@ -1020,83 +1026,89 @@ def init_cluster(
)
if len(chains) > 1:
cfg = relayer_config.pop("chains", {})
# write relayer config for hermes
relayer_config_hermes = (data_dir / "relayer.toml")
relayer_config_hermes.write_text(
tomlkit.dumps(
jsonmerge.merge(
is_hermes = relayer == Relayer.HERMES
is_rly = relayer == Relayer.RLY
if is_hermes:
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
# write relayer config for hermes
relayer_config_hermes = (data_dir / "relayer.toml")
relayer_config_hermes.write_text(
tomlkit.dumps(
jsonmerge.merge(
{
"global": {
"log_level": "info",
},
"chains": [
relayer_chain_config_hermes(data_dir, c, cfg)
for c in chains
],
},
relayer_config,
)
)
)
if is_rly:
# write relayer config folder for rly
relayer_config_rly = data_dir
for folder in ["relayer", "config"]:
relayer_config_rly = relayer_config_rly / folder
relayer_config_rly.mkdir()
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
relayer_config_rly = relayer_config_rly / "config.yaml"
relayer_config_rly.write_text(
yaml.dump(
{
"global": {
"log_level": "info",
"api-listen-addr": ":5183",
"timeout": "10s",
"memo": "",
"light-cache-size": 20
},
"chains": [
relayer_chain_config_hermes(data_dir, c, cfg)
"chains": {
c["chain_id"]: relayer_chain_config_rly(data_dir, c, cfg)
for c in chains
],
},
relayer_config,
},
}
)
)
)
# write relayer config folder for rly
relayer_config_rly = data_dir
for folder in ["relayer", "config"]:
relayer_config_rly = relayer_config_rly / folder
relayer_config_rly.mkdir()
relayer_config_rly = relayer_config_rly / "config.yaml"
relayer_config_rly.write_text(
yaml.dump(
{
"global": {
"api-listen-addr": ":5183",
"timeout": "10s",
"memo": "",
"light-cache-size": 20
},
"chains": {
c["chain_id"]: relayer_chain_config_rly(data_dir, c, cfg)
for c in chains
},
}
)
)
for chain in chains:
relayer = chain.get("key_name", "relayer")
mnemonic = find_account(data_dir, chain["chain_id"], relayer)["mnemonic"]
key_name = chain.get("key_name", "relayer")
mnemonic = find_account(data_dir, chain["chain_id"], key_name)["mnemonic"]
mnemonic_path = Path(data_dir) / "relayer.env"
mnemonic_path.write_text(mnemonic)
# restore the relayer account for hermes
subprocess.run(
[
"hermes",
"--config",
relayer_config_hermes,
"keys",
"add",
"--chain",
chain["chain_id"],
"--mnemonic-file",
str(mnemonic_path),
"--overwrite",
"--hd-path",
"m/44'/" + str(chain.get("coin-type", 394)) + "'/0'/0/0",
],
check=True,
)
# restore the relayer account for rly
subprocess.run(
[
"rly",
"keys",
"restore",
chain["chain_id"],
"relayer",
mnemonic,
"--home",
str(data_dir / "relayer"),
],
check=True,
)
if is_hermes:
# restore the relayer account for hermes
subprocess.run(
[
"hermes",
"--config",
relayer_config_hermes,
"keys",
"add",
"--chain",
chain["chain_id"],
"--mnemonic-file",
str(mnemonic_path),
"--overwrite",
"--hd-path",
"m/44'/" + str(chain.get("coin-type", 394)) + "'/0'/0/0",
],
check=True,
)
if is_rly:
# restore the relayer account for rly
subprocess.run(
[
"rly",
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
"keys",
"restore",
chain["chain_id"],
"relayer",
mnemonic,
"--home",
str(data_dir / "relayer"),
],
check=True,
)


def find_account(data_dir, chain_id, name):
Expand Down