Skip to content

Commit

Permalink
feature: initial setup for ics support for chains (#454)
Browse files Browse the repository at this point in the history
* initial setup for ics chain

* update neutron relayer test

* update some mor

* update client go.mod and sum

* add script for ics setup

* make everything work with neutron node to run

* update neutron

* try and debug hermes creation with ics support

* update config proposal settings

* update unbonding time to 300s from 90s

* update neutron relayer test to run hermes with ics enabled system
  • Loading branch information
Anmol1696 authored Jul 10, 2024
1 parent 609f83e commit 870da6e
Show file tree
Hide file tree
Showing 14 changed files with 325 additions and 12 deletions.
3 changes: 3 additions & 0 deletions starship/charts/devnet/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@ defaultScripts:
ibcConnection:
name: ibc-connection.sh
file: scripts/default/ibc-connection.sh
createICS:
name: create-ics.sh
file: scripts/default/create-ics.sh

defaultFaucet:
cosmjs:
Expand Down
5 changes: 5 additions & 0 deletions starship/charts/devnet/scripts/default/create-genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ echo "Adding key...." $(jq -r ".faucet[0].name" $KEYS_CONFIG)
jq -r ".faucet[0].mnemonic" $KEYS_CONFIG | $CHAIN_BIN keys add $(jq -r ".faucet[0].name" $KEYS_CONFIG) --recover --keyring-backend="test"
$CHAIN_BIN $CHAIN_GENESIS_CMD add-genesis-account $($CHAIN_BIN keys show -a $(jq -r .faucet[0].name $KEYS_CONFIG) --keyring-backend="test") $COINS --keyring-backend="test"

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

if [[ $FAUCET_ENABLED == "false" && $NUM_RELAYERS -gt "-1" ]];
then
## Add relayers keys and delegate tokens
Expand Down
142 changes: 142 additions & 0 deletions starship/charts/devnet/scripts/default/create-ics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/bin/bash

set -euxo pipefail

DENOM="${DENOM:=uatom}"
CHAIN_ID="${CHAIN_ID:=cosmoshub-1}"
CHAIN_BIN="${CHAIN_BIN:=gaiad}"
NODE_URL="${NODE_URL:=http://0.0.0.0:26657}"
KEYS_CONFIG="${KEYS_CONFIG:=configs/keys.json}"

PROPOSAL_FILE="${PROPOSAL_FILE}"
KEY_NAME="ics-setup"
MAX_RETRIES=3
RETRY_INTERVAL=30
SUBMIT_PROPOSAL_CMD=""

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

get_validator_address() {
echo "Getting validator address..."
VALIDATOR_ADDRESS=$($CHAIN_BIN q staking validators --node $NODE_URL --output json | jq -r '.validators[0].operator_address')
echo "Selected validator address: $VALIDATOR_ADDRESS"
}

stake_tokens() {
COINS="10000000$DENOM"
echo "Staking tokens..."
$CHAIN_BIN tx staking delegate $VALIDATOR_ADDRESS $COINS \
--from $KEY_NAME \
--chain-id $CHAIN_ID \
--node $NODE_URL \
--keyring-backend="test" \
--gas auto --gas-adjustment 2 \
--output json \
--yes
sleep 5
}

determine_proposal_command() {
echo "Determining the correct command to submit proposals..."
HELP_OUTPUT=$($CHAIN_BIN tx gov --help)
if echo "$HELP_OUTPUT" | grep -q "submit-legacy-proposal"; then
SUBMIT_PROPOSAL_CMD="submit-legacy-proposal"
else
SUBMIT_PROPOSAL_CMD="submit-proposal"
fi
echo "Using $SUBMIT_PROPOSAL_CMD for submitting proposals."
}

submit_proposal() {
echo "Get all proposals"
PROPOSALS_OUTPUT=$($CHAIN_BIN query gov proposals --output json --node $NODE_URL 2>&1 || true)
if echo "$PROPOSALS_OUTPUT" | grep -q "no proposals found"; then
echo "No existing proposals found. Proceeding to submit a new proposal."
else
echo "Existing proposals: $PROPOSALS_OUTPUT"
fi

echo "Submit gov proposal on chain"
PROPOSAL_TX=$($CHAIN_BIN tx gov $SUBMIT_PROPOSAL_CMD consumer-addition $PROPOSAL_FILE \
--from $KEY_NAME \
--chain-id $CHAIN_ID \
--node $NODE_URL \
--keyring-backend="test" \
--gas auto --gas-adjustment 2 \
--output json \
--yes)
echo $PROPOSAL_TX

# Extract JSON part from the output
TX_HASH=$(echo "$PROPOSAL_TX" | grep -o '{.*}' | jq -r '.txhash')
if [ -n "$TX_HASH" ]; then
echo "Transaction hash: $TX_HASH"
else
echo "Failed to submit proposal. Output was not as expected."
exit 1
fi

sleep 5
}

get_proposal_id() {
echo "Getting proposal ID"
PROPOSAL_QUERY=$(gaiad query tx $TX_HASH --node $NODE_URL --output json)
LOGS=$(echo $PROPOSAL_QUERY | jq -r '.logs')
if [ "$LOGS" != "null" ] && [ "$LOGS" != "[]" ]; then
PROPOSAL_ID=$(echo $PROPOSAL_QUERY | jq -r '.logs[0].events[] | select(.type=="submit_proposal").attributes[] | select(.key=="proposal_id").value')
if [ -n "$PROPOSAL_ID" ]; then
echo "Proposal ID: $PROPOSAL_ID"
return 0
fi
fi
echo "Failed to retrieve proposal ID from transaction logs. Logs might be empty."
exit 1
}

vote_proposal() {
echo "Voting on proposal"
$CHAIN_BIN tx gov vote $PROPOSAL_ID yes \
--from $KEY_NAME \
--chain-id $CHAIN_ID \
--node $NODE_URL \
--keyring-backend="test" \
--gas auto --gas-adjustment 2 \
--output json \
--yes
sleep 5
}

wait_for_proposal_to_pass() {
echo "Waiting for proposal to pass"
for ((i=1; i<=$MAX_RETRIES; i++)); do
STATUS=$($CHAIN_BIN query gov proposal $PROPOSAL_ID --node $NODE_URL --output json | jq -r '.status')
if [ "$STATUS" == "PROPOSAL_STATUS_PASSED" ]; then
echo "Proposal has passed!"
return 0
else
echo "Current status: $STATUS. Attempt $i/$MAX_RETRIES. Waiting..."
sleep $RETRY_INTERVAL
fi
done
echo "Proposal did not pass after $MAX_RETRIES attempts."
exit 1
}

main() {
add_key
get_validator_address
stake_tokens
determine_proposal_command
submit_proposal
get_proposal_id
vote_proposal
wait_for_proposal_to_pass
}

main
4 changes: 2 additions & 2 deletions starship/charts/devnet/scripts/default/update-genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ echo "Update max gas param"
jq -r '.consensus_params.block.max_gas |= "100000000000"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json

echo "Update staking unbonding time and slashing jail time"
jq -r '.app_state.staking.params.unbonding_time |= "90s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.slashing.params.downtime_jail_duration |= "6s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.staking.params.unbonding_time |= "300s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.slashing.params.downtime_jail_duration |= "60s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json

# overrides for older sdk versions, before 0.47
function gov_overrides_sdk_v46() {
Expand Down
4 changes: 2 additions & 2 deletions starship/charts/devnet/scripts/injective/update-genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ echo "Update genesis.json file with updated local params"
sed -i -e "s/\"stake\"/\"$DENOM\"/g" $CHAIN_DIR/config/genesis.json
sed -i "s/\"time_iota_ms\": \".*\"/\"time_iota_ms\": \"$TIME_IOTA_MS\"/" $CHAIN_DIR/config/genesis.json

echo "NOTE: Setting unbolding time to 90s to as to be able to set trusttime on relayers correctly"
jq -r '.app_state.staking.params.unbonding_time |= "90s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
echo "NOTE: Setting unbolding time to 300s to as to be able to set trusttime on relayers correctly"
jq -r '.app_state.staking.params.unbonding_time |= "300s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.slashing.params.downtime_jail_duration |= "6s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.deposit_params.max_deposit_period |= "30s"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
jq -r '.app_state.gov.deposit_params.min_deposit[0].amount |= "10"' $CHAIN_DIR/config/genesis.json > /tmp/genesis.json; mv /tmp/genesis.json $CHAIN_DIR/config/genesis.json
Expand Down
8 changes: 8 additions & 0 deletions starship/charts/devnet/templates/_relayers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ Usage:

{{ $_ := set $relayer "fullname" (printf "%s-%s" $relayer.type $relayer.name) }}

{{- if not (hasKey $relayer "ics")}}
{{ $_ = set $relayer "ics" (dict "enabled" false) }}
{{- end }}

{{- if not (hasKey $relayer "channels")}}
{{- if $relayer.ics.enabled }}
{{ $_ = set $relayer "channels" (list (dict "a-chain" $relayer.ics.consumer "a-connection" "connection-0" "a-port" "consumer" "b-port" "provider" "order" "ordered" "channel-version" 1) (dict "a-chain" $relayer.ics.consumer "a-port" "transfer" "b-port" "transfer" "a-connection" "connection-0")) }}
{{- else }}
{{ $_ = set $relayer "channels" (list (dict "a-chain" (index $relayer.chains 0) "b-chain" (index $relayer.chains 1) "a-port" "transfer" "b-port" "transfer" "new-connection" true)) }}
{{- end }}
{{- end }}

{{ println "@return" }}
{{ mustToJson $relayer }}
Expand Down
37 changes: 37 additions & 0 deletions starship/charts/devnet/templates/chains/cosmos/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,41 @@ data:
{{ toJson $chain.genesis | nindent 4 }}
---
{{- end }}
{{- if $chain.ics.enabled }}
{{ $icsChain := include "devnet.fullchain" (dict "name" $chain.ics.provider "file" $defaultFile "context" $) | fromJson }}
apiVersion: v1
kind: ConfigMap
metadata:
name: consumer-proposal-{{ $chain.hostname }}
data:
proposal.json: |-
{
"title": "Add {{ $chain.name }} consumer chain",
"summary": "Add {{ $chain.name }} consumer chain with id {{ $chain.id }}",
"chain_id": "{{ $chain.id }}",
"initial_height": {
"revision_height": 1,
"revision_number": 1
},
"genesis_hash": "d86d756e10118e66e6805e9cc476949da2e750098fcc7634fd0cc77f57a0b2b0",
"binary_hash": "376cdbd3a222a3d5c730c9637454cd4dd925e2f9e2e0d0f3702fc922928583f1",
"spawn_time": "2023-02-28T20:40:00.000000Z",
"unbonding_period": 294000000000,
"ccv_timeout_period": 259920000000,
"transfer_timeout_period": 18000000000,
"consumer_redistribution_fraction": "0.75",
"blocks_per_distribution_transmission": 10,
"historical_entries": 100,
"distribution_transmission_channel": "",
"top_N": 95,
"validators_power_cap": 0,
"validator_set_cap": 0,
"allowlist": [],
"denylist": [],
"deposit": "10000{{ $icsChain.denom }}"
}
---
{{- end }}
{{- end }}
{{- end }}
---
Expand All @@ -52,4 +87,6 @@ data:
{{- $.Files.Get "scripts/default/transfer-tokens.sh" | nindent 4 }}
ibc-connection.sh: |-
{{- $.Files.Get "scripts/default/ibc-connection.sh" | nindent 4 }}
create-ics.sh: |-
{{- $.Files.Get "scripts/default/create-ics.sh" | nindent 4 }}
---
68 changes: 68 additions & 0 deletions starship/charts/devnet/templates/chains/cosmos/genesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ spec:
echo "Create node id json file"
NODE_ID=$($CHAIN_BIN tendermint show-node-id)
echo '{"node_id":"'$NODE_ID'"}' > $CHAIN_DIR/config/node_id.json
echo "Create consensus key json file"
$CHAIN_BIN tendermint show-validator > $CHAIN_DIR/config/consensus_key.json
cat $CHAIN_DIR/config/consensus_key.json
resources: {{- include "devnet.node.resources" ( dict "node" $chain "context" $ ) | trim | nindent 12 }}
volumeMounts:
- mountPath: {{ $chain.home }}
Expand Down Expand Up @@ -172,6 +176,65 @@ spec:
- mountPath: /faucet
name: faucet
{{- end }}
{{- if $chain.ics.enabled }}
{{ $waitParams := dict "chain" (list $chain.ics.provider) "port" $.Values.exposer.ports.rest "context" $ }}
{{- include "devnet.init.wait" $waitParams | indent 8 }}
{{ $icsChain := include "devnet.fullchain" (dict "name" $chain.ics.provider "file" $defaultFile "context" $) | fromJson }}
- name: init-ics
image: {{ $icsChain.image }}
imagePullPolicy: {{ $.Values.images.imagePullPolicy }}
env:
{{- include "devnet.defaultEvnVars" $chain | indent 12 }}
{{- include "devnet.evnVars" $chain | indent 12 }}
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: KEYS_CONFIG
value: /configs/keys.json
command:
- bash
- "-c"
- |
export
echo "Fetching priv keys from provider exposer"
curl -s http://{{ $icsChain.hostname }}-genesis.$NAMESPACE.svc.cluster.local:8081/priv_keys | jq > $CHAIN_DIR/config/provider_priv_validator_key.json
cat $CHAIN_DIR/config/provider_priv_validator_key.json
echo "Replace provider priv validator key with provider keys"
mv $CHAIN_DIR/config/priv_validator_key.json $CHAIN_DIR/config/previous_priv_validator_key.json
mv $CHAIN_DIR/config/provider_priv_validator_key.json $CHAIN_DIR/config/priv_validator_key.json
echo "Create consumer addition proposal"
DENOM={{ $icsChain.denom }} \
CHAIN_ID={{ $icsChain.id }} \
CHAIN_BIN={{ $icsChain.binary }} \
NODE_URL=http://{{ $icsChain.hostname }}-genesis.$NAMESPACE.svc.cluster.local:26657 \
PROPOSAL_FILE=/proposal/proposal.json \
bash -e /scripts/create-ics.sh
echo "create ccv state file"
{{ $icsChain.binary }} query provider consumer-genesis {{ $chain.id }} \
--node http://{{ $icsChain.hostname }}-genesis.$NAMESPACE.svc.cluster.local:26657 \
-o json > $CHAIN_DIR/config/ccv-state.json
cat $CHAIN_DIR/config/ccv-state.json | jq
echo "Update genesis file with ccv state"
jq -s '.[0].app_state.ccvconsumer = .[1] | .[0]' $CHAIN_DIR/config/genesis.json $CHAIN_DIR/config/ccv-state.json > $CHAIN_DIR/config/genesis-ccv.json
mv $CHAIN_DIR/config/genesis.json $CHAIN_DIR/config/genesis-no-ccv.json
mv $CHAIN_DIR/config/genesis-ccv.json $CHAIN_DIR/config/genesis.json
resources: {{- include "devnet.node.resources" ( dict "node" $chain "context" $ ) | trim | nindent 12 }}
volumeMounts:
- mountPath: /proposal
name: proposal
- mountPath: {{ $chain.home }}
name: node
- mountPath: /configs
name: addresses
- mountPath: /scripts
name: scripts
{{- end }}
containers:
- name: validator
image: {{ $chain.image }}
Expand Down Expand Up @@ -411,6 +474,11 @@ spec:
- name: faucet
emptyDir: { }
{{- end }}
{{- if $chain.ics.enabled }}
- name: proposal
configMap:
name: consumer-proposal-{{ $chain.hostname }}
{{- end }}
---
{{- end }}
{{- end }}
17 changes: 15 additions & 2 deletions starship/charts/devnet/templates/relayers/hermes/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,26 @@ spec:
"{{ $fullchain.faucet.enabled }}" || true
{{- end }}
{{- if $relayer.ics.enabled }}
echo "Creating IBC connection for {{ $relayer.ics.consumer }}..."
hermes create connection --a-chain {{ $relayer.ics.consumer }} --a-client 07-tendermint-0 --b-client 07-tendermint-0
{{- end }}
{{- range $i, $channel := $relayer.channels }}
hermes create channel \
{{- if (get $channel "new-connection" | default false) }}
--new-client-connection --yes \
--b-chain {{ get $channel "b-chain" }} \
{{- else if (hasKey $channel "a-connection") }}
--a-connection {{ get $channel "a-connection" }} \
{{- end }}
{{- if hasKey $channel "channel-version" }}
--channel-version {{ get $channel "channel-version" }} \
{{- end }}
{{- if hasKey $channel "order" }}
--order {{ get $channel "order" }} \
{{- end }}
--a-chain {{ get $channel "a-chain" }} \
--b-chain {{ get $channel "b-chain" }} \
--a-port {{ get $channel "a-port" }} \
--b-port {{ get $channel "b-port" }}
{{- end }}
Expand All @@ -157,7 +170,7 @@ spec:
- |
RLY_INDEX=${HOSTNAME##*-}
echo "Relayer Index: $RLY_INDEX"
sleep infinity
hermes start
resources: {{- include "devnet.node.resources" ( dict "node" $relayer "context" $ ) | trim | nindent 12 }}
securityContext:
Expand Down
Loading

0 comments on commit 870da6e

Please sign in to comment.