From f1412703a434c5e7cc25bdc3bfc09a1a67963619 Mon Sep 17 00:00:00 2001 From: spuddy <72078372+0xSpuddy@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:18:40 -0500 Subject: [PATCH] Scripts used for Setup and Testing (#462) * scripts for setup and testing * formatting * typo * more formatting (cherry picked from commit 2c607ac7e7c46329287a271bd37342afa6e89822) --- README.md | 13 +++++ layer_scripts/configure_layer_linux.sh | 61 ++++++++++++++++++++ layer_scripts/configure_layer_mac.sh | 61 ++++++++++++++++++++ local_devnet/upgrade_test.sh | 77 ++++++++++++++++++++++++++ 4 files changed, 212 insertions(+) create mode 100644 layer_scripts/configure_layer_linux.sh create mode 100644 layer_scripts/configure_layer_mac.sh create mode 100755 local_devnet/upgrade_test.sh diff --git a/README.md b/README.md index ed539acda..d674107b4 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,19 @@ Here you will find a detailed breakdown for how to join a chain as a node and ho Run the chain locally in a docker container, powered by [local-ic](https://github.com/strangelove-ventures/interchaintest/tree/main/local-interchain) +Install heighliner: +```sh +make get-heighliner +``` +Create image: +```sh +make local-image +``` +Install local interchain: +```sh +make get-localic +``` +Start the local-devnet: ```sh make local-devnet ``` diff --git a/layer_scripts/configure_layer_linux.sh b/layer_scripts/configure_layer_linux.sh new file mode 100644 index 000000000..55a799665 --- /dev/null +++ b/layer_scripts/configure_layer_linux.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# clear the terminal +clear + +# Stop execution if any command fails +set -e + +# set variables in your .bashrc before starting this script! +source ~/.bashrc + +export LAYER_NODE_URL=tellorlayer.com +export TELLORNODE_ID=5ca2c0eccb54e907ba474ce3b6827077ae40ba53 +export KEYRING_BACKEND="test" +export PEERS="5ca2c0eccb54e907ba474ce3b6827077ae40ba53@54.234.103.186:26656,c3223c066d7e97904192a1cdb99e7676ad03d581@3.147.56.107:26656,06067c9ce50f07f4fdd3dba4a7730c62b6225080@18.222.23.49:26656" + +echo "Change denom to loya in config files..." +sed -i 's/([0-9]+)stake/1loya/g' ~/.layer/config/app.toml + +echo "Set Chain Id to layer in client config file..." +sed -i 's/^chain-id = .*$/chain-id = "layer"/g' ~/.layer/config/app.toml + +# Modify timeout_commit in config.toml for node +echo "Modifying timeout_commit in config.toml for node..." +sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/' ~/.layer/config/config.toml + +# Open up node to outside traffic +echo "Open up node to outside traffice" +sed -i 's/^laddr = "tcp:\/\/127.0.0.1:26656"/laddr = "tcp:\/\/0.0.0.0:26656"/g' ~/.layer/config/config.toml + +sed -i 's/^address = "tcp:\/\/localhost:1317"/address = "tcp:\/\/0.0.0.0:1317"/g' ~/.layer/config/app.toml + +# Modify cors to accept * +echo "Modify cors to accept *" +sed -i 's/^cors_allowed_origins = \[\]/cors_allowed_origins = \["\*"\]/g' ~/.layer/config/config.toml + +# enable unsafe cors +echo "Enable unsafe cors" +sed -i 's/^cors_allowed_origins = \[\]/cors_allowed_origins = \["\*"\]/g' ~/.layer/config/app.toml +sed -i 's/^enable-unsafe-cors = false/enable-unsafe-cors = true/g' ~/.layer/config/app.toml +sed -i 's/^enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' ~/.layer/config/app.toml +sed -i 's/^enable-unsafe-cors = false/enable-unsafe-cors = true/g' ~/.layer/config/app.toml + +# Modify keyring-backend in client.toml for node +echo "Modifying keyring-backend in client.toml for node..." +sed -i 's/^keyring-backend = "os"/keyring-backend = "'$KEYRING_BACKEND'"/g' ~/.layer/config/client.toml +# update for main dir as well. why is this needed? +sed -i 's/keyring-backend = "os"/keyring-backend = "'$KEYRING_BACKEND'"/g' ~/.layer/config/client.toml + +rm -f ~/.layer/config/genesis.json +# get genesis file from running node's rpc +echo "Getting genesis from runnning node....." +curl $LAYER_NODE_URL:26657/genesis | jq '.result.genesis' > ~/.layer/config/genesis.json + +# set initial seeds / peers +echo "Running Tellor node id: $TELLORNODE_ID" +sed -i 's/seeds = ""/seeds = "'$PEERS'"/g' ~/.layer/config/config.toml +sed -i 's/persistent_peers = ""/persistent_peers = "'$PEERS'"/g' ~/.layer/config/config.toml + + +echo "layer has been configured in it's home folder!" diff --git a/layer_scripts/configure_layer_mac.sh b/layer_scripts/configure_layer_mac.sh new file mode 100644 index 000000000..cb97cab25 --- /dev/null +++ b/layer_scripts/configure_layer_mac.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# clear the terminal +clear + +# Stop execution if any command fails +set -e + +# set variables in your .bashrc before starting this script! +source ~/.zshrc + +export LAYER_NODE_URL=tellorlayer.com +export TELLORNODE_ID=5ca2c0eccb54e907ba474ce3b6827077ae40ba53 +export KEYRING_BACKEND="test" +export PEERS="5ca2c0eccb54e907ba474ce3b6827077ae40ba53@54.234.103.186:26656,c3223c066d7e97904192a1cdb99e7676ad03d581@3.147.56.107:26656,06067c9ce50f07f4fdd3dba4a7730c62b6225080@18.222.23.49:26656" + +echo "Change denom to loya in config files..." +sed -i '' 's/([0-9]+)stake/1loya/g' ~/.layer/config/app.toml + +echo "Set Chain Id to layer in client config file..." +sed -i '' 's/^chain-id = .*$/chain-id = "layer"/g' ~/.layer/config/app.toml + +# Modify timeout_commit in config.toml for node +echo "Modifying timeout_commit in config.toml for node..." +sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/' ~/.layer/config/config.toml + +# Open up node to outside traffic +echo "Open up node to outside traffice" +sed -i '' 's/^laddr = "tcp:\/\/127.0.0.1:26656"/laddr = "tcp:\/\/0.0.0.0:26656"/g' ~/.layer/config/config.toml + +sed -i '' 's/^address = "tcp:\/\/localhost:1317"/address = "tcp:\/\/0.0.0.0:1317"/g' ~/.layer/config/app.toml + +# Modify cors to accept * +echo "Modify cors to accept *" +sed -i '' 's/^cors_allowed_origins = \[\]/cors_allowed_origins = \["\*"\]/g' ~/.layer/config/config.toml + +# enable unsafe cors +echo "Enable unsafe cors" +sed -i '' 's/^cors_allowed_origins = \[\]/cors_allowed_origins = \["\*"\]/g' ~/.layer/config/app.toml +sed -i '' 's/^enable-unsafe-cors = false/enable-unsafe-cors = true/g' ~/.layer/config/app.toml +sed -i '' 's/^enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' ~/.layer/config/app.toml +sed -i '' 's/^enable-unsafe-cors = false/enable-unsafe-cors = true/g' ~/.layer/config/app.toml + +# Modify keyring-backend in client.toml for node +echo "Modifying keyring-backend in client.toml for node..." +sed -i '' 's/^keyring-backend = "os"/keyring-backend = "'$KEYRING_BACKEND'"/g' ~/.layer/config/client.toml +# update for main dir as well. why is this needed? +sed -i '' 's/keyring-backend = "os"/keyring-backend = "'$KEYRING_BACKEND'"/g' ~/.layer/config/client.toml + +rm -f ~/.layer/config/genesis.json +# get genesis file from running node's rpc +echo "Getting genesis from runnning node....." +curl $LAYER_NODE_URL:26657/genesis | jq '.result.genesis' > ~/.layer/config/genesis.json + +# set initial seeds / peers +echo "Running Tellor node id: $TELLORNODE_ID" +sed -i '' 's/seeds = ""/seeds = "'$PEERS'"/g' ~/.layer/config/config.toml +sed -i '' 's/persistent_peers = ""/persistent_peers = "'$PEERS'"/g' ~/.layer/config/config.toml + + +echo "layer has been configured in it's home folder!" diff --git a/local_devnet/upgrade_test.sh b/local_devnet/upgrade_test.sh new file mode 100755 index 000000000..92fb225c1 --- /dev/null +++ b/local_devnet/upgrade_test.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# THIS SCRIPT CAN BE USED TO TEST A CHAIN UPGRADE WHILE RUNNING THE LOCAL DEVNET +# BE SURE TO SET "expedited": false FOR THE PROPOSAL. +# THE LOCAL DEVNET HAS A 15s VOTING PERIOD. +# RUN THIS SCRIPT AS SOON AS THE DOCKER CONTAINERS START UP. +# Sleep times may need to be adjusted depending on the power of your computer. (faster computers go faster) + +# Stop execution if any command fails +set -e + +# use docker ps to get the container id hashes +echo "setting variables" +export ETH_RPC_URL="https://sepolia.infura.io/v3/53ba4f713bf940fb87a58280912231ab" +export TOKEN_BRIDGE_CONTRACT="0xFC1C57F1E466605e3Dd40840bC3e7DdAa400528c" +export upgrade_binary_path="/Users/sloetter/projects/layer/local_devnet/v2.0.0-audit/layerd" +export terminal="/Users/sloetter/projects/layer/local_devnet/v2.0.0-audit/layerd" + +# Get all container IDs into an array +container_ids=($(docker ps -q)) + +# automatically sets a CONTAINER_ variable for all containers +# (for running docker exec) +for i in "${!container_ids[@]}"; do + varname="CONTAINER_$((i + 1))" + export "$varname=${container_ids[i]}" + echo "Exported $varname=${container_ids[i]}" +done + +# optionally view the logs in the terminal: +# mac os: +# osascript -e "tell application \"Terminal\" to do script \"docker logs -f $CONTAINER_1\"" +# osascript -e "tell application \"Terminal\" to do script \"docker logs -f $CONTAINER_3\"" +# desktop linux with gnome: +# gnome-terminal -- bash -c "docker logs -f $CONTAINER_1; exec bash" +# gnome-terminal -- bash -c "docker logs -f $CONTAINER_NAME; exec bash" + +# copy proposal to node1 container and submit proposal +echo "copying the proposal to CONTAINER_1" +docker cp ./proposal.json $CONTAINER_1:/bin/ + +echo "proposing the upgrade" +docker exec $CONTAINER_1 layerd tx gov submit-proposal /bin/proposal.json --from validator --chain-id layer-1 --home /var/cosmos-chain/layer-1 --keyring-backend test --fees 510loya --yes + +# (optionally) check if proposal is live +# docker exec $node1_id layerd query gov proposals +# wait a bit +echo "voting in the next block..." +sleep 5 + +# vote on proposal +echo "voting on the upgrade proposal" +docker exec $CONTAINER_1 layerd tx gov vote 1 yes --from validator --chain-id layer-1 --home /var/cosmos-chain/layer-1 --keyring-backend test --fees 500loya --yes +docker exec $CONTAINER_2 layerd tx gov vote 1 yes --from validator --chain-id layer-1 --home /var/cosmos-chain/layer-1 --keyring-backend test --fees 500loya --yes +docker exec $CONTAINER_3 layerd tx gov vote 1 yes --from validator --chain-id layer-1 --home /var/cosmos-chain/layer-1 --keyring-backend test --fees 500loya --yes +docker exec $CONTAINER_4 layerd tx gov vote 1 yes --from validator --chain-id layer-1 --home /var/cosmos-chain/layer-1 --keyring-backend test --fees 500loya --yes + +echo "making reporters in the next block..." +sleep 5 + +# create 2 reporters to sanity check that reporting works before and after the upgrade +echo "creating two reporters to test that reporting works before / after upgrade" +docker exec $CONTAINER_3 layerd tx reporter create-reporter "2000000" "10000000" --from validator --home /var/cosmos-chain/layer-1 --keyring-dir /var/cosmos-chain/layer-1 --keyring-backend test --chain-id layer-1 --fees 500loya --yes +docker exec $CONTAINER_4 layerd tx reporter create-reporter "200000" "1000000" --from validator --home /var/cosmos-chain/layer-1 --keyring-dir /var/cosmos-chain/layer-1 --keyring-backend test --chain-id layer-1 --fees 500loya --yes + +# wait for chain to stop +sleep 30 + +#copy new binary into each container +docker cp $upgrade_binary_path $CONTAINER_1:/bin/ +docker cp $upgrade_binary_path $CONTAINER_2:/bin/ +docker cp $upgrade_binary_path $CONTAINER_3:/bin/ +docker cp $upgrade_binary_path $CONTAINER_4:/bin/ + +# all done! +echo "Done!" +echo "Restart the docker containers via docker desktop to verify that the upgrade was successsful."