Skip to content

Commit

Permalink
chore: automatically download chain binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Jan 22, 2024
1 parent 12a713c commit f0e8d6a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 46 deletions.
28 changes: 14 additions & 14 deletions scripts/testnet/add_wasm_state_to_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ function download_contract_release() {
# $1: Contract file name
# $2: Initial state
function 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 --chain-id $TEMP_CHAIN_ID -y --output json)
local TX_OUTPUT=$($LOCAL_BIN tx wasm store $WASM_DIR/$1 --from $ADDR --keyring-backend test --gas auto --gas-adjustment 1.2 --home $TMP_HOME --chain-id $TEMP_CHAIN_ID -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 STORE_TX_OUTPUT=$($LOCAL_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 --chain-id $TEMP_CHAIN_ID -y --output json)
local INSTANTIATE_OUTPUT=$($LOCAL_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 --chain-id $TEMP_CHAIN_ID -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 INSTANTIATE_TX_OUTPUT=$($LOCAL_BIN query tx $TX_HASH --home $TMP_HOME --output json)
local CONTRACT_ADDRESS=$(echo $INSTANTIATE_TX_OUTPUT | jq -r '.events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address") | .value')
[[ -z "$CONTRACT_ADDRESS" ]] && { echo "failed to get contract address for ${1}" ; exit 1; }

Expand Down Expand Up @@ -95,16 +95,16 @@ TEMP_CHAIN_ID=temp-seda-chain
#
# SCRIPT BEGINS - START CHAIN
#
$BIN init node0 --home $TMP_HOME --chain-id $TEMP_CHAIN_ID --default-denom aseda
$LOCAL_BIN init node0 --home $TMP_HOME --chain-id $TEMP_CHAIN_ID --default-denom aseda

$BIN keys add deployer --home $TMP_HOME --keyring-backend test
ADDR=$($BIN keys show deployer --home $TMP_HOME --keyring-backend test -a)
$BIN add-genesis-account $ADDR 100000000000000000seda --home $TMP_HOME --keyring-backend test
$BIN gentx deployer 10000000000000000seda --home $TMP_HOME --keyring-backend test --chain-id $TEMP_CHAIN_ID
$BIN collect-gentxs --home $TMP_HOME
$LOCAL_BIN keys add deployer --home $TMP_HOME --keyring-backend test
ADDR=$($LOCAL_BIN keys show deployer --home $TMP_HOME --keyring-backend test -a)
$LOCAL_BIN add-genesis-account $ADDR 100000000000000000seda --home $TMP_HOME --keyring-backend test
$LOCAL_BIN gentx deployer 10000000000000000seda --home $TMP_HOME --keyring-backend test --chain-id $TEMP_CHAIN_ID
$LOCAL_BIN collect-gentxs --home $TMP_HOME


$BIN start --home $TMP_HOME > chain_output.log 2>&1 & disown
$LOCAL_BIN start --home $TMP_HOME > chain_output.log 2>&1 & disown

sleep 20

Expand All @@ -122,9 +122,9 @@ 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 --chain-id $TEMP_CHAIN_ID -y
$LOCAL_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 --chain-id $TEMP_CHAIN_ID -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 --chain-id $TEMP_CHAIN_ID -y
$LOCAL_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 --chain-id $TEMP_CHAIN_ID -y
sleep 10


Expand All @@ -134,7 +134,7 @@ sleep 10
pkill seda-chaind
sleep 5

$BIN export --home $TMP_HOME > $TMP_HOME/exported
$LOCAL_BIN export --home $TMP_HOME > $TMP_HOME/exported
python3 -m json.tool $TMP_HOME/exported > $TMP_HOME/genesis.json
rm $TMP_HOME/exported

Expand Down
46 changes: 39 additions & 7 deletions scripts/testnet/config_example.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@

NODE_DIR=./nodes # where node directories will be created
WASM_DIR=./artifacts # where Wasm files are located
CHAIN_ID=seda-testnet
GENESIS_TIME="2024-01-18T22:00:00.000000Z"

NODE_DIR=./$CHAIN_ID-nodes # where node directories will be created
WASM_DIR=./artifacts # where Wasm files will be downloaded

HOME_DIR=$HOME/.seda-chain # chain directory
HOME_CONFIG_DIR=$HOME_DIR/config # chain config directory

BIN=$(git rev-parse --show-toplevel)/build/seda-chaind # chain binary executable on your machine
LOCAL_BIN=$(git rev-parse --show-toplevel)/build/seda-chaind # chain binary executable on your machine
LINUX_BIN=$(git rev-parse --show-toplevel)/build/seda-chaind-linux # linux version of chain binary

CHAIN_ID=seda-testnet
# GENESIS_TIME=
DENOM_METADATA='[
{
"description": "The token asset for SEDA Chain",
"denom_units": [
{
"denom": "aseda",
"exponent": 0,
"aliases": [
"attoseda"
]
},
{
"denom": "seda",
"exponent": 18,
"aliases": []
}
],
"base": "aseda",
"display": "seda",
"name": "seda",
"symbol": "SEDA"
}
]'

IBC_ALLOWED_CLIENTS='[
"06-solomachine",
"07-tendermint"
]'

WASMVM_VERSION=v1.5.2

#######################################
########### VALIDATOR NODES ###########
Expand All @@ -33,7 +63,6 @@ SELF_DELEGATION_AMOUNTS=(

SSH_KEY=~/.ssh/id_rsa # key used for ssh


#######################################
########## GENESIS ACCOUNTS ###########
#######################################
Expand All @@ -48,9 +77,12 @@ GENESIS_ADDRESSES=(
SATOSHI=seda... # if set, creates a genesis account with 100x seda tokens compared to standard genesis account
FAUCET=seda... # if set, creates a genesis account with 10x seda tokens compared to standard genesis account

#######################################
######### COSMWASM CONTRACTS ##########
#######################################
CONTRACTS_VERSION=v0.0.1-rc # latest or seda-chain-contracts release version

#######################################
############### GITHUB ################
#######################################
GITHUB_TOKEN=ghp_... # github token for accessing seda-chain-contracts repo
CONTRACTS_VERSION=v0.0.1-rc # latest or seda-chain-contracts release version
32 changes: 15 additions & 17 deletions scripts/testnet/create_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ rm -rf $NODE_DIR
#
# CREATE GENESIS AND ADJUST GENESIS PARAMETERS
#
$BIN init node0 --chain-id $CHAIN_ID --default-denom aseda
$LOCAL_BIN init node0 --chain-id $CHAIN_ID --default-denom aseda

cat $HOME/.seda-chain/config/genesis.json | jq --arg GENESIS_TIME $GENESIS_TIME '.genesis_time=$GENESIS_TIME' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json

# bank params
cat $HOME/.seda-chain/config/genesis.json | jq --argjson denom_metadata "$DENOM_METADATA" '.app_state["bank"]["denom_metadata"]=$denom_metadata' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json

# crisis params
cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["amount"]="1000000000000"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json
Expand All @@ -42,6 +43,7 @@ cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["max
cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["gov"]["params"]["min_initial_deposit_ratio"]="0.010000000000000000"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json

# ibc params
cat $HOME/.seda-chain/config/genesis.json | jq --argjson ibc_allowed_clients "$IBC_ALLOWED_CLIENTS" '.app_state["ibc"]["client_genesis"]["params"]["allowed_clients"]=$ibc_allowed_clients' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json

# mint params
cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["mint"]["params"]["blocks_per_year"]="4204800"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json
Expand All @@ -56,26 +58,22 @@ cat $HOME/.seda-chain/config/genesis.json | jq '.app_state["slashing"]["params"]
# consensus params
cat $HOME/.seda-chain/config/genesis.json | jq '.consensus["params"]["block"]["max_gas"]="100000000"' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json

# TO-DO
# - gov (intentionally adjusted for testing): voting_params.voting_period, params.voting_period, params.expedited_voting_period, min_deposit[0].amount, max_deposit_period
# - cat $HOME/.seda-chain/config/genesis.json | jq '.consensus["params"]["version"]={}' > $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 --arg IBC_ALLOWED_CLIENTS $IBC_ALLOWED_CLIENTS '.app_state["ibc"]["client_genesis"]["params"]["allowed_clients"]=$IBC_ALLOWED_CLIENTS' > $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 --arg DENOM_METADATA $DENOM_METADATA '.app_state["bank"]["denom_metadata"]=$DENOM_METADATA' > $HOME/.seda-chain/config/tmp_genesis.json && mv $HOME/.seda-chain/config/tmp_genesis.json $HOME/.seda-chain/config/genesis.json
# - wasm params
# TO-DO gov (intentionally adjusted for testing): voting_params.voting_period, params.voting_period, params.expedited_voting_period, min_deposit[0].amount, max_deposit_period
# TO-DO wasm params

#
# ADD GENESIS ACCOUNTS
#
for i in ${!GENESIS_ADDRESSES[@]}; do
$BIN add-genesis-account ${GENESIS_ADDRESSES[$i]} 100000000000000000seda
$LOCAL_BIN add-genesis-account ${GENESIS_ADDRESSES[$i]} 100000000000000000seda
done

set +u
if [ ! -z "$SATOSHI" ]; then
$BIN add-genesis-account $SATOSHI 10000000000000000000seda
$LOCAL_BIN add-genesis-account $SATOSHI 10000000000000000000seda
fi
if [ ! -z "$FAUCET" ]; then
$BIN add-genesis-account $FAUCET 1000000000000000000seda
$LOCAL_BIN add-genesis-account $FAUCET 1000000000000000000seda
fi
set -u

Expand All @@ -89,21 +87,21 @@ for i in ${!MONIKERS[@]}; do
INDIVIDUAL_VAL_HOME_DIR=$NODE_DIR/${MONIKERS[$i]}
INDIVIDUAL_VAL_CONFIG_DIR="$INDIVIDUAL_VAL_HOME_DIR/config"

$BIN init ${MONIKERS[$i]} --home $INDIVIDUAL_VAL_HOME_DIR --chain-id $CHAIN_ID --default-denom aseda
$BIN keys add ${MONIKERS[$i]} --keyring-backend=test --home $INDIVIDUAL_VAL_HOME_DIR
$LOCAL_BIN init ${MONIKERS[$i]} --home $INDIVIDUAL_VAL_HOME_DIR --chain-id $CHAIN_ID --default-denom aseda
$LOCAL_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)
VALIDATOR_ADDRESS=$($LOCAL_BIN keys show ${MONIKERS[$i]} --keyring-backend test --home $INDIVIDUAL_VAL_HOME_DIR -a)

# to create their gentx
$BIN add-genesis-account $VALIDATOR_ADDRESS 500000000000000000seda --home $INDIVIDUAL_VAL_HOME_DIR
$LOCAL_BIN add-genesis-account $VALIDATOR_ADDRESS 500000000000000000seda --home $INDIVIDUAL_VAL_HOME_DIR
# to output geneis file
$BIN add-genesis-account $VALIDATOR_ADDRESS 500000000000000000seda
$LOCAL_BIN add-genesis-account $VALIDATOR_ADDRESS 500000000000000000seda

$BIN gentx ${MONIKERS[$i]} ${SELF_DELEGATION_AMOUNTS[$i]} --moniker=${MONIKERS[$i]} --keyring-backend=test --home $INDIVIDUAL_VAL_HOME_DIR --ip=${IPS[$i]} --chain-id $CHAIN_ID
$LOCAL_BIN gentx ${MONIKERS[$i]} ${SELF_DELEGATION_AMOUNTS[$i]} --moniker=${MONIKERS[$i]} --keyring-backend=test --home $INDIVIDUAL_VAL_HOME_DIR --ip=${IPS[$i]} --chain-id $CHAIN_ID

cp -a $INDIVIDUAL_VAL_CONFIG_DIR/gentx/. $GENTX_DIR
done

cp -r $GENTX_DIR $HOME_CONFIG_DIR
$BIN collect-gentxs --home $HOME_DIR
$LOCAL_BIN collect-gentxs --home $HOME_DIR
cp $HOME_CONFIG_DIR/genesis.json $NODE_DIR
25 changes: 17 additions & 8 deletions scripts/testnet/upload_and_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ 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."
if [ ! -f "$LOCAL_BIN" ]; then
echo "local chain binary not found."
exit 1
fi

# download chain binaries
curl -LO https://github.com/sedaprotocol/seda-chain/releases/download/$CHAIN_VERSION/seda-chaind-amd64
mv seda-chaind-amd64 $NODE_DIR
curl -LO https://github.com/sedaprotocol/seda-chain/releases/download/$CHAIN_VERSION/seda-chaind-arm64
mv seda-chaind-arm64 $NODE_DIR


################################################
############# Set up for new nodes #############
Expand All @@ -49,7 +51,7 @@ done

SEEDS=()
for i in ${!IPS[@]}; do
SEED=$($BIN tendermint show-node-id --home $NODE_DIR/node$i)
SEED=$($LOCAL_BIN tendermint show-node-id --home $NODE_DIR/node$i)
SEEDS+=("$SEED@${IPS[$i]}:26656")
done

Expand All @@ -75,9 +77,16 @@ for i in ${!IPS[@]}; do

ssh -i $SSH_KEY -t ec2-user@${IPS[$i]} 'sudo rm -rf /home/ec2-user/.seda-chain'

# upload
# upload node files
scp -i $SSH_KEY -r $NODE_DIR/node$i ec2-user@${IPS[$i]}:/home/ec2-user/.seda-chain

# upload chain binary built for the corresponding architecture
LINUX_BIN=$NODE_DIR/seda-chaind-amd64
ARCH=$(ssh -i $SSH_KEY -t ec2-user@${IPS[$i]} 'uname -m') # aarch64 or x86_64
if [ $ARCH == "aarch64" ]; then
LINUX_BIN=$NODE_DIR/seda-chaind-arm64
fi

ssh -i $SSH_KEY -t ec2-user@${IPS[$i]} 'mkdir -p /home/ec2-user/.seda-chain/cosmovisor/genesis/bin'
scp -i $SSH_KEY $LINUX_BIN ec2-user@${IPS[$i]}:/home/ec2-user/.seda-chain/cosmovisor/genesis/bin/seda-chaind

Expand Down

0 comments on commit f0e8d6a

Please sign in to comment.