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

Scripts for Gaiad network with full-mesh IBC connections #898

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Unreleased

> Nothing yet.
- [scripts]
- Added "full-mesh" scripts to simulate multiple interconnected networks on a local machine ([#897])

## v0.3.0
*May 7h, 2021*
Expand Down Expand Up @@ -72,6 +73,7 @@ and periodically refresh IBC clients. The relayer now also supports [ICS 027 (In
[#871]: https://github.com/informalsystems/ibc-rs/issues/871
[#873]: https://github.com/informalsystems/ibc-rs/issues/873
[#878]: https://github.com/informalsystems/ibc-rs/issues/878
[#897]: https://github.com/informalsystems/ibc-rs/issues/897
[#909]: https://github.com/informalsystems/ibc-rs/issues/909

## v0.2.0
Expand Down
6 changes: 6 additions & 0 deletions scripts/full-mesh/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docker-compose.gaiad.yml
docker-compose.yml
paths
network*/
.hermes/
.gaia/
80 changes: 80 additions & 0 deletions scripts/full-mesh/1-create-network-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/sh

##############################
## Script setup
##############################

# Fail if there are any errors
set -eu

# Run in a subfolder, not in your $HOME (safeguard against accidental .gaia-deletions)
test "$HOME" != "$(pwd)"

EXPECTED_GAIAD_VERSION=4.2.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wonderful! Looking forward to trying it out!

I'd love to be able to spin up a mesh with chains using different versions of gaia to test IBC and relayer compatibility between them. Testing that a gaia v4 chain can interact with gaia v5 using the same relayer binary

Another wishlist item is using non-gaia docker images, so chains could test out their docker image before upgrading on mainnet, but I think it might be best to let non-gaia chains copy the script and replace its relevant info rather than maintaining scripts for several chains

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! There were a lot of good points from the IBC-rs team about this, including non-gaia docker images. I'm not sure yet how we move forward because I find the current configuration fairly inflexible. We have another tool in the works that is much more flexible for developer work and allows you to choose your binaries on a per-node basis. (Issue #902 .)

So, we might continue expanding the configuration here or maybe we end up merging the two tools. But I'll definitely keep this in mind.

Small trick right now: you can do

make config-files
vi docker-compose.gaiad.yml
make network-up setup-relay

and edit the gaiad images that will be used before they are started.

DOCKER_IMAGE="cephalopodequipment/gaiad:${EXPECTED_GAIAD_VERSION}"
GAIAD="docker run --rm -v $(pwd):/home/gaiad --entrypoint /usr/bin/gaiad ${DOCKER_IMAGE}"
N="${1:-5}"
echo "N=$N"

##############################
## Create gaiad config
##############################

for i in $(seq 1 "$N")
do
test -d "network$i" && continue
echo "i=$i"
$GAIAD testnet --chain-id "network$i" --keyring-backend test --node-dir-prefix "network${i}v" -o . --node-daemon-home . --v 1
mv "network${i}v0" "network$i"
mv "gentxs" "network$i"
$GAIAD keys add "network${i}c0" --keyring-backend test --keyring-dir "network$i" --output json > "network${i}/client_wallet_seed.json"
$GAIAD add-genesis-account "network${i}c0" "10000000stake,10000network${i}coin" --keyring-backend test --home "network$i"
done

##############################
## Create docker-compose.gaiad.yml
##############################

cat <<EOF > docker-compose.gaiad.yml
services:
EOF

for i in $(seq 1 "$N")
do
RPC="$((26000 + 10 * i))"
LEET="$((RPC + 1))"
GRPC="$((RPC + 2))"
PP="$((RPC + 3))"

cat <<EOF >> docker-compose.gaiad.yml
network${i}:
container_name: network${i}
image: "$DOCKER_IMAGE"
entrypoint: "/usr/bin/gaiad"
command: start --x-crisis-skip-assert-invariants
ports:
- "$RPC:26657"
- "$LEET:1317"
- "$GRPC:9090"
- "$PP:26656"
volumes:
- $(pwd)/network${i}:/home/gaiad/.gaia
EOF

done

##############################
## Create full-mesh (default) networks connection graph
##############################

echo "# IBC full-mesh connection graph" > paths

for i in $(seq 1 "$((N-1))")
do
for j in $(seq "$((i+1))" "$N")
do
test $i -eq $j && continue
echo "$i $j" >> paths
done
done

67 changes: 67 additions & 0 deletions scripts/full-mesh/2-create-hermes-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

##############################
## Script setup
##############################

# Fail if there are any errors
set -eu

# Run in a subfolder, not in your $HOME (safeguard against accidental .hermes-deletions)
test "$HOME" != "$(pwd)"
# But if hermes was not run locally, we're going to overcome the issue of not having a --home parameter
ln -s $(pwd)/.hermes $HOME/.hermes || echo "$HOME/.hermes is already set, make sure you link it to .hermes here if you run things locally"

EXPECTED_HERMES_VERSION=0.2.0
DOCKER_IMAGE="informaldev/hermes:${EXPECTED_HERMES_VERSION}"
HERMES="docker run --rm -v $(pwd):/home/hermes --entrypoint /usr/bin/hermes ${DOCKER_IMAGE}"
N="${1:-5}"
echo "N=$N"

##############################
## Create config.toml
##############################

rm -rf .hermes && mkdir .hermes

cat <<EOF > .hermes/config.toml
[global]
strategy = 'naive'
log_level = 'info'

EOF

for i in $(seq 1 "$N")
do
RPC="$((26000 + 10 * i))"
GRPC="$((RPC + 2))"

cat <<EOF >> .hermes/config.toml
[[chains]]
id='network${i}'
rpc_addr='http://localhost:${RPC}'
grpc_addr='https://localhost:${GRPC}'
websocket_addr='ws://localhost:${RPC}/websocket'
rpc_timeout='1s'
account_prefix='cosmos'
key_name='network${i}c0'
store_prefix='ibc'
fee_denom='stake'

[chains.trust_threshold]
numerator = '1'
denominator = '3'

EOF

done

##############################
## Add keys to hermes
##############################

for i in $(seq 1 "$N")
do
$HERMES keys add "network$i" -f "network${i}/client_wallet_seed.json"
done

32 changes: 32 additions & 0 deletions scripts/full-mesh/3-create-onchain-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

##############################
## Script setup
##############################

# Fail if there are any errors
set -eu

# Run in a subfolder, not in your $HOME (safeguard against accidental .hermes-deletions)
test "$HOME" != "$(pwd)"
# But if hermes was not run locally, we're going to overcome the issue of not having a --home parameter
ln -s $(pwd)/.hermes $HOME/.hermes || echo "$HOME/.hermes is already set, make sure you link it to .hermes here if you run things locally"

EXPECTED_HERMES_VERSION=0.2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update this to 0.3.0?

DOCKER_IMAGE="informaldev/hermes:${EXPECTED_HERMES_VERSION}"
HERMES="docker run --rm -v $(pwd)/.hermes:/home/hermes/.hermes --net=host --entrypoint /usr/bin/hermes ${DOCKER_IMAGE}"

##############################
## Create paths on the networks
##############################

while read -r line;
do
VALID="$(echo "$line" | grep '^[ ]*[0-9]\+[ ]\+[0-9]\+[ ]*$' || echo "")"
test -n "$VALID" || continue
i="$(echo "$line" | grep -o '[0-9]\+' | head -1)"
j="$(echo "$line" | grep -o '[0-9]\+' | tail -1)"
echo "Connecting network$i and network$j"
$HERMES create channel "network$i" "network$j" --port-a transfer --port-b transfer
done < paths

43 changes: 43 additions & 0 deletions scripts/full-mesh/4-create-relayer-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

##############################
## Script setup
##############################

# Fail if there are any errors
set -eu

# Run in a subfolder, not in your $HOME (safeguard against accidental .hermes-deletions)
test "$HOME" != "$(pwd)"

EXPECTED_HERMES_VERSION=0.2.0
DOCKER_IMAGE="informaldev/hermes:${EXPECTED_HERMES_VERSION}"

##############################
## Create docker-compose.yml (set of hermes relayers)
##############################

cat <<EOF > docker-compose.yml
services:
EOF

while read -r line;
do
VALID="$(echo "$line" | grep '^[ ]*[0-9]\+[ ]\+[0-9]\+[ ]*$' || echo "")"
test -n "$VALID" || continue
i="$(echo "$line" | grep -o '[0-9]\+' | head -1)"
j="$(echo "$line" | grep -o '[0-9]\+' | tail -1)"

cat <<EOF >> docker-compose.yml
hermes-${i}-${j}:
container_name: hermes-${i}-${j}
network_mode: "host"
image: "$DOCKER_IMAGE"
entrypoint: "/usr/bin/hermes"
command: start network$i network$j -p transfer -c channel-0
volumes:
- $(pwd)/.hermes:/home/hermes/.hermes
EOF

done < paths

41 changes: 41 additions & 0 deletions scripts/full-mesh/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Number of nodes
N?=5

all: setup-network setup-relay

setup-network: config-files network-up
setup-relay: config-onchain relay-up

config-files:
./1-create-network-config.sh $(N)
./2-create-hermes-config.sh $(N)

network-up:
docker compose -f docker-compose.gaiad.yml -p gaiad up -d
sleep 5

network-start:
docker compose -f docker-compose.gaiad.yml -p gaiad start

network-stop:
docker compose -f docker-compose.gaiad.yml -p gaiad stop

network-down:
docker compose -f docker-compose.gaiad.yml -p gaiad down || true

config-onchain: paths
./3-create-onchain-config.sh
./4-create-relayer-config.sh

# If this command fails with aliases, you need to upgrade Docker CLI to 1.0.14 or above.
relay-up:
docker compose up -d

relay-down:
docker compose down || true

clean: relay-down network-down
@rm -rf gentxs network[0-9]* docker-compose.gaiad.yml docker-compose.yml paths .gaia .hermes
@echo DONE

.PHONY: config-files network-up network-down config-onchain relay-up relay-start relay-stop relay-down clean all
Loading