Skip to content

Commit

Permalink
fix: add build setup for validator script
Browse files Browse the repository at this point in the history
  • Loading branch information
JeancarloBarrios committed Oct 17, 2023
1 parent c8d9a80 commit 3e8238b
Showing 1 changed file with 60 additions and 59 deletions.
119 changes: 60 additions & 59 deletions scripts/validator_setup/validator_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,79 @@
set -e

# Basic Setup Configurations
# --------------------------
# This script is used to setup a validator node for the seda-chain network
# It takes the following parameters insde a env file:
# 1. MNEMONIC: The mnemonic of the validator account
# 2. KEYRING_PASSWORD: The password to encrypt the keyring
# 3. NETWORK_ID: The network id of the seda-chain network
# 4. MONIKER: The moniker of the validator node
# 5. NODE_ADDRESS: The address of the seda-chain network
# IE:
# MONIKER="somemonicer"
#MNEMONIC="a mnemonic"
#KEYRING_PASSWORD="somepassword"
#NETWORK_ID="devnet"
#NODE_ADDRESS="http://35.177.180.184:26657"

BIN=seda-chaind # chain binary executable on your machine
KEYRING="${KEYRING:-file}"
KEYPASSWD="${KEYPASSWD:-somepassword}"
CHAIN_ID="${CHAIN_ID:-sedachain}"
NETWORK="${NETWORK:-devnet}"
MONIKER="${MONIKER:-node-test2}"
MNEMONIC="mixture alone swear radar gate violin subway wink panther slim photo banana robust quarter client piano topic coin wool shove derive august volume alone"
SEDA_NODE="${SEDA_NODE:-http://35.177.180.184:26657}"
KEY_NAME="${KEY_NAME:-default_key}"

$BIN config keyring-backend file # use file backend
#if NODE_ADDRESS is not provided exit with error
if [[ -z "${NODE_ADDRESS}" ]]; then
echo "Error no key NODE_ADDRESS provided"
exit 1
fi

if [[ -z "${KEYRING_PASSWORD}" ]]; then
echo "Error no key KEYRING_PASSWORD provided"
exit 1
fi

KeyName="${KEY_NAME:-default_key}"
if [[ -z "${NETWORK_ID}" ]]; then
echo "Error no key NETWORK_ID provided"
exit 1
fi

# Adds a key to the keyring with the given MNEMONIC and KEYPASSWD (if provided) and KeyName
if [[ -z "${MNEMONIC}" ]]; then
# $BIN
echo $KeyName
echo "Error no mnemonic provided"
# (echo $KEYPASSWD; echo $KEYPASSWD) | $BIN keys add $KeyName
else
echo "Recovered key from mnemonic"
(echo $MNEMONIC; echo $KEYPASSWD; echo $KEYPASSWD) | $BIN keys add $KEY_NAME --recover
if [[ -z "${MONIKER}" ]]; then
echo "Error no key password provided"
exit 1
fi

if [[ -z "${MNEMONIC}" ]]; then
echo "Error no key MNEMONIC provided"
exit 1
fi

# Set the keyring-backend to file
# Initialize NODE config
echo "Initializing Node ..."
echo $MNEMONIC | $BIN init join ${MONIKER} --network ${NETWORK} --recover
echo "Node Initialized !"
echo "Connecting to Network ..."
echo $SEDA_NODE | $BIN config node $SEDA_NODE
echo "Conected to network !"

# VALIDATOR ENVS
STAKE_AMOUNT="${STAKE_AMOUNT:-"100000000000000000seda"}"
echo $STAKE_AMOUNT
COMMISSION_RATE="${COMMISSION_RATE:-"0.10"}"
COMMISSION_MAX_RATE="${COMMISSION_MAX_RATE:-"0.20"}"
COMMISSION_MAX_CHANGE_RATE="${COMMISSION_MAX_CHANGE_RATE:"-0.01"}"
MINIMAL_SELF_DELETAGION="${MINIMAL_SELF_DELETAGION:-10}"
# Check if configuration directory seda-chain config directory exist if it does not
# exist initialize the node with the given MNEMONIC, MONIKER and NETWORK_ID
if ! [ -f /root/.seda-chain/config/genesis.json ]; then
echo "Setting Up seda configuration"
$BIN config keyring-backend file # use file backend
echo $MNEMONIC | $BIN init join ${MONIKER} --network ${NETWORK_ID} --recover
else
echo "seda configuration already exists"
fi

#if [[ ! -d "/root/.seda-chain" ]]; then
# echo "Setting Up seda configuration"
# echo $MNEMONIC | $BIN init join ${MONIKER} --network ${NETWORK_ID} --recover
# else
# echo "seda configuration already exists"
#fi
echo "Node Initialized !"

# Query for a validator if it does not exist exist create it
echo "Setting up validator ..."
echo "Querying for validator ..."
VALIDATOR=$($BIN query staking validators --output json | jq -r '.validators[] | select(.description.moniker=="'"${MONIKER}"'")')
echo $VALIDATOR
echo "Validator queried !"
if [[ -z "${VALIDATOR}" ]]; then
echo "Creating validator ..."
# (echo $KEYPASSWD) | $BIN tx staking create-validator --amount 10000000seda --pubkey $($BIN tendermint show-validator) --from $KEY_NAME --moniker $MONIKER --min-self-delegation 1 --chain-id $CHAIN_ID --commission-rate $COMMISSION_RATE --commission-max-change-rate $COMMISSION_MAX_CHANGE_RATE --commission-max-rate $COMMISSION_MAX_RATE
(echo $KEYPASSWD; echo -y) | $BIN tx staking create-validator \
--amount=100000000000seda\
--pubkey=$($BIN tendermint show-validator) \
--moniker=$MONIKER \
--chain-id=$CHAIN_ID \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--gas="auto" \
--gas-adjustment="1.2" \
--gas-prices="0.0025seda" \
--from=$KEY_NAME \
--min-self-delegation 1 \
--yes
else
echo "Validator already exists"
fi

# Start the node
echo "Starting node ..."
$BIN start
# It creates a Client to the seda-chain network
echo "Connecting to Network ..."
echo $NODE_ADDRESS | $BIN config node $NODE_ADDRESS
echo "Connected to network !"

# Run node
echo "Running Node ..."
#$BIN start

0 comments on commit 3e8238b

Please sign in to comment.