Skip to content

Commit

Permalink
Cosmos-simapp example, support for sdk v0.47.*, upgrade chart to `0…
Browse files Browse the repository at this point in the history
….1.35` (#123)

* initial commit with cosmos-simapp example

* update genesis setup bash script to check for genesis subcommand, add simapp to defaultChain in values.yaml

* add devnet 20, update values

* fix hermes relayer, move faucet transfer tokens to post start hook in validator, fix scripts

* create devnet with 30 validators

* Add resources for build chain test for faster initialization
  • Loading branch information
Anmol1696 committed Jun 18, 2023
1 parent f9d7289 commit 6350ebb
Show file tree
Hide file tree
Showing 16 changed files with 335 additions and 25 deletions.
6 changes: 0 additions & 6 deletions charts/devnet/scripts/create_validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ do
sleep 30
done

echo "Get account into for $VAL_NAME"
VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a)
echo "$VAL_NAME address: $VAL_ADDR"
VAL_ACC=$($CHAIN_BIN query account $VAL_ADDR --chain-id $CHAIN_ID -o json | jq ".value.account_number")
echo "$VAL_NAME account number: $VAL_ACC"

# Run create validator tx command
echo "Running txn for create-validator"
$CHAIN_BIN tx staking create-validator \
Expand Down
1 change: 0 additions & 1 deletion charts/devnet/scripts/setup_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ sed -i -e 's/seeds = ".*"/seeds = ""/g' $CHAIN_DIR/config/config.toml
echo "Update client.toml file"
sed -i -e 's#keyring-backend = "os"#keyring-backend = "test"#g' $CHAIN_DIR/config/client.toml
sed -i -e 's#output = "text"#output = "json"#g' $CHAIN_DIR/config/client.toml
sed -i -e 's#broadcast-mode = "sync"#broadcast-mode = "block"#g' $CHAIN_DIR/config/client.toml
sed -i -e "s#chain-id = \"\"#chain-id = \"$CHAIN_ID\"#g" $CHAIN_DIR/config/client.toml


Expand Down
9 changes: 6 additions & 3 deletions charts/devnet/scripts/setup_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ WASM_PERMISSIONLESS="${WASM_PERMISSIONLESS:=true}"

set -eu

# check if the binary has genesis subcommand or not, if not, set CHAIN_GENESIS_CMD to empty
CHAIN_GENESIS_CMD=$($CHAIN_BIN 2>&1 | grep -q "genesis-related subcommands" && echo "genesis" || echo "")

jq -r ".genesis[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN init $CHAIN_ID --chain-id $CHAIN_ID --recover

# Add genesis keys to the keyring and self delegate initial coins
echo "Adding key...." $(jq -r ".genesis[0].name" $KEYS_CONFIG)
jq -r ".genesis[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $(jq -r ".genesis[0].name" $KEYS_CONFIG) --recover --keyring-backend="test"
$CHAIN_BIN add-genesis-account $($CHAIN_BIN keys show -a $(jq -r .genesis[0].name $KEYS_CONFIG) --keyring-backend="test") $COINS --keyring-backend="test"
$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account $($CHAIN_BIN keys show -a $(jq -r .genesis[0].name $KEYS_CONFIG) --keyring-backend="test") $COINS --keyring-backend="test"

echo "Creating gentx..."
$CHAIN_BIN gentx $(jq -r ".genesis[0].name" $KEYS_CONFIG) 5000000000$DENOM --keyring-backend="test" --chain-id $CHAIN_ID
$CHAIN_BIN $CHAIN_GENESIS_CMD gentx $(jq -r ".genesis[0].name" $KEYS_CONFIG) 5000000000$DENOM --keyring-backend="test" --chain-id $CHAIN_ID

echo "Output of gentx"
cat $CHAIN_DIR/config/gentx/*.json | jq

echo "Running collect-gentxs"
$CHAIN_BIN collect-gentxs
$CHAIN_BIN $CHAIN_GENESIS_CMD collect-gentxs

ls $CHAIN_DIR/config

Expand Down
8 changes: 4 additions & 4 deletions charts/devnet/scripts/transfer_tokens.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ set -eu

function transfer_token() {
status_code=$(curl --header "Content-Type: application/json" \
--request POST --write-out %{http_code} --silent \
--request POST --write-out %{http_code} --silent --output /dev/null \
--data '{"denom":"'"$DENOM"'","address":"'"$ADDRESS"'"}' \
$FAUCET_URL)
return $status_code
echo $status_code
}

echo "Try to send tokens, if failed, wait for 5 seconds and try again"
Expand All @@ -23,7 +23,7 @@ do
echo "Successfully sent tokens"
exit 0
fi
echo "Failed to send tokens. Sleeping for 10 secs. Tries left $max_tries"
echo "Failed to send tokens. Sleeping for 2 secs. Tries left $max_tries"
((max_tries--))
sleep 5
sleep 2
done
10 changes: 5 additions & 5 deletions charts/devnet/templates/chain/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ spec:
$CHAIN_BIN keys add $VAL_NAME --keyring-backend="test"
fi
VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test")
echo "Transfer tokens to address $VAL_ADDR"
bash -e /scripts/transfer_tokens.sh $VAL_ADDR $DENOM http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit
curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json
echo "Genesis file that we got....."
cat $CHAIN_DIR/config/genesis.json
Expand Down Expand Up @@ -182,7 +178,11 @@ spec:
VAL_INDEX=${HOSTNAME##*-}
VAL_NAME=$(jq -r ".validators[$VAL_INDEX].name" /configs/keys.json)
[[ $VAL_NAME == "null" ]] && VAL_NAME="validator-$VAL_INDEX"
echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME"
echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME. Chain bin $CHAIN_BIN"
VAL_ADDR=$($CHAIN_BIN keys show $VAL_NAME -a --keyring-backend="test")
echo "Transfer tokens to address $VAL_ADDR before trying to create validator. Best effort"
bash -e /scripts/transfer_tokens.sh $VAL_ADDR $DENOM http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit || true
$CHAIN_BIN keys list | jq
Expand Down
5 changes: 5 additions & 0 deletions charts/devnet/templates/relayers/hermes/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ spec:
name: relayer-config
- mountPath: /keys
name: keys
- mountPath: /scripts
name: scripts
resources:
{{ toYaml $.Values.resources.init | indent 12 }}
containers:
Expand Down Expand Up @@ -125,6 +127,9 @@ spec:
- name: keys
configMap:
name: keys
- name: scripts
configMap:
name: setup-scripts
---
{{- end }}
{{- end }}
5 changes: 5 additions & 0 deletions charts/devnet/templates/relayers/ts-relayer/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ spec:
name: relayer-config
- mountPath: /keys
name: keys
- mountPath: /scripts
name: scripts
resources:
{{ toYaml $.Values.resources.init | indent 12 }}
containers:
Expand Down Expand Up @@ -134,6 +136,9 @@ spec:
- name: keys
configMap:
name: keys
- name: scripts
configMap:
name: setup-scripts
---
{{- end }}
{{- end }}
12 changes: 11 additions & 1 deletion charts/devnet/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resources:
memory: "100M"

exposer:
image: ghcr.io/cosmology-tech/starship/exposer:20230614-7173db2
image: ghcr.io/cosmology-tech/starship/exposer:20230617-eea58bd
ports:
rest: 8081
resources:
Expand Down Expand Up @@ -108,6 +108,16 @@ defaultChains:
hdPath: m/44'/118'/0'/0/0
coinType: 118
repo: https://github.com/cosmos/gaia
simapp:
image: ghcr.io/cosmology-tech/starship/simapp:v0.47.3
home: /root/.simapp
binary: simd
prefix: cosmos
denom: stake
coins: 100000000000000stake
hdPath: m/44'/118'/0'/0/0
coinType: 118
repo: https://github.com/cosmos/cosmos-sdk/tree/main/simapp
persistencecore:
image: anmol1696/persistencecore:latest
home: /root/.persistenceCore
Expand Down
1 change: 0 additions & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ docker-build-push:

docker-run:
$(DOCKER) run --rm -it --entrypoint /bin/bash $(DOCKER_REPO_NAME)/$(PROCESS):$(DOCKER_TAG_NAME)

70 changes: 70 additions & 0 deletions examples/cosmos-simapp-multi/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
NAME = cosmos-simapp-multi
FILE = configs/local.yaml

HELM_REPO = starship
HELM_CHART = devnet
HELM_VERSION = v0.1.34

###############################################################################
### All commands ###
###############################################################################

.PHONY: setup
setup: setup-deps setup-helm setup-kind

.PHONY: stop
stop: stop-forward delete

.PHONY: clean
clean: stop clean-kind

###############################################################################
### Dependency check ###
###############################################################################

.PHONY: check
setup-deps:
bash $(CURDIR)/scripts/dev-setup.sh

###############################################################################
### Helm Charts ###
###############################################################################

setup-helm:
helm repo add $(HELM_REPO) https://cosmology-tech.github.io/starship/
helm repo update
helm search repo $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION)

install:
helm install -f $(FILE) $(NAME) $(HELM_REPO)/$(HELM_CHART) --version $(HELM_VERSION)

install-base:
helm install -f $(FILE) $(NAME) ../../charts/$(HELM_CHART)

delete:
-helm delete $(NAME)

###############################################################################
### Port forward ###
###############################################################################

.PHONY: port-forward
port-forward:
bash $(CURDIR)/scripts/port-forward.sh --config=$(FILE)

.PHONY: stop-forward
stop-forward:
-pkill -f "port-forward"

###############################################################################
### Local Kind Setup ###
###############################################################################
KIND_CLUSTER=starship

.PHONY: setup-kind
setup-kind:
kind create cluster --name $(KIND_CLUSTER)

.PHONY: clean-kind
clean-kind:
kind delete cluster --name $(KIND_CLUSTER)
17 changes: 17 additions & 0 deletions examples/cosmos-simapp-multi/configs/devnet-20.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
chains:
- name: simapp
type: simapp
numValidators: 20
ports:
rest: 1317
rpc: 26657

registry:
enabled: true
ports:
rest: 8081

explorer:
enabled: true
ports:
rest: 8080
35 changes: 35 additions & 0 deletions examples/cosmos-simapp-multi/configs/devnet-30.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
chains:
- name: simapp
type: simapp
numValidators: 30
ports:
rest: 1317
rpc: 26657

registry:
enabled: true
ports:
rest: 8081

explorer:
enabled: true
ports:
rest: 8080

exposer:
resources:
limits:
cpu: "0.1"
memory: "100M"
requests:
cpu: "0.1"
memory: "100M"

faucet:
resources:
limits:
cpu: "0.4"
memory: "500M"
requests:
cpu: "0.4"
memory: "500M"
24 changes: 24 additions & 0 deletions examples/cosmos-simapp-multi/configs/local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
chains:
- name: simapp
type: simapp
numValidators: 2
ports:
rest: 1317
rpc: 26657
resources:
limits:
cpu: "1"
memory: "2Gi"
requests:
cpu: "1"
memory: "2Gi"

registry:
enabled: true
ports:
rest: 8081

explorer:
enabled: true
ports:
rest: 8080
65 changes: 65 additions & 0 deletions examples/cosmos-simapp-multi/scripts/dev-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

set -euo pipefail

function color() {
local color=$1
shift
local black=30 red=31 green=32 yellow=33 blue=34 magenta=35 cyan=36 white=37
local color_code=${!color:-$green}
printf "\033[%sm%s\033[0m\n" "$color_code" "$*"
}

# Define a function to install a binary on macOS
install_macos() {
case $1 in
kubectl) brew install kubectl ;;
helm) brew install helm ;;
yq) brew install yq ;;
kind) brew install kind ;;
esac
}

# Define a function to install a binary on Linux
install_linux() {
color green "Installing $1 at ~/.local/bin, please add it to PATH"
mkdir -p ~/.local/bin
case $1 in
kubectl) curl -Lks "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" > ~/.local/bin/kubectl && chmod +x ~/.local/bin/kubectl ;;
helm) curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash ;;
yq) curl -Lks "https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64" > ~/.local/bin/yq && chmod +x ~/.local/bin/yq ;;
kind) curl -Lks https://kind.sigs.k8s.io/dl/v0.18.1/kind-linux-amd64 > ~/.local/bin/kind && chmod +x ~/.local/bin/kind ;;
esac
}

# Define a function to install a binary
install_binary() {
if [[ $(uname -s) == "Darwin" ]]; then
install_macos $1
else
install_linux $1
fi
}

# Define a function to check for the presence of a binary
check_binary() {
if ! command -v $1 &> /dev/null
then
echo "$1 is not installed"
install_binary $1
if ! command -v $1 &> /dev/null
then
color red "Installation of $1 failed, exiting..."
color red "Please install $1 manually, then run me again to verify the installation"
exit 1
fi
fi
}

# Check the binaries
check_binary kubectl
check_binary helm
check_binary yq
check_binary kind

color green "All binaries are installed"
Loading

0 comments on commit 6350ebb

Please sign in to comment.