Skip to content

Commit

Permalink
ENG-375 akash-node: introduce state-sync feature (#59)
Browse files Browse the repository at this point in the history
* ENG-375 akash-node: move start script to standalone file

fixes #18

* ENG-375 akash-node: avoid unnecessary config overwrite

fixes #19

* ENG-375 akash-node: remove nonsense

AKASH_P2P_PRIVATE_PEER_IDS is comma separated list of peer IDs to keep private (will not be gossiped to othe
r peers) which does not make any sense as we aren't using private peers
nor does it make sense to nmap through whole list of (25 as of now)
peers to just pick a single working one. It just slows down the
bootstrap.

and we already use akash_node.peers, which go to AKASH_P2P_PERSISTENT_PEERS and should be more than enough.

* ENG-375 akash-node: validate-genesis does not do anything

and akash validate-genesis fails after 0.16.3 upgrade
https://github.com/ovrclk/akash/issues/1565

* ENG-375 akash-node: introduce state-sync feature

* ENG-375 akash-provider: explicitly set bid deposit to 5 AKT

it looks like that when running a provider against state-synced RPC node
it would default to 50 AKT for bid deposit. Despite that state-synced
RPC node returns 5 AKT for "akash query params subspace market
BidMinDeposit" command.
  • Loading branch information
arno01 authored Jun 8, 2022
1 parent 21b7d3e commit 13b081e
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 42 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Experimental: It is recommended to run Akash nodes outside of Kubernetes. For ex

Be aware that there is no persistent storage on this Helm chart so a pod restart will lose the blockchain data and the entire snapshot will need to be downloaded again (approx. 30GB).

Or you can pass `--set state_sync.enabled=true` flag to enable state-sync which can bootstrap the Akash Node in under 10 minutes!

This chart will create an Akash node that downloads a snapshot into the pod, extracts it and then starts. This may take some time depending on your internet connection.

```
Expand Down
2 changes: 1 addition & 1 deletion charts/akash-node/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.127.0
version: 0.130.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
68 changes: 68 additions & 0 deletions charts/akash-node/scripts/node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
set -x

if [ ! -d "$AKASH_HOME/data" ]
then
/bin/akash init --chain-id "$AKASH_CHAIN_ID" "$AKASH_MONIKER"
fi

apt update && apt -y --no-install-recommends install ca-certificates curl jq > /dev/null 2>&1
curl -s "$AKASH_NET/genesis.json" > "$AKASH_HOME/config/genesis.json"

mkdir -p $AKASH_HOME/data
cd $AKASH_HOME/data

if [ "$AKASH_STATESYNC_ENABLE" == true ]; then
echo "state-sync is enabled, figure the right trust height & derive its hash"

SNAP_RPC1="{{ .Values.state_sync.rpc1 }}"
SNAP_RPC2="{{ .Values.state_sync.rpc2 }}"

echo "update AKASH_P2P_PERSISTENT_PEERS with the state-sync hosts: $SNAP_RPC1, $SNAP_RPC2 ..."
SNAP_RPC1_ID=$(curl -s ${SNAP_RPC1}/status | jq -r '.result.node_info.id')
SNAP_RPC2_ID=$(curl -s ${SNAP_RPC2}/status | jq -r '.result.node_info.id')

SNAP_RPC1_ADDR=$(curl -s ${SNAP_RPC1}/status | jq -r '.result.node_info.other.rpc_address')
SNAP_RPC2_ADDR=$(curl -s ${SNAP_RPC2}/status | jq -r '.result.node_info.other.rpc_address')

SNAP_RPC1_PORT=${SNAP_RPC1_ADDR##*:}
SNAP_RPC2_PORT=${SNAP_RPC2_ADDR##*:}

T=${SNAP_RPC1#*//}
SNAP_RPC1_HOST=${T%:*}

T=${SNAP_RPC2#*//}
SNAP_RPC2_HOST=${T%:*}

if [ $SNAP_RPC1_ID == $SNAP_RPC2_ID ]; then
T="${SNAP_RPC1_ID}@${SNAP_RPC1_HOST}:${SNAP_RPC1_PORT}"
else
T="${SNAP_RPC1_ID}@${SNAP_RPC1_HOST}:${SNAP_RPC1_PORT},${SNAP_RPC2_ID}@${SNAP_RPC2_HOST}:${SNAP_RPC2_PORT}"
fi
AKASH_P2P_PERSISTENT_PEERS="$AKASH_P2P_PERSISTENT_PEERS,$T"
export AKASH_P2P_PERSISTENT_PEERS
echo "AKASH_P2P_PERSISTENT_PEERS: $AKASH_P2P_PERSISTENT_PEERS"

LATEST_HEIGHT=$(curl -s $SNAP_RPC1/block | jq -r .result.block.header.height)
HEIGHT_OFFSET={{ .Values.state_sync.height_offset }}
BLOCK_HEIGHT=$((LATEST_HEIGHT - HEIGHT_OFFSET))
TRUST_HASH=$(curl -s "$SNAP_RPC1/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

echo "TRUST HEIGHT: $BLOCK_HEIGHT"
echo "TRUST HASH: $TRUST_HASH"

export AKASH_STATESYNC_TRUST_HEIGHT=$BLOCK_HEIGHT
export AKASH_STATESYNC_TRUST_HASH=$TRUST_HASH

else

apt -y --no-install-recommends install aria2 > /dev/null 2>&1
SNAPSHOT_URL=$(curl https://cosmos-snapshots.s3.filebase.com/akash/pruned/snapshot.json | jq -r .latest)
echo "Using latest blockchain snapshot, $SNAPSHOT_URL"
aria2c --out=snapshot.tar.gz --summary-interval 15 --check-certificate=false --max-tries=99 --retry-wait=5 --always-resume=true --max-file-not-found=99 --conditional-get=true -s 16 -x 16 -k 1M -j 1 $SNAPSHOT_URL
tar -zxvf snapshot.tar.gz
rm -f snapshot.tar.gz
fi

/bin/akash start
if $AKASH_DEBUG == "true"; then sleep 5000; fi
41 changes: 1 addition & 40 deletions charts/akash-node/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,5 @@ metadata:
{{- include "akash-node.labels" . | nindent 4 }}
data:
node.sh: |
#!/bin/bash
set -x
if [ ! -d "$AKASH_HOME/data" ]
then
/bin/akash init --chain-id "$AKASH_CHAIN_ID" "$AKASH_MONIKER"
sed -i -E 's#^(minimum-gas-prices[[:space:]]+=[[:space:]]+)""$#\1"0.025uakt"#' $AKASH_HOME/config/app.toml
fi
apt update && apt -y install curl > /dev/null 2>&1
curl -s "$AKASH_NET/genesis.json" > "$AKASH_HOME/config/genesis.json"
if [[ $AKASH_NET == "https://raw.githubusercontent.com/ovrclk/net/master/mainnet" ]]
then
apt -y install jq aria2 wget nmap > /dev/null 2>&1
rm -rf $AKASH_HOME/data ; mkdir -p $AKASH_HOME/data ; cd $AKASH_HOME/data
SNAPSHOT_URL=$(curl https://cosmos-snapshots.s3.filebase.com/akash/pruned/snapshot.json | jq -r .latest)
echo "Using latest blockchain snapshot, $SNAPSHOT_URL" ; aria2c --out=snapshot.tar.gz --summary-interval 15 --check-certificate=false --max-tries=99 --retry-wait=5 --always-resume=true --max-file-not-found=99 --conditional-get=true -s 16 -x 16 -k 1M -j 1 $SNAPSHOT_URL
tar -zxvf snapshot.tar.gz
rm -f snapshot.tar.gz
echo "Get working peers to sync an RPC node with!"
wget https://raw.githubusercontent.com/ovrclk/net/master/mainnet/peer-nodes.txt
ip=$(cat peer-nodes.txt)
for i in $ip; do
original=$i ; i=$(echo $i | cut -d@ -f2-)
solo_ip=$(echo $i | cut -f1 -d":")
port=$(echo $i | cut -d":" -f2-)
nmap -p $port $solo_ip | grep "down" &> /dev/null
if [ $? == 0 ]; then
echo "$solo_ip is unreachable"
else
echo "$original" >> good-nodes.txt
fi
done
export AKASH_P2P_PRIVATE_PEER_IDS=$(cat good-nodes.txt | shuf -n 1)
fi
/bin/akash validate-genesis
/bin/akash start
if $AKASH_DEBUG == "true"; then sleep 5000; fi
{{ tpl (.Files.Get "scripts/node.sh") . | indent 4 }}
{{- end }}
8 changes: 8 additions & 0 deletions charts/akash-node/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ spec:
value: "true"
- name: AKASH_DEBUG
value: "{{ $.Values.debug }}"
- name: AKASH_MINIMUM_GAS_PRICES
value: "0.025uakt"
{{- if .Values.state_sync.enabled }}
- name: AKASH_STATESYNC_ENABLE
value: "true"
- name: AKASH_STATESYNC_RPC_SERVERS
value: "{{ .Values.state_sync.rpc1 }},{{ .Values.state_sync.rpc2 }}"
{{- end }}
ports:
- containerPort: 1317
name: akashd-api
Expand Down
9 changes: 9 additions & 0 deletions charts/akash-node/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ akash_node:
net: https://raw.githubusercontent.com/ovrclk/net/master/mainnet
peers: [email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656

# If your node gets connection troubles to Polkachu,
# make sure to get through the trouble-shooting section at
# https://www.polkachu.com/state_sync/akash
state_sync:
enabled: false
rpc1: "https://akash-rpc.polkachu.com:443"
rpc2: "https://akash-rpc.polkachu.com:443"
height_offset: 2000

persistent_storage:
enabled: false
capacity: 100Gi
Expand Down
2 changes: 1 addition & 1 deletion charts/akash-provider/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type: application
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)

version: 0.164.0
version: 0.165.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
3 changes: 3 additions & 0 deletions charts/akash-provider/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ spec:
- name: AKASH_MINIMUM_BALANCE
value: "{{ .Values.minimumbalance }}"

- name: AKASH_BID_DEPOSIT
value: "5000000uakt"

ports:
- name: api
containerPort: 8443
Expand Down

0 comments on commit 13b081e

Please sign in to comment.