add deploy scripts

This commit is contained in:
Peter Zhang 2024-04-21 20:09:34 +08:00 committed by 0g-wh
parent 31d565f5a7
commit e976f28232
2 changed files with 98 additions and 93 deletions

View File

@ -6,13 +6,13 @@ function help() {
echo " -i Identity file" echo " -i Identity file"
echo " -k Keyring password to create key (for Linux only)" echo " -k Keyring password to create key (for Linux only)"
echo " -n Network (default: testnet)" echo " -n Network (default: testnet)"
echo " -c Chain ID (default: \"zgtendermint_9000-1\")" echo " -c Chain ID (default: \"zgtendermint_16600-1\")"
echo "" echo ""
} }
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
help help
exit 1 exit 1
fi fi
set -e set -e
@ -25,29 +25,29 @@ NETWORK="testnet"
INIT_GENESIS_ENV="" INIT_GENESIS_ENV=""
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
-i) -i)
PEM_FLAG="-i $2"; PEM_FLAG="-i $2";
shift; shift shift; shift
;; ;;
-k) -k)
KEYRING_PASSWORD=$2; KEYRING_PASSWORD=$2;
shift; shift shift; shift
;; ;;
-n) -n)
NETWORK=$2 NETWORK=$2
INIT_GENESIS_ENV="$INIT_GENESIS_ENV export ROOT_DIR=$2;" INIT_GENESIS_ENV="$INIT_GENESIS_ENV export ROOT_DIR=$2;"
shift; shift shift; shift
;; ;;
-c) -c)
INIT_GENESIS_ENV="$INIT_GENESIS_ENV export CHAIN_ID=$2;" INIT_GENESIS_ENV="$INIT_GENESIS_ENV export CHAIN_ID=$2;"
shift; shift shift; shift
;; ;;
*) *)
help help
echo "Unknown flag passed: \"$1\"" echo "Unknown flag passed: \"$1\""
exit 1 exit 1
;; ;;
esac esac
done done
@ -56,7 +56,7 @@ NUM_NODES=${#IPS[@]}
# Install dependent libraries and binary # Install dependent libraries and binary
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
ssh $PEM_FLAG ubuntu@${IPS[$i]} "git clone https://github.com/0glabs/0g-chain.git; cd 0g-chain; ./networks/testnet/install.sh" ssh $PEM_FLAG ubuntu@${IPS[$i]} "rm -rf 0g-chain; git clone https://github.com/0glabs/0g-chain.git; cd 0g-chain; git checkout testnet; ./networks/testnet/install.sh"
done done
# Create genesis config on node0 # Create genesis config on node0

View File

@ -1,29 +1,29 @@
#!/bin/bash #!/bin/bash
ROOT_DIR=${ROOT_DIR:-testnet} ROOT_DIR=${ROOT_DIR:-testnet}
CHAIN_ID=${CHAIN_ID:-zgtendermint_9000-1} CHAIN_ID=${CHAIN_ID:-zgtendermint_16600-1}
# Usage: init-genesis.sh IP1,IP2,IP3 KEYRING_PASSWORD # Usage: init-genesis.sh IP1,IP2,IP3 KEYRING_PASSWORD
OS_NAME=`uname -o` OS_NAME=`uname -o`
USAGE="Usage: ${BASH_SOURCE[0]} IP1,IP2,IP3" USAGE="Usage: ${BASH_SOURCE[0]} IP1,IP2,IP3"
if [[ "$OS_NAME" = "GNU/Linux" ]]; then if [[ "$OS_NAME" = "GNU/Linux" ]]; then
USAGE="$USAGE KEYRING_PASSWORD" USAGE="$USAGE KEYRING_PASSWORD"
fi fi
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
echo "IP list not specified" echo "IP list not specified"
echo $USAGE echo $USAGE
exit 1 exit 1
fi fi
if [[ "$OS_NAME" = "GNU/Linux" ]]; then if [[ "$OS_NAME" = "GNU/Linux" ]]; then
if [[ $# -eq 1 ]]; then if [[ $# -eq 1 ]]; then
echo "Keyring password not specified" echo "Keyring password not specified"
echo $USAGE echo $USAGE
exit 1 exit 1
fi fi
PASSWORD=$2 PASSWORD=$2
fi fi
kava version 2>/dev/null || export PATH=$PATH:$(go env GOPATH)/bin kava version 2>/dev/null || export PATH=$PATH:$(go env GOPATH)/bin
@ -33,19 +33,20 @@ set -e
IFS=","; declare -a IPS=($1); unset IFS IFS=","; declare -a IPS=($1); unset IFS
NUM_NODES=${#IPS[@]} NUM_NODES=${#IPS[@]}
BALANCE=$((100000000/$NUM_NODES))kava VLIDATOR_BALANCE=20000000000000ukava
STAKING=$((50000000/$NUM_NODES))kava FAUCET_BALANCE=20000000000000ukava
STAKING=2000000000000ukava
# Init configs # Init configs
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
HOMEDIR="$ROOT_DIR"/node$i HOMEDIR="$ROOT_DIR"/node$i
# Change parameter token denominations to neuron # Change parameter token denominations to neuron
GENESIS="$HOMEDIR"/config/genesis.json GENESIS="$HOMEDIR"/config/genesis.json
TMP_GENESIS="$HOMEDIR"/config/tmp_genesis.json TMP_GENESIS="$HOMEDIR"/config/tmp_genesis.json
# Init # Init
kava init "node$i" --home "$HOMEDIR" --chain-id "$CHAIN_ID" >/dev/null 2>&1 kava init "node$i" --home "$HOMEDIR" --chain-id "$CHAIN_ID" >/dev/null 2>&1
# Replace stake with ukava # Replace stake with ukava
sed -in-place='' 's/stake/ukava/g' "$GENESIS" sed -in-place='' 's/stake/ukava/g' "$GENESIS"
@ -80,16 +81,19 @@ for ((i=0; i<$NUM_NODES; i++)) do
strategies: ["STRATEGY_TYPE_SAVINGS"], strategies: ["STRATEGY_TYPE_SAVINGS"],
}]' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS }]' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS
cat $GENESIS | jq '.app_state.savings.params.supported_denoms = ["bkava-kavavaloper1ffv7nhd3z6sych2qpqkk03ec6hzkmufyz4scd0"]' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS # cat "$GENESIS" | jq '.app_state["staking"]["params"]["bond_denom"]="ukava"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# cat "$GENESIS" | jq '.app_state["gov"]["params"]["min_deposit"][0]["denom"]="ukava"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# cat "$GENESIS" | jq '.app_state["staking"]["params"]["bond_denom"]="ukava"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" cat "$GENESIS" | jq '.app_state["staking"]["params"]["max_validators"]=200' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# cat "$GENESIS" | jq '.app_state["gov"]["params"]["min_deposit"][0]["denom"]="neuron"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" cat "$GENESIS" | jq '.app_state["slashing"]["params"]["signed_blocks_window"]="1000"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# Change app.toml cat "$GENESIS" | jq '.app_state["consensus_params"]["block"]["time_iota_ms"]="3000"' >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
APP_TOML="$HOMEDIR"/config/app.toml
sed -i 's/minimum-gas-prices = "0akava"/minimum-gas-prices = "1000000000ukava"/' "$APP_TOML" # Change app.toml
sed -i '/\[json-rpc\]/,/^\[/ s/enable = false/enable = true/' "$APP_TOML" APP_TOML="$HOMEDIR"/config/app.toml
sed -i '/\[json-rpc\]/,/^\[/ s/address = "127.0.0.1:8545"/address = "0.0.0.0:8545"/' "$APP_TOML" sed -i 's/minimum-gas-prices = "0akava"/minimum-gas-prices = "1000000000akava"/' "$APP_TOML"
sed -i '/\[json-rpc\]/,/^\[/ s/enable = false/enable = true/' "$APP_TOML"
sed -i '/\[json-rpc\]/,/^\[/ s/address = "127.0.0.1:8545"/address = "0.0.0.0:8545"/' "$APP_TOML"
# Set evm tracer to json # Set evm tracer to json
sed -in-place='' 's/tracer = ""/tracer = "json"/g' "$APP_TOML" sed -in-place='' 's/tracer = ""/tracer = "json"/g' "$APP_TOML"
@ -102,13 +106,13 @@ done
# Update seeds in config.toml # Update seeds in config.toml
SEEDS="" SEEDS=""
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
if [[ $i -gt 0 ]]; then SEEDS=$SEEDS,; fi if [[ $i -gt 0 ]]; then SEEDS=$SEEDS,; fi
NODE_ID=`kava tendermint show-node-id --home $ROOT_DIR/node$i` NODE_ID=`kava tendermint show-node-id --home $ROOT_DIR/node$i`
SEEDS=$SEEDS$NODE_ID@${IPS[$i]}:26656 SEEDS=$SEEDS$NODE_ID@${IPS[$i]}:26656
done done
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
sed -i "/seeds = /c\seeds = \"$SEEDS\"" "$ROOT_DIR"/node$i/config/config.toml sed -i "/seeds = /c\seeds = \"$SEEDS\"" "$ROOT_DIR"/node$i/config/config.toml
done done
# Prepare validators # Prepare validators
@ -121,53 +125,54 @@ done
# - Windows: Windows credentials management. # - Windows: Windows credentials management.
# - Linux: under `--home` specified folder. # - Linux: under `--home` specified folder.
if [[ "$OS_NAME" = "Msys" ]]; then if [[ "$OS_NAME" = "Msys" ]]; then
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
VALIDATOR="0gchain_9000_validator_$i" VALIDATOR="0gchain_9000_validator_$i"
set +e set +e
ret=`kava keys list --keyring-backend os -n | grep $VALIDATOR` ret=`kava keys list --keyring-backend os -n | grep $VALIDATOR`
set -e set -e
if [[ "$ret" = "" ]]; then if [[ "$ret" = "" ]]; then
echo "Create validator key: $VALIDATOR" echo "Create validator key: $VALIDATOR"
kava keys add $VALIDATOR --keyring-backend os kava keys add $VALIDATOR --keyring-backend os --eth
fi fi
done done
elif [[ "$OS_NAME" = "GNU/Linux" ]]; then elif [[ "$OS_NAME" = "GNU/Linux" ]]; then
# Create N validators for node0 # Create N validators for node0
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
yes $PASSWORD | kava keys add "0gchain_9000_validator_$i" --keyring-backend os --home "$ROOT_DIR"/node0 yes $PASSWORD | kava keys add "0gchain_9000_validator_$i" --keyring-backend os --home "$ROOT_DIR"/node0 --eth
done done
# Copy validators to other nodes # Copy validators to other nodes
for ((i=1; i<$NUM_NODES; i++)) do for ((i=1; i<$NUM_NODES; i++)) do
cp "$ROOT_DIR"/node0/keyhash "$ROOT_DIR"/node$i cp "$ROOT_DIR"/node0/keyhash "$ROOT_DIR"/node$i
cp "$ROOT_DIR"/node0/*.address "$ROOT_DIR"/node$i cp "$ROOT_DIR"/node0/*.address "$ROOT_DIR"/node$i
cp "$ROOT_DIR"/node0/*.info "$ROOT_DIR"/node$i cp "$ROOT_DIR"/node0/*.info "$ROOT_DIR"/node$i
done done
else else
echo -e "\n\nOS: $OS_NAME" echo -e "\n\nOS: $OS_NAME"
echo "Unsupported OS to generate keys for validators!!!" echo "Unsupported OS to generate keys for validators!!!"
exit 1 exit 1
fi fi
# Add all validators in genesis # Add all validators in genesis
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
for ((j=0; j<$NUM_NODES; j++)) do for ((j=0; j<$NUM_NODES; j++)) do
if [[ "$OS_NAME" = "GNU/Linux" ]]; then if [[ "$OS_NAME" = "GNU/Linux" ]]; then
yes $PASSWORD | kava add-genesis-account "0gchain_9000_validator_$i" $BALANCE --home "$ROOT_DIR/node$j" yes $PASSWORD | kava add-genesis-account "0gchain_9000_validator_$j" $VLIDATOR_BALANCE --home "$ROOT_DIR/node$i"
else else
kava add-genesis-account "0gchain_9000_validator_$i" $BALANCE --home "$ROOT_DIR/node$j" kava add-genesis-account "0gchain_9000_validator_$j" $VLIDATOR_BALANCE --home "$ROOT_DIR/node$i"
fi fi
done done
kava add-genesis-account kava17n8707c20e8gge2tk2gestetjcs4536pdtf8y0 $FAUCET_BALANCE --home "$ROOT_DIR/node$i"
done done
# Prepare genesis txs # Prepare genesis txs
mkdir -p "$ROOT_DIR"/gentxs mkdir -p "$ROOT_DIR"/gentxs
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
if [[ "$OS_NAME" = "GNU/Linux" ]]; then if [[ "$OS_NAME" = "GNU/Linux" ]]; then
yes $PASSWORD | kava gentx "0gchain_9000_validator_$i" $STAKING --home "$ROOT_DIR/node$i" --output-document "$ROOT_DIR/gentxs/node$i.json" yes $PASSWORD | kava gentx "0gchain_9000_validator_$i" $STAKING --home "$ROOT_DIR/node$i" --output-document "$ROOT_DIR/gentxs/node$i.json"
else else
kava gentx "0gchain_9000_validator_$i" $STAKING --home "$ROOT_DIR/node$i" --output-document "$ROOT_DIR/gentxs/node$i.json" kava gentx "0gchain_9000_validator_$i" $STAKING --home "$ROOT_DIR/node$i" --output-document "$ROOT_DIR/gentxs/node$i.json"
fi fi
done done
# Create genesis at node0 and copy to other nodes # Create genesis at node0 and copy to other nodes
@ -175,20 +180,20 @@ kava collect-gentxs --home "$ROOT_DIR/node0" --gentx-dir "$ROOT_DIR/gentxs" >/de
sed -i '/persistent_peers = /c\persistent_peers = ""' "$ROOT_DIR"/node0/config/config.toml sed -i '/persistent_peers = /c\persistent_peers = ""' "$ROOT_DIR"/node0/config/config.toml
kava validate-genesis --home "$ROOT_DIR/node0" kava validate-genesis --home "$ROOT_DIR/node0"
for ((i=1; i<$NUM_NODES; i++)) do for ((i=1; i<$NUM_NODES; i++)) do
cp "$ROOT_DIR"/node0/config/genesis.json "$ROOT_DIR"/node$i/config/genesis.json cp "$ROOT_DIR"/node0/config/genesis.json "$ROOT_DIR"/node$i/config/genesis.json
done done
# For linux, backup keys for all validators # For linux, backup keys for all validators
if [[ "$OS_NAME" = "GNU/Linux" ]]; then if [[ "$OS_NAME" = "GNU/Linux" ]]; then
mkdir -p "$ROOT_DIR"/keyring-os mkdir -p "$ROOT_DIR"/keyring-os
cp "$ROOT_DIR"/node0/keyhash "$ROOT_DIR"/keyring-os cp "$ROOT_DIR"/node0/keyhash "$ROOT_DIR"/keyring-os
cp "$ROOT_DIR"/node0/*.address "$ROOT_DIR"/keyring-os cp "$ROOT_DIR"/node0/*.address "$ROOT_DIR"/keyring-os
cp "$ROOT_DIR"/node0/*.info "$ROOT_DIR"/keyring-os cp "$ROOT_DIR"/node0/*.info "$ROOT_DIR"/keyring-os
for ((i=0; i<$NUM_NODES; i++)) do for ((i=0; i<$NUM_NODES; i++)) do
rm -f "$ROOT_DIR"/node$i/keyhash "$ROOT_DIR"/node$i/*.address "$ROOT_DIR"/node$i/*.info rm -f "$ROOT_DIR"/node$i/keyhash "$ROOT_DIR"/node$i/*.address "$ROOT_DIR"/node$i/*.info
done done
fi fi
echo -e "\n\nSucceeded to init genesis!\n" echo -e "\n\nSucceeded to init genesis!\n"