-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add testnet deployment scripts
- Loading branch information
1 parent
6a1f50d
commit be335ca
Showing
6 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
# | ||
# This script dumps wasm states after storing and instantiating contracts. | ||
# Then, it adds these states to a given original genesis file. | ||
# The final genesis file is placed in the current directory as genesis.json. | ||
# | ||
|
||
# | ||
# PARAMETERS | ||
# | ||
WASM_DIR=./artifacts # where Wasm files are located | ||
BIN=../../build/seda-chaind # chain binary executable on your machine | ||
ORIGINAL_GENESIS=./nodes/genesis.json # genesis file to be modified by this script | ||
|
||
|
||
# | ||
# PRELIMINARY CHECKS | ||
# | ||
if [ ! -f "$ORIGINAL_GENESIS" ]; then | ||
echo "Original genesis file not found." | ||
exit 1 | ||
fi | ||
|
||
TMP_HOME=./tmp | ||
rm -rf $TMP_HOME | ||
|
||
|
||
# store_and_instantiate() stores and instantiates a contract and returns its address | ||
# Accept arguments: | ||
# $1: Contract file name | ||
# $2: Initial state | ||
store_and_instantiate() { | ||
local TX_OUTPUT=$($BIN tx wasm store $WASM_DIR/$1 --from $ADDR --keyring-backend test --gas auto --gas-adjustment 1.2 --home $TMP_HOME -y --output json) | ||
[[ -z "$TX_OUTPUT" ]] && { echo "failed to get tx output" ; exit 1; } | ||
local TX_HASH=$(echo $TX_OUTPUT | jq -r .txhash) | ||
sleep 10; | ||
|
||
local STORE_TX_OUTPUT=$($BIN query tx $TX_HASH --home $TMP_HOME --output json) | ||
local CODE_ID=$(echo $STORE_TX_OUTPUT | jq -r '.events[] | select(.type | contains("store_code")).attributes[] | select(.key | contains("code_id")).value') | ||
[[ -z "$CODE_ID" ]] && { echo "failed to get code ID" ; exit 1; } | ||
|
||
local INSTANTIATE_OUTPUT=$($BIN tx wasm instantiate $CODE_ID "$2" --no-admin --from $ADDR --keyring-backend test --label $CODE_ID --gas auto --gas-adjustment 1.2 --home $TMP_HOME -y --output json) | ||
TX_HASH=$(echo "$INSTANTIATE_OUTPUT" | jq -r '.txhash') | ||
sleep 10; | ||
|
||
local INSTANTIATE_TX_OUTPUT=$($BIN query tx $TX_HASH --home $TMP_HOME --output json) | ||
local CONTRACT_ADDRESS=$(echo $INSTANTIATE_TX_OUTPUT | jq -r '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value') | ||
[[ -z "$CONTRACT_ADDRESS" ]] && { echo "failed to get contract address for ${1}" ; exit 1; } | ||
|
||
echo $CONTRACT_ADDRESS | ||
} | ||
|
||
|
||
# | ||
# SCRIPT BEGINS - START CHAIN | ||
# | ||
$BIN init new node0 --home $TMP_HOME | ||
|
||
$BIN keys add satoshi --home $TMP_HOME --keyring-backend test | ||
ADDR=$($BIN keys show satoshi --home $TMP_HOME --keyring-backend test -a) | ||
$BIN add-genesis-account $ADDR 100000000000000000seda --home $TMP_HOME --keyring-backend test | ||
$BIN gentx satoshi 10000000000000000seda --home $TMP_HOME --keyring-backend test | ||
$BIN collect-gentxs --home $TMP_HOME | ||
|
||
|
||
$BIN start --home $TMP_HOME > chain_output.log 2>&1 & disown | ||
|
||
sleep 20 | ||
|
||
|
||
# | ||
# SEND TRANSACTIONS WHILE CHAIN IS RUNNING | ||
# | ||
|
||
# Store and instantiate three contracts | ||
PROXY_ADDR=$(store_and_instantiate proxy_contract.wasm '{"token":"aseda"}') | ||
|
||
ARG='{"token":"aseda", "proxy": "'$PROXY_ADDR'" }' | ||
STAKING_ADDR=$(store_and_instantiate staking.wasm "$ARG") | ||
DR_ADDR=$(store_and_instantiate data_requests.wasm "$ARG") | ||
|
||
|
||
# Call SetStaking and SetDataRequests on Proxy contract to set circular dependency | ||
$BIN tx wasm execute $PROXY_ADDR '{"set_staking":{"contract":"'$STAKING_ADDR'"}}' --from $ADDR --gas auto --gas-adjustment 1.2 --keyring-backend test --home $TMP_HOME -y | ||
sleep 10 | ||
$BIN tx wasm execute $PROXY_ADDR '{"set_data_requests":{"contract":"'$DR_ADDR'"}}' --from $ADDR --gas auto --gas-adjustment 1.2 --keyring-backend test --home $TMP_HOME -y | ||
sleep 10 | ||
|
||
|
||
|
||
# | ||
# TERMINATE CHAIN PROCESS, EXPORT, AND MODIFY GIVEN GENESIS | ||
# | ||
pkill seda-chaind | ||
|
||
|
||
$BIN export --home $TMP_HOME > $TMP_HOME/exported | ||
python3 -m json.tool $TMP_HOME/exported > $TMP_HOME/genesis.json | ||
rm $TMP_HOME/exported | ||
|
||
|
||
EXPORTED_GENESIS=$TMP_HOME/genesis.json | ||
TMP_GENESIS=$TMP_HOME/tmp_genesis.json | ||
TMP_TMP_GENESIS=$TMP_HOME/tmp_tmp_genesis.json | ||
|
||
# | ||
# Modify | ||
# - wasm.codes | ||
# - wasm.contracts | ||
# - wasm.sequences | ||
# - wasm-storage.proxy_contract_registry | ||
# | ||
CODES=$(jq '.app_state["wasm"]["codes"]' $EXPORTED_GENESIS) | ||
CONTRACTS=$(jq '.app_state["wasm"]["contracts"]' $EXPORTED_GENESIS) | ||
SEQUENCES=$(jq '.app_state["wasm"]["sequences"]' $EXPORTED_GENESIS) | ||
|
||
jq '.app_state["wasm-storage"]["proxy_contract_registry"]="'$PROXY_ADDR'"' "$ORIGINAL_GENESIS" > "$TMP_TMP_GENESIS" && mv $TMP_TMP_GENESIS $TMP_GENESIS | ||
jq '.app_state["wasm"]["codes"]='"$CODES"'' "$TMP_GENESIS" > "$TMP_TMP_GENESIS" && mv $TMP_TMP_GENESIS $TMP_GENESIS | ||
jq '.app_state["wasm"]["contracts"]='"$CONTRACTS"'' "$TMP_GENESIS" > "$TMP_TMP_GENESIS" && mv $TMP_TMP_GENESIS $TMP_GENESIS | ||
jq '.app_state["wasm"]["sequences"]='"$SEQUENCES"'' "$TMP_GENESIS" > "$TMP_TMP_GENESIS" && mv $TMP_TMP_GENESIS $TMP_GENESIS | ||
|
||
mv $TMP_GENESIS $ORIGINAL_GENESIS | ||
rm -rf $TMP_HOME |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
# | ||
# This script accomplishes the following: | ||
# - Add genesis accounts | ||
# - Create node key and validator file for each given node | ||
# - Create and collect gentxs | ||
# | ||
# The resulting files are placed in $OUT_DIR | ||
# | ||
|
||
# | ||
# PARAMETERS | ||
# | ||
OUT_DIR=./nodes # output directory | ||
BIN=../../build/seda-chaind # chain binary executable on your machine | ||
HOME_DIR=$HOME/.seda-chain # chain directory | ||
CONFIG_DIR=$HOME_DIR/config # chain config directory | ||
# validators | ||
IPS=( | ||
"18.169.59.167" | ||
"35.178.98.62" | ||
) | ||
MONIKERS=( | ||
"node0" | ||
"node1" | ||
) | ||
SELF_DELEGATION_AMOUNTS=( | ||
"30000000000000000seda" | ||
"10000000000000000seda" | ||
) | ||
# genesis acoounts addresses | ||
ADDR1=seda19gqrkdjhju0txurteag8vle90p09a5r5dd78rp | ||
ADDR2=seda1gnes565n2vhldm2eerm5fcuwz2mpcadvqnvped | ||
ADDR3=seda1wr0la8asy5wg9ja83rvdy36cmp4qrztypytdl7 | ||
ADDR4=seda154aany5fudkp9mncekupm3hwr7w3da3dv79c4k | ||
ADDR5=seda15yfxudv7ek8m6ecxt4u9v5a677yhm3d662z3fg | ||
ADDR6=seda1c3czshqflpxs9eyns9r906gk9s9xfcpsf7rcac | ||
ADDR7=seda1uvraznfum5zc2tke5vu3hcj9n7a4ndcv533gnr | ||
ADDR8=seda1z3ecw3k2asd5gd82v7m78y6u5y5vm7xnp46lf2 | ||
# CHAIN_ID=seda-testnet | ||
# GENESIS_TIME= | ||
|
||
|
||
# | ||
# PRELIMINARY PROCESS | ||
# | ||
rm -rf $HOME_DIR | ||
rm -rf $OUT_DIR | ||
|
||
# | ||
# CREATE GENESIS AND ADJUST GOV PARAMETERS | ||
# | ||
$BIN init new node0 | ||
|
||
cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="180s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json | ||
cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["voting_period"]="180s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json | ||
cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["max_deposit_period"]="180s"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json | ||
|
||
# TO-DO? | ||
# - chain id | ||
# - launch time | ||
|
||
# | ||
# ADD GENESIS ACCOUNTS | ||
# | ||
$BIN add-genesis-account $ADDR1 100000000000000000seda --keyring-backend test | ||
$BIN add-genesis-account $ADDR2 100000000000000000seda --keyring-backend test | ||
$BIN add-genesis-account $ADDR3 100000000000000000seda --keyring-backend test | ||
$BIN add-genesis-account $ADDR4 100000000000000000seda --keyring-backend test | ||
$BIN add-genesis-account $ADDR5 100000000000000000seda --keyring-backend test | ||
$BIN add-genesis-account $ADDR6 100000000000000000seda --keyring-backend test | ||
$BIN add-genesis-account $ADDR7 100000000000000000seda --keyring-backend test | ||
$BIN add-genesis-account $ADDR8 100000000000000000seda --keyring-backend test | ||
|
||
|
||
# | ||
# CREATE NODE KEY, VALIDATOR KEY, AND GENTX FOR EACH NODE | ||
# | ||
GENTX_DIR=$OUT_DIR/gentx | ||
mkdir -p $GENTX_DIR | ||
|
||
for i in ${!MONIKERS[@]}; do | ||
INDIVIDUAL_VAL_HOME_DIR=$OUT_DIR/${MONIKERS[$i]} | ||
INDIVIDUAL_VAL_CONFIG_DIR="$INDIVIDUAL_VAL_HOME_DIR/config" | ||
|
||
$BIN init new ${MONIKERS[$i]} --home $INDIVIDUAL_VAL_HOME_DIR | ||
$BIN keys add ${MONIKERS[$i]} --keyring-backend=test --home $INDIVIDUAL_VAL_HOME_DIR | ||
|
||
VALIDATOR_ADDRESS=$($BIN keys show ${MONIKERS[$i]} --keyring-backend test --home $INDIVIDUAL_VAL_HOME_DIR -a) | ||
|
||
# to create their gentx | ||
$BIN add-genesis-account $VALIDATOR_ADDRESS 100000000000000000seda --home $INDIVIDUAL_VAL_HOME_DIR | ||
# to output geneis file | ||
$BIN add-genesis-account $VALIDATOR_ADDRESS 100000000000000000seda | ||
|
||
$BIN gentx ${MONIKERS[$i]} ${SELF_DELEGATION_AMOUNTS[$i]} --moniker=${MONIKERS[$i]} --keyring-backend=test --home $INDIVIDUAL_VAL_HOME_DIR --ip=${IPS[$i]} | ||
|
||
cp -a $INDIVIDUAL_VAL_CONFIG_DIR/gentx/. $GENTX_DIR | ||
done | ||
|
||
cp -r $GENTX_DIR $CONFIG_DIR | ||
|
||
$BIN collect-gentxs --home $HOME_DIR | ||
|
||
cp $CONFIG_DIR/genesis.json $OUT_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
|
||
# NOTE: | ||
# Assuming systemctl is set up for seda-node.service | ||
# Assuming cosmovisor has been set up | ||
# | ||
# To FIX: | ||
# connection closing after every ssh command | ||
# | ||
|
||
# | ||
# PARAMETERS | ||
# | ||
SSH_KEY=~/.ssh/id_rsa # key used for ssh | ||
BIN=../../build/seda-chaind # chain binary executable on your machine | ||
LINUX_BIN=../../build/seda-chaind-linux # linux version of chain binary | ||
NODE_DIR=./nodes # OUT_DIR in other scripts | ||
DESTINATIONS=( | ||
"[email protected]" | ||
"[email protected]" | ||
) | ||
IPS=( | ||
"18.169.59.167:26656" | ||
"35.178.98.62:26656" | ||
) | ||
|
||
|
||
# Prelimiary checks | ||
if [ ! -f "$SSH_KEY" ]; then | ||
echo "ssh key file not found." | ||
exit 1 | ||
fi | ||
if [ ! -f "$BIN" ]; then | ||
echo "binary file not found." | ||
exit 1 | ||
fi | ||
if [ ! -f "$LINUX_BIN" ]; then | ||
echo "linux binary file not found." | ||
exit 1 | ||
fi | ||
|
||
SEEDS=() | ||
for i in ${!DESTINATIONS[@]}; do | ||
SEED=$($BIN tendermint show-node-id --home ./$NODE_DIR/node$i) | ||
SEEDS+=("$SEED@${IPS[$i]}") | ||
done | ||
|
||
printf -v list '%s,' "${SEEDS[@]}" | ||
SEEDS_LIST="${list%,}" | ||
echo $SEEDS_LIST | ||
|
||
for i in ${!DESTINATIONS[@]}; do | ||
cp $NODE_DIR/genesis.json $NODE_DIR/node$i/config/genesis.json | ||
|
||
sed -i '' "s/seeds = \"\"/seeds = \"${SEEDS_LIST}\"/g" ./$NODE_DIR/node$i/config/config.toml | ||
|
||
# stop and remove | ||
ssh -i $SSH_KEY -t ${DESTINATIONS[$i]} 'sudo systemctl stop seda-node.service' | ||
ssh -i $SSH_KEY -t ${DESTINATIONS[$i]} 'sudo rm -f /var/log/seda-chain-error.log' | ||
ssh -i $SSH_KEY -t ${DESTINATIONS[$i]} 'sudo rm -f /var/log/seda-chain-output.log' | ||
|
||
ssh -i $SSH_KEY -t ${DESTINATIONS[$i]} 'sudo rm -rf /home/ec2-user/.seda-chain' | ||
|
||
# upload | ||
scp -i $SSH_KEY -r ./$NODE_DIR/node$i ${DESTINATIONS[$i]}:/home/ec2-user/.seda-chain | ||
|
||
ssh -i $SSH_KEY -t ${DESTINATIONS[$i]} 'mkdir -p /home/ec2-user/.seda-chain/cosmovisor/genesis/bin' | ||
scp -i $SSH_KEY $LINUX_BIN ${DESTINATIONS[$i]}:/home/ec2-user/.seda-chain/cosmovisor/genesis/bin/seda-chaind | ||
|
||
# start | ||
ssh -i $SSH_KEY -t ${DESTINATIONS[$i]} 'chmod 755 /home/ec2-user/.seda-chain/cosmovisor/genesis/bin/seda-chaind' | ||
ssh -i $SSH_KEY -t ${DESTINATIONS[$i]} 'sudo systemctl daemon-reload' | ||
ssh -i $SSH_KEY -t ${DESTINATIONS[$i]} 'sudo systemctl start seda-node.service' | ||
done |