Skip to content

Commit

Permalink
chore: simplify deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Dec 13, 2024
1 parent e9720fe commit e9fb263
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 251 deletions.
16 changes: 8 additions & 8 deletions scripts/testnet/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## Testnet Deployment SCripts
## Testnet Deployment Scripts

These scripts generate a genesis file and deploy chain across the nodes specified in the parameters.
These scripts generate a genesis file and deploy chain across nodes following the given configuration.

Make sure to first create a configuration file named config.sh using the template config_example.sh and populate it with the values reflecting your environment and desired deployment settings.
First, make sure to create a configuration file named `config.sh` using the template `config_example.sh`.
Then, check out the tag as specified by the configuration's `CHAIN_VERSION` and run `make build`.
Finally, run the scripts in the following order to generate the genesis file and deploy the chain:

Run in the following order, one by one:

1. `create_genesis.sh` - Validates validator files for each node and creates a genesis file.
2. `build_genesis_state.sh` - Runs a chain, deploys Wasm contracts on it, and dumps the Wasm state, which is then added to a given genesis file. Must be used with at least one of the following flags: `--add-groups` and `add-wasm-contracts`.
3. `upload_and_start.sh` - Uploads and runs setup_node.sh on the nodes to process necessary setups. Then uploads the validator files and genesis and restarts the nodes.
1. `create_genesis.sh` - Creates a genesis file with given parameters and token allocations.
2. `add_groups_to_genesis.sh` - Adds groups to the genesis file (optional).
3. `upload_and_start.sh` - Uploads and runs `setup_node.sh` on the nodes. Then uploads the validator files and starts the nodes.
102 changes: 102 additions & 0 deletions scripts/testnet/add_groups_to_genesis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash
set -euxo pipefail

source config.sh

########################################
# PRELIMINARY CHECKS AND DOWNLOADS #
########################################
ORIGINAL_GENESIS=$NODE_DIR/genesis.json
if [ ! -f "$ORIGINAL_GENESIS" ]; then
echo "Original genesis file not found inside node directory."
exit 1
fi

TMP_HOME=./tmp
rm -rf $TMP_HOME

TEMP_CHAIN_ID=temp-seda-chain

###################################
# SCRIPT BEGINS - START CHAIN #
###################################
$LOCAL_BIN init node0 --home $TMP_HOME --chain-id $TEMP_CHAIN_ID --default-denom aseda

$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

echo $ADMIN_SEED | $LOCAL_BIN keys add admin --home $TMP_HOME --keyring-backend test --recover
ADMIN_ADDR=$($LOCAL_BIN keys show admin --home $TMP_HOME --keyring-backend test -a)
$LOCAL_BIN add-genesis-account $ADMIN_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

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

sleep 20


###############################################
# SEND TRANSACTIONS WHILE CHAIN IS RUNNING #
###############################################

# Create group and group policy
# SEDA Security Policy
$LOCAL_BIN tx group create-group-with-policy $ADMIN_ADDR "Security Group" "{\"name\":\"Security Group Policy\",\"description\":\"\"}" $GROUP_SECURITY_MEMBERS $GROUP_SECURITY_POLICY --home $TMP_HOME --from $ADMIN_ADDR --keyring-backend test --fees 1seda --gas auto --gas-adjustment 1.5 --chain-id $TEMP_CHAIN_ID -y
sleep 10
# DAO Treasury Group
$LOCAL_BIN tx group create-group-with-policy $ADMIN_ADDR "Treasury Group" "{\"name\":\"Treasury Group Policy\",\"description\":\"\"}" $GROUP_TREASURY_MEMBERS $GROUP_TREASURY_POLICY --home $TMP_HOME --from $ADMIN_ADDR --keyring-backend test --fees 1seda --gas auto --gas-adjustment 1.5 --chain-id $TEMP_CHAIN_ID -y
sleep 10
# OOA Group
$LOCAL_BIN tx group create-group-with-policy $ADMIN_ADDR "OOA Group" "{\"name\":\"OOA Group Policy\",\"description\":\"\"}" $GROUP_OOA_MEMBERS $GROUP_OOA_POLICY --home $TMP_HOME --from $ADMIN_ADDR --keyring-backend test --fees 1seda --gas auto --gas-adjustment 1.5 --chain-id $TEMP_CHAIN_ID -y
sleep 10


#############################################################
# TERMINATE CHAIN PROCESS, EXPORT, AND MODIFY GIVEN GENESIS #
#############################################################
pkill sedad
sleep 5

$LOCAL_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

cp $ORIGINAL_GENESIS $TMP_GENESIS # make adjustments on TMP_GENESIS until replacing original genesis in the last step

# Modify group state and wasm code upload params
jq '.app_state["group"]' $EXPORTED_GENESIS > $TMP_HOME/group.tmp
TREASURY_GROUP_POLICY_ADDR=$(jq '.app_state["group"]["group_policies"][0]["address"]' $EXPORTED_GENESIS)
OOA_GROUP_POLICY_ADDR=$(jq '.app_state["group"]["group_policies"][1]["address"]' $EXPORTED_GENESIS)
SECURITY_GROUP_POLICY_ADDR=$(jq '.app_state["group"]["group_policies"][2]["address"]' $EXPORTED_GENESIS)

jq --slurpfile group $TMP_HOME/group.tmp '.app_state["group"] = $group[0]' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS

# replace group policy address as group & group policy admin
jq '(.app_state.group.groups[] | select(.metadata == "Security Group") .admin) |= '$SECURITY_GROUP_POLICY_ADDR'' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS
jq '(.app_state.group.group_policies[] | select(.address == '$SECURITY_GROUP_POLICY_ADDR') .admin) |= '$SECURITY_GROUP_POLICY_ADDR'' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS

jq '(.app_state.group.groups[] | select(.metadata == "Treasury Group") .admin) |= '$TREASURY_GROUP_POLICY_ADDR'' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS
jq '(.app_state.group.group_policies[] | select(.address == '$TREASURY_GROUP_POLICY_ADDR') .admin) |= '$TREASURY_GROUP_POLICY_ADDR'' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS

jq '(.app_state.group.groups[] | select(.metadata == "OOA Group") .admin) |= '$OOA_GROUP_POLICY_ADDR'' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS
jq '(.app_state.group.group_policies[] | select(.address == '$OOA_GROUP_POLICY_ADDR') .admin) |= '$OOA_GROUP_POLICY_ADDR'' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS

if [ "$WASM_PERMISSION_EVERYONE" != "true" ]; then
jq '.app_state["wasm"]["params"]["code_upload_access"]["permission"]="AnyOfAddresses"' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS
jq '.app_state["wasm"]["params"]["instantiate_default_permission"]="AnyOfAddresses"' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS
jq '.app_state["wasm"]["params"]["code_upload_access"]["addresses"]=['$SECURITY_GROUP_POLICY_ADDR']' $TMP_GENESIS > $TMP_TMP_GENESIS && mv $TMP_TMP_GENESIS $TMP_GENESIS
fi

mv $TMP_GENESIS $ORIGINAL_GENESIS

# clean up
rm -rf $TMP_HOME
rm chain_output.log
198 changes: 0 additions & 198 deletions scripts/testnet/build_genesis_state.sh

This file was deleted.

31 changes: 8 additions & 23 deletions scripts/testnet/config_example.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
CHAIN_ID=seda-1-devnet
GENESIS_TIME="2024-04-24T16:00:00.000000Z"
CHAIN_VERSION=v0.1.3
CHAIN_VERSION=v0.4.0-dev.8

WASM_PERMISSION_EVERYONE=true # true for everyone and false for mainnet configuration
SHORT_VOTING_PERIOD=true # true for 180s voting period or false for mainnet configuration

# If DOWNLOAD_FROM_RELEASE is set to false, specify RUN_NO and ARTIFACT_NO so the script
# can download the artifact.
DOWNLOAD_FROM_RELEASE=true
# RUN_NO=0123
# ARTIFACT_NO=0123

LOCAL_BIN=$(git rev-parse --show-toplevel)/build/sedad # chain binary executable on your machine
HOME_DIR=$HOME/.sedad # chain directory
HOME_CONFIG_DIR=$HOME_DIR/config # chain config directory
NODE_DIR=./$CHAIN_ID-nodes # where node directories will be created
WASM_DIR=./artifacts # where Wasm files will be downloaded


#######################################
########### VALIDATOR NODES ###########
#######################################
Expand All @@ -35,8 +22,8 @@ MONIKERS=(
"SEDA-node1"
)
SELF_DELEGATION_AMOUNTS=(
"27500seda"
"27500seda"
"27500"
"27500"
)

#######################################
Expand All @@ -53,11 +40,6 @@ GENESIS_ADDRESSES=(
"seda..."
)

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

#######################################
############ GROUP CONFIG #############
#######################################
Expand All @@ -72,6 +54,9 @@ GROUP_TREASURY_POLICY=./group_treasury_policy.json
ADMIN_SEED="mushroom energy ..." # seed for one of the genesis accounts - used for creating groups

#######################################
############### GITHUB ################
######### RARELY MODIFIED #############
#######################################
GITHUB_TOKEN=ghp_... # github token for accessing seda-chain-contracts repo
LOCAL_BIN=$(git rev-parse --show-toplevel)/build/sedad # chain binary executable on your machine
HOME_DIR=$HOME/.sedad # chain directory
HOME_CONFIG_DIR=$HOME_DIR/config # chain config directory
NODE_DIR=./$CHAIN_ID-nodes # where node directories will be created
Loading

0 comments on commit e9fb263

Please sign in to comment.