Skip to content

Commit

Permalink
update create-validator script to handle cosmos-sdk version (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 committed Aug 8, 2023
1 parent 7048c36 commit 48170c2
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 22 deletions.
91 changes: 74 additions & 17 deletions charts/devnet/scripts/create_validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,77 @@ do
sleep 30
done

# Run create validator tx command
echo "Running txn for create-validator"
$CHAIN_BIN tx staking create-validator \
--pubkey=$($CHAIN_BIN tendermint show-validator) \
--moniker $VAL_NAME \
--amount 5000000000$DENOM \
--chain-id $CHAIN_ID \
--from $VAL_NAME \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--min-self-delegation="1000000" \
--fees 100000$DENOM \
--gas="auto" \
--gas-adjustment 1.5 --yes > /validator.log

cat /validator.log | jq
# Function to compare version numbers
version_compare() {
version1="$1"
version2="$2"
if [[ "$(printf '%s\n' "$version1" "$version2" | sort -V | head -n 1)" == "$version1" ]]; then
return 1 # version1 is greater
else
return 0 # version2 is greater or equal
fi
}

# Check if cosmos_sdk_version is greater than a specified version
is_greater() {
version_compare "$1" "$2"
return $?
}

function cosmos-sdk-version-v50() {
# Content for the validator.json file
json_content='{
"pubkey": '$($CHAIN_BIN tendermint show-validator)',
"amount": "5000000000'$DENOM'",
"moniker": "'$VAL_NAME'",
"commission-rate": "0.1",
"commission-max-rate": "0.2",
"commission-max-change-rate": "0.01",
"min-self-delegation": "1000000"
}'
echo "$json_content" > /validator.json
cat /validator.json

# Run create validator tx command
echo "Running txn for create-validator"
$CHAIN_BIN tx staking create-validator /validator.json \
--chain-id $CHAIN_ID \
--from $VAL_NAME \
--fees 100000$DENOM \
--gas="auto" \
--gas-adjustment 1.5 --yes > /validator.log

cat /validator.log | jq
}

function cosmos-sdk-version-default() {
# Run create validator tx command
echo "Running txn for create-validator"
$CHAIN_BIN tx staking create-validator \
--pubkey=$($CHAIN_BIN tendermint show-validator) \
--moniker $VAL_NAME \
--amount 5000000000$DENOM \
--chain-id $CHAIN_ID \
--from $VAL_NAME \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--min-self-delegation="1000000" \
--fees 100000$DENOM \
--gas="auto" \
--gas-adjustment 1.5 --yes > /validator.log

cat /validator.log | jq
}

# Fetch the cosmos-sdk version to be able to perform the create-validator tx
cosmos_sdk_version=$($CHAIN_BIN version --long | sed -n 's/cosmos_sdk_version: \(.*\)/\1/p')
echo "cosmos_sdk_version: $cosmos_sdk_version"

if is_greater "$cosmos_sdk_version" "v0.50.0"; then
echo "cosmos_sdk_version is greater than v0.50.0, running create-validator tx with new format"
cosmos-sdk-version-v50
else
echo "cosmos_sdk_version is less than v0.50.0, running create-validator tx with old format"
cosmos-sdk-version-default
fi
14 changes: 9 additions & 5 deletions examples/cosmos-simapp-multi/configs/local.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
chains:
- name: simapp
type: simapp
image: ghcr.io/cosmology-tech/starship/simapp:v0.47.3
image: ghcr.io/cosmos/simapp:latest
numValidators: 2
ports:
rest: 1317
rpc: 26657
grpc: 9091
faucet: 8001
faucet:
image: ghcr.io/cosmology-tech/starship/cosmjs-faucet:v0.31.0-alpha.2
resources:
cpu: "1"
memory: "2Gi"
# use v0.31.0-alpha.2 cosmjs-faucet for compatibility with simapp v0.47.3
image: ghcr.io/cosmology-tech/starship/cosmjs-faucet:v0.31.0
concurrency: 4

exposer:
image: ghcr.io/cosmology-tech/starship/exposer:20230808-2333929

registry:
enabled: true
Expand Down

0 comments on commit 48170c2

Please sign in to comment.