From f88ee98bc3b34babe01d2d60e055068293eaccd3 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Tue, 8 Aug 2023 19:57:54 +0530 Subject: [PATCH] update create-validator script to handle cosmos-sdk version --- charts/devnet/scripts/create_validator.sh | 91 +++++++++++++++---- .../cosmos-simapp-multi/configs/local.yaml | 14 ++- 2 files changed, 83 insertions(+), 22 deletions(-) diff --git a/charts/devnet/scripts/create_validator.sh b/charts/devnet/scripts/create_validator.sh index 7efa8d25..1a5dd982 100644 --- a/charts/devnet/scripts/create_validator.sh +++ b/charts/devnet/scripts/create_validator.sh @@ -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 diff --git a/examples/cosmos-simapp-multi/configs/local.yaml b/examples/cosmos-simapp-multi/configs/local.yaml index 75720f99..d54c8d96 100644 --- a/examples/cosmos-simapp-multi/configs/local.yaml +++ b/examples/cosmos-simapp-multi/configs/local.yaml @@ -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