Skip to content

Commit

Permalink
update clients script
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Maslanka committed Dec 13, 2023
1 parent c6c82e3 commit 549495b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ ARG BASE_IMAGE="binhex/arch-base"

FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE}

ARG HERMES_VERSION="v1.7.0"
ARG HERMES_VERSION="v1.7.3"

COPY ./etc /etc/
COPY ./bin /usr/local/bin/

RUN set -eux && \
pacman -Syyu --noconfirm python-toml && \
curl -sSL https://github.com/informalsystems/hermes/releases/download/${HERMES_VERSION}/hermes-${HERMES_VERSION}-x86_64-unknown-linux-gnu.tar.gz | \
tar -xz -C /usr/local/bin && \
chmod +x /usr/local/bin/* && \
Expand Down
83 changes: 83 additions & 0 deletions bin/update_clients.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#! /usr/bin/env python3

import toml, json, subprocess

HERMES = "hermes"
HERMES_CONFIG = "/hermes/config.toml"


def hermes(command):
process = subprocess.run(
[HERMES, "--config", HERMES_CONFIG, "--json"] + command.split(" "),
stdout=subprocess.PIPE,
text=True,
)
output_lines = process.stdout.splitlines()

for line in output_lines:
line_json = json.loads(line)
if "result" in line_json:
return line_json
else:
return None


def get_connection(chain_id, port, channel):
output = hermes(
f"query channel end --chain {chain_id} --port {port} --channel {channel}"
)

if output["status"] == "success":
return output["result"]["connection_hops"][0]
else:
return None


def get_client_id(chain_id, connection):
output = hermes(
f"query connection end --chain {chain_id} --connection {connection}"
)

if output["status"] == "success":
return output["result"]["client_id"]
else:
return None


def get_clients_from_config():
config = toml.load(HERMES_CONFIG)
clients = []

for chain in config["chains"]:
chain_id = chain["id"]
whitelist = chain["packet_filter"]["list"]

for position in whitelist:
port = position[0]
channel = position[1]

connection = get_connection(chain_id, port, channel)
if connection:
client = get_client_id(chain_id, connection)
if client:
clients.append((chain_id, client))

return clients


def update_clients():
clients = get_clients_from_config()
for client in clients:
chain_id = client[0]
client_id = client[1]

output = hermes(f"update client --host-chain {chain_id} --client {client_id}")
result = output["result"]

if output["status"] == "success":
print(f"Success: {client_id} ({chain_id})")
else:
print(f"Failed: {result}")


update_clients()

0 comments on commit 549495b

Please sign in to comment.