Skip to content

Instantly share code, notes, and snippets.

@CharlyCst
Last active January 16, 2021 18:13
Show Gist options
  • Save CharlyCst/48fc02d4c1e6ed59e6395ee6ae766703 to your computer and use it in GitHub Desktop.
Save CharlyCst/48fc02d4c1e6ed59e6395ee6ae766703 to your computer and use it in GitHub Desktop.
A script to create and update a client with the IBC relayer
#!/bin/bash
BIN="$1"
CONFIG="$2"
if [[ $BIN == "" || $CONFIG == "" ]]
then
echo "usage: $0 <path_to_relayer> <path_to_config>"
exit 1
fi
# remove any lingering data
if [ -a data0 ]
then
rm -rf data0/*
fi
if [ -a data1 ]
then
rm -rf data1/*
fi
mkdir -p data0
mkdir -p data1
# remove all light clients for each chain, the '-c' parameter must correspond to the chain identifier in the $CONFIG file:
$BIN -c $CONFIG light rm -c chain_A --all -y
$BIN -c $CONFIG light rm -c chain_B --all -y
# setup primary light client peers for each chain
$BIN -c $CONFIG light add localhost:26657 -c chain_A -f -p -s data0 -y
$BIN -c $CONFIG light add localhost:26557 -c chain_B -f -p -s data1 -y
# setup witness peers for the light clients (note: the precise peer ids are not important here):
$BIN -c $CONFIG light add localhost:26657 -c chain_A -s data0 -y --peer-id 5CD00153B35C4811D29736BF7C1B825056BED454
$BIN -c $CONFIG light add localhost:26557 -c chain_B -s data1 -y --peer-id 8C16EEB6C01698F62E2359C6250FDB965FC2A89B
# register the key seed files for each chain
# download the file from https://gist.github.com/adizere/f17ea650de7d9256edfeee248fe22b18 and save as 'key_seed.json'
# we'll use the same key seed for both chains
curl https://gist.githubusercontent.com/adizere/f17ea650de7d9256edfeee248fe22b18/raw/60489d7dfe34a947799d815654bf2bac0c75625f/key_seed.json > key_seed.json
$BIN -c $CONFIG keys add chain_A key_seed.json
$BIN -c $CONFIG keys add chain_B key_seed.json
# create a client
$BIN -c $CONFIG tx raw create-client chain_A chain_B
# update the client
while :
do
$BIN -c $CONFIG tx raw update-client chain_A chain_B defaultClient
sleep 5
done
[global]
timeout = '10s'
strategy = 'naive'
[[chains]]
id = 'chain_A'
rpc_addr = 'tcp://localhost:26657'
grpc_addr = 'tcp://localhost:9090'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
client_ids = [
'clA1',
'clA2',
]
gas = 200000
max_msg_num = 4
max_tx_size = 1048576
clock_drift = '5s'
trusting_period = '3days'
[chains.trust_threshold]
numerator = '1'
denominator = '3'
[chains.peers]
primary = '3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D'
[[chains.peers.light_clients]]
peer_id = '3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D'
address = 'tcp://localhost:26657'
timeout = '10s'
trusted_header_hash = 'B79718A5032F3776B621494701953888FE4C804628E8D6C6ABDCB98601C7527D'
trusted_height = '15'
[chains.peers.light_clients.store]
type = 'disk'
path = 'data0/3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D'
[[chains.peers.light_clients]]
peer_id = '5CD00153B35C4811D29736BF7C1B825056BED454'
address = 'tcp://localhost:26657'
timeout = '10s'
trusted_header_hash = 'B79718A5032F3776B621494701953888FE4C804628E8D6C6ABDCB98601C7527D'
trusted_height = '15'
[chains.peers.light_clients.store]
type = 'disk'
path = 'data0/5CD00153B35C4811D29736BF7C1B825056BED454'
[[chains]]
id = 'chain_B'
rpc_addr = 'tcp://localhost:26557'
grpc_addr = 'tcp://localhost:9090'
account_prefix = 'cosmos'
key_name = 'testkey'
store_prefix = 'ibc'
client_ids = ['clB1']
clock_drift = '5s'
trusting_period = '3days'
[chains.trust_threshold]
numerator = '1'
denominator = '3'
[chains.peers]
primary = '3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D'
[[chains.peers.light_clients]]
peer_id = '3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D'
address = 'tcp://localhost:26557'
timeout = '10s'
trusted_header_hash = 'B79718A5032F3776B621494701953888FE4C804628E8D6C6ABDCB98601C7527D'
trusted_height = '15'
[chains.peers.light_clients.store]
type = 'disk'
path = 'data1/3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D3D'
[[chains.peers.light_clients]]
peer_id = '8C16EEB6C01698F62E2359C6250FDB965FC2A89B'
address = 'tcp://localhost:26557'
timeout = '10s'
trusted_header_hash = 'B79718A5032F3776B621494701953888FE4C804628E8D6C6ABDCB98601C7527D'
trusted_height = '15'
[chains.peers.light_clients.store]
type = 'disk'
path = 'data1/8C16EEB6C01698F62E2359C6250FDB965FC2A89B'
[[connections]]
[connections.a_end]
chain_id = 'chain_A'
client_id = 'clB1'
connection_id = 'connAtoB'
[connections.b_end]
chain_id = 'chain_B'
client_id = 'clA1'
connection_id = 'connBtoA'
[[connections.paths]]
a_port = 'transfer'
b_port = 'transfer'
direction = 'unidirectional'
[[connections.paths]]
a_port = 'transfer'
b_port = 'transfer'
direction = 'bidirectional'
[[connections.paths]]
a_port = 'transfer'
b_port = 'transfer'
a_channel = 'chan3onA'
b_channel = 'chan3onB'
direction = 'bidirectional'
@CharlyCst
Copy link
Author

Usage

Download the script and the configuration file, as well as the IBC relayer (see ibc-rs)

curl https://gist.githubusercontent.com/CharlyCst/48fc02d4c1e6ed59e6395ee6ae766703/raw/e528a2cc6409da5e48d64e5414c1d16db9f00c40/relayer.sh > relayer.sh
curl https://gist.githubusercontent.com/CharlyCst/48fc02d4c1e6ed59e6395ee6ae766703/raw/e528a2cc6409da5e48d64e5414c1d16db9f00c40/relayer_config.toml > relayer_config.toml
chmod +x relayer.sh

Then start two Terdermock nodes using docker (you can use different terminals for better log visualisation)

docker run -p 26657:26657 -p 9090:50051 --rm gripsou/tendermock
docker run -p 26557:26657 -p 9091:50051 --rm gripsou/tendermock

Finally run the relayer by passing a path to the executable to relayer.sh:

./relayer.sh <path_to_relayer_bin> relayer_config.toml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment