Skip to content

Commit

Permalink
feature: faucet-less setup (#262)
Browse files Browse the repository at this point in the history
* add feature to handle manual key addition as part of gentx if faucet is disabled

* fix num of keys test

* update exposer keys test

* add more delay, update make command to not cache

* add random address per chain instead of getting address from on chain addresses

* add custom addresses as osmosis addrs

* add docs around what happens when faucet is disabled
  • Loading branch information
Anmol1696 authored Oct 9, 2023
1 parent 010b357 commit 3a4a450
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 232 deletions.
175 changes: 0 additions & 175 deletions charts/devnet/configs/all_keys.json

This file was deleted.

26 changes: 3 additions & 23 deletions charts/devnet/configs/keys.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
{
"genesis": [
{
"name": "val0",
"name": "genesis",
"type": "local",
"mnemonic": "razor dog gown public private couple ecology paper flee connect local robot diamond stay rude join sound win ribbon soup kidney glass robot vehicle"
}
],
"validators": [
{
"name": "val1",
"name": "validator",
"type": "local",
"mnemonic": "issue have volume expire shoe year finish poem alien urban license undo rural endless food host opera fix forum crack wide example firm learn"
},
{
"name": "val2",
"type": "local",
"mnemonic": "broccoli robot upon blush rabbit squeeze fruit still lady antique detect can spice clay magic monster zebra solution dry salute stay wet arena matrix"
},
{
"name": "val3",
"type": "local",
"mnemonic": "tornado modify spring arm title double bulk other recall decide table fun caught buyer bring once knife sphere arctic text zoo swim visual patient"
},
{
"name": "val4",
"type": "local",
"mnemonic": "warm marine rent lift siege tool artwork home curious film blade trophy flush angry exact athlete edge combine weasel hour marriage grocery lake famous"
}
],
"keys": [
Expand All @@ -47,14 +32,9 @@
],
"relayers": [
{
"name": "rly1",
"name": "relayer",
"type": "local",
"mnemonic": "pen quit web pill hunt hobby tonight base wine black era cereal veteran trouble december method diet orbit copper nephew into badge olympic repair"
},
{
"name": "rly2",
"type": "local",
"mnemonic": "rally area annual range egg solid paper kick cabbage relax grow ginger axis tone penalty swing marine endless vendor dinner guilt echo stable system"
}
]
}
26 changes: 20 additions & 6 deletions charts/devnet/scripts/create-genesis.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/bin/bash

set -eux

DENOM="${DENOM:=uosmo}"
COINS="${COINS:=100000000000000000uosmo}"
CHAIN_ID="${CHAIN_ID:=osmosis}"
CHAIN_BIN="${CHAIN_BIN:=osmosisd}"
CHAIN_DIR="${CHAIN_DIR:=$HOME/.osmosisd}"
KEYS_CONFIG="${KEYS_CONFIG:=configs/keys.json}"

set -eux
FAUCET_ENABLED="${FAUCET_ENABLED:=true}"
NUM_VALIDATORS="${NUM_VALIDATORS:=1}"

# Args and vars specific to chains
ARGS_ADD_GENESIS_ACCOUNT=""
Expand All @@ -26,11 +29,22 @@ 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 $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" $ARGS_ADD_GENESIS_ACCOUNT

# todo: adding relayer key is a temporary fix for not having faucet
# Add relayer key to the keyring and self delegate initial coins
echo "Adding key...." $(jq -r ".relayers[0].name" $KEYS_CONFIG)
jq -r ".relayers[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $(jq -r ".relayers[0].name" $KEYS_CONFIG) --recover --keyring-backend="test"
$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account $($CHAIN_BIN keys show -a $(jq -r .relayers[0].name $KEYS_CONFIG) --keyring-backend="test") $COINS --keyring-backend="test" $ARGS_ADD_GENESIS_ACCOUNT
## if facuet not enabled then add validator and relayer with index as keys and into gentx
if [[ $FAUCET_ENABLED == "false" && $NUM_VALIDATORS -gt "1" ]];
then
## Add validators key and delegate tokens
for i in $(seq 0 $NUM_VALIDATORS);
do
VAL_KEY_NAME="$(jq -r '.validators[0].name' $KEYS_CONFIG)-$i"
echo "Adding validator key.... $VAL_KEY_NAME"
jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_KEY_NAME --index $i --recover --keyring-backend="test"
$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account $($CHAIN_BIN keys show -a $VAL_KEY_NAME --keyring-backend="test") $COINS --keyring-backend="test" $ARGS_ADD_GENESIS_ACCOUNT
done
## Add relayer key and delegate tokens
echo "Adding key...." $(jq -r ".relayers[0].name" $KEYS_CONFIG)
jq -r ".relayers[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $(jq -r ".relayers[0].name" $KEYS_CONFIG) --recover --keyring-backend="test"
$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account $($CHAIN_BIN keys show -a $(jq -r .relayers[0].name $KEYS_CONFIG) --keyring-backend="test") $COINS --keyring-backend="test" $ARGS_ADD_GENESIS_ACCOUNT
fi

echo "Creating gentx..."
COIN=$(echo $COINS | cut -d ',' -f1)
Expand Down
7 changes: 7 additions & 0 deletions charts/devnet/scripts/transfer-tokens.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ADDRESS="$1"
DENOM="$2"
FAUCET_URL="$3"
FAUCET_ENABLED="$4"

set -eux

Expand All @@ -14,6 +15,12 @@ function transfer_token() {
echo $status_code
}

if [[ $FAUCET_ENABLED == "false" ]];
then
echo "Faucet not enabled... skipping transfer token from faucet"
exit 0
fi

echo "Try to send tokens, if failed, wait for 5 seconds and try again"
max_tries=5
while [[ max_tries -gt 0 ]]
Expand Down
6 changes: 6 additions & 0 deletions charts/devnet/templates/chains/cosmos/genesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ spec:
{{- include "devnet.timeoutVars" $.Values | indent 12 }}
- name: KEYS_CONFIG
value: /configs/keys.json
- name: FAUCET_ENABLED
value: "{{ $chain.faucet.enabled }}"
- name: NUM_VALIDATORS
value: "{{ $chain.numValidators }}"
command:
- bash
- "-c"
Expand Down Expand Up @@ -169,6 +173,8 @@ spec:
env:
{{- include "devnet.defaultEvnVars" $chain | indent 12 }}
{{- include "devnet.evnVars" $chain | indent 12 }}
- name: FAUCET_ENABLED
value: "{{ $chain.faucet.enabled }}"
command:
- bash
- "-c"
Expand Down
29 changes: 14 additions & 15 deletions charts/devnet/templates/chains/cosmos/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ spec:
{{- include "devnet.genesisVars" $dataExposer | indent 12 }}
- name: KEYS_CONFIG
value: /configs/keys.json
- name: FAUCET_ENABLED
value: "{{ $chain.faucet.enabled }}"
- name: METRICS
value: "{{ $chain.metrics }}"
command:
Expand All @@ -103,20 +105,12 @@ spec:
exit 0
fi
RECOVER=true
VAL_NAME=$(jq -r ".validators[$VAL_INDEX].name" $KEYS_CONFIG)
[[ $VAL_NAME == "null" ]] && VAL_NAME="validator-$VAL_INDEX" && RECOVER=false
VAL_NAME=$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX
echo "Validator Index: $VAL_INDEX, Key name: $VAL_NAME"
if [[ $RECOVER == "true" ]]; then
echo "Recover validator $VAL_NAME"
jq -r ".validators[$VAL_INDEX].mnemonic" $KEYS_CONFIG | $CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID --recover
jq -r ".validators[$VAL_INDEX].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --recover --keyring-backend="test"
else
echo "Create validator $VAL_NAME"
$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID
$CHAIN_BIN keys add $VAL_NAME --keyring-backend="test"
fi
echo "Recover validator $VAL_NAME"
$CHAIN_BIN init $VAL_NAME --chain-id $CHAIN_ID
jq -r ".validators[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $VAL_NAME --index $VAL_INDEX --recover --keyring-backend="test"
curl http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:$GENESIS_PORT/genesis -o $CHAIN_DIR/config/genesis.json
echo "Genesis file that we got....."
Expand Down Expand Up @@ -183,6 +177,8 @@ spec:
{{- include "devnet.defaultEvnVars" $chain | indent 12 }}
{{- include "devnet.evnVars" $chain | indent 12 }}
{{- include "devnet.genesisVars" $dataExposer | indent 12}}
- name: KEYS_CONFIG
value: /configs/keys.json
command:
- bash
- "-c"
Expand All @@ -203,13 +199,16 @@ spec:
- "-e"
- |
VAL_INDEX=${HOSTNAME##*-}
VAL_NAME=$(jq -r ".validators[$VAL_INDEX].name" /configs/keys.json)
[[ $VAL_NAME == "null" ]] && VAL_NAME="validator-$VAL_INDEX"
VAL_NAME="$(jq -r ".validators[0].name" $KEYS_CONFIG)-$VAL_INDEX"
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
bash -e /scripts/transfer-tokens.sh \
$VAL_ADDR \
$DENOM \
http://$GENESIS_HOST.$NAMESPACE.svc.cluster.local:8000/credit \
"{{ $chain.faucet.enabled }}" || true
$CHAIN_BIN keys list --keyring-backend test | jq
Expand Down
7 changes: 6 additions & 1 deletion charts/devnet/templates/relayers/go-relayer/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
{{- range $i, $chain := $relayer.chains }}
{{ $fullchain := include "devnet.fullchain" (dict "name" $chain "file" $defaultFile "context" $) | fromJson }}
echo "Adding {{ $fullchain.name }} chain"
rly chains add --file "/configs/{{ $fullchain.name }}.json" {{ $fullchain.name }}
Expand All @@ -70,7 +71,11 @@ spec:
DENOM="{{ $fullchain.denom }}"
RLY_ADDR=$(rly address "{{ $fullchain.name }}" | awk 'END{print}')
echo "Transfer tokens to address $RLY_ADDR on {{ $fullchain.name }} chain with denom $DENOM"
bash -e /scripts/transfer-tokens.sh $RLY_ADDR $DENOM http://{{ include "devnet.chain.name" $fullchain.name }}-genesis.$NAMESPACE.svc.cluster.local:8000/credit
bash -e /scripts/transfer-tokens.sh \
$RLY_ADDR \
$DENOM \
http://{{- include "devnet.chain.name" $fullchain.name }}-genesis.$NAMESPACE.svc.cluster.local:8000/credit \
"{{ $fullchain.faucet.enabled }}"
{{- end }}
PATHEND="{{ index $relayer.chains 0 }}-{{ index $relayer.chains 1 }}"
Expand Down
Loading

0 comments on commit 3a4a450

Please sign in to comment.