Skip to content

Instantly share code, notes, and snippets.

@ratik
Created July 25, 2023 11:27
Show Gist options
  • Save ratik/3d3c0852fde6becccf6e91c03d10a173 to your computer and use it in GitHub Desktop.
Save ratik/3d3c0852fde6becccf6e91c03d10a173 to your computer and use it in GitHub Desktop.
lsm_net
#!/bin/bash
set -o errexit -o nounset
CHAINID=${CHAINID:-"testlsm"}
CONFIG=${CONFIG:-"config.json"}
AMOUNT=100000000000000stake
VAMOUNT=10000000000000stake
keys=()
values=()
walletkeys=()
walletvalues=()
peers=()
while IFS=" " read -r key value
do
key=$(echo ${key} | sed s/_MNEMONIC//i | tr '[:upper:]' '[:lower:]')
keys+=("$key")
values+=("$value")
done < <(cat $CONFIG | jq -r '.validators | to_entries[] | select(.key|test("MNEMONIC")) | "\(.key) \(.value)"')
while IFS=" " read -r key value
do
key=$(echo ${key} | sed s/_MNEMONIC//i | tr '[:upper:]' '[:lower:]')
walletkeys+=("$key")
walletvalues+=("$value")
done < <(cat $CONFIG | jq -r '.wallets | to_entries[] | "\(.key) \(.value)"')
# Then, use the saved keys and values in the docker-compose loop
for index in "${!keys[@]}"; do
key=${keys[$index]}
value=${values[$index]}
if [[ $key == *"val"* ]]; then
echo "Setting val" $key
docker-compose run -T --rm $key init $key --chain-id $CHAINID --home=/opt
echo $value | docker-compose run --rm -T $key keys add $key --recover --keyring-backend=test --home=/opt
docker-compose run --rm -T $key keys list --keyring-backend=test --home=/opt
docker-compose run --rm -T $key add-genesis-account $key $AMOUNT --keyring-backend=test --home=/opt
for j in "${!walletkeys[@]}"; do
walletkey=${walletkeys[$j]}
walletvalue=${walletvalues[$j]}
echo $walletvalue | docker-compose run --rm -T $key keys add $walletkey --recover --keyring-backend=test --home=/opt
docker-compose run --rm -T $key add-genesis-account $walletkey $AMOUNT --keyring-backend=test --home=/opt
done
docker-compose run --rm -T $key gentx $key $VAMOUNT --chain-id $CHAINID --home=/opt --keyring-backend=test
docker-compose run --rm -d -T --entrypoint sleep $key inf
container=$(docker-compose ps -a $key -q)
docker cp $container:/opt/config/gentx .
docker stop $container
peer_id=$(docker-compose run --rm -T $key tendermint show-node-id --home=/opt)
peers+=("$peer_id@$key:26656")
fi
done
docker-compose run --rm -d -T --entrypoint sleep val1 inf
container=$(docker-compose ps -a val1 -q)
docker cp $(pwd)/gentx $container:/opt/config/gentx
docker-compose exec val1 liquidstakingd collect-gentxs --home=/opt
docker cp $container:/opt/config/genesis.json $(pwd)/_genesis.json
docker cp $container:/opt/config/config.toml $(pwd)/_config.toml
docker stop $container
sed -i '' 's/"validator_bond_factor": "-1.000000000000000000"/"validator_bond_factor": "10.000000000000000000"/g' $(pwd)/_genesis.json
IFS=","
peerslist=$(echo "${peers[*]}")
unset IFS
sed -i '' 's/^persistent_peers = ""/persistent_peers = "'$peerslist'"/g' $(pwd)/_config.toml
for index in "${!keys[@]}"; do
key=${keys[$index]}
docker-compose run --rm -d -T --entrypoint sleep $key inf
container=$(docker-compose ps -a $key -q)
docker cp $(pwd)/_genesis.json $container:/opt/config/genesis.json
docker cp $(pwd)/_config.toml $container:/opt/config/config.toml
docker stop $container
done
docker-compose up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment