Skip to content

Commit 798573a

Browse files
authored
52 snapshot versioning data versioning (#54)
close #52
1 parent da6cc38 commit 798573a

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

load_balancer/run.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ then
99
exit
1010
fi
1111

12+
13+
# functions
14+
find_current_data_version () {
15+
ver=0
16+
ver=$(curl -s "https://snapshot.notional.ventures/$chain_name/chain.json" |jq -r '.data_version // 0')
17+
echo $ver
18+
}
19+
20+
21+
1222
cd $HOME
1323

1424
pacman -Syu --noconfirm
15-
pacman -S --noconfirm base-devel dnsutils python caddy logrotate screen
25+
pacman -S --noconfirm base-devel jq dnsutils python caddy logrotate screen
1626

1727
echo "read chain info:"
1828
eval "$(curl -s https://raw.githubusercontent.com/notional-labs/cosmosia/main/data/chain_registry.ini |awk -v TARGET=$chain_name -F ' = ' '
@@ -31,25 +41,30 @@ echo "json_rpc=$json_rpc"
3141
########################################################################################################################
3242
# dynamic upstream
3343

44+
# get the data version from chain.json, service name is rpc_$chain_name_$version
45+
data_version=$(find_current_data_version)
46+
rpc_service_name="rpc_${chain_name}_${data_version}"
47+
echo "rpc_service_name=$rpc_service_name"
48+
3449
CONFIG_FILE="/etc/caddy/Caddyfile"
3550
TMP_CONFIG_FILE="/etc/caddy/Caddyfile.tmp"
3651

3752
# functions
3853
generate_new_upstream_config () {
3954
# use dig to figure out IPs of service
40-
new_ips=$(dig +short "tasks.$chain_name" |sort)
55+
new_ips=$(dig +short "tasks.$rpc_service_name" |sort)
4156

4257
rpc_str=""
4358
api_str=""
4459
ws_str=""
4560
grpc_str=""
4661
jsonrpc_str=""
4762
if [[ -z "$new_ips" ]]; then
48-
rpc_str="to http://$chain_name"
49-
api_str="to http://$chain_name:1317"
50-
ws_str="to http://$chain_name"
51-
grpc_str="to http://$chain_name:9090"
52-
jsonrpc_str="to http://$chain_name:8545"
63+
rpc_str="to http://$rpc_service_name"
64+
api_str="to http://$rpc_service_name:1317"
65+
ws_str="to http://$rpc_service_name"
66+
grpc_str="to http://$rpc_service_name:9090"
67+
jsonrpc_str="to http://$rpc_service_name:8545"
5368
else
5469
while read -r ip_addr || [[ -n $ip_addr ]]; do
5570
if [[ -z "$rpc_str" ]]; then

rpc/docker_service_create.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,29 @@ then
99
exit
1010
fi
1111

12+
git_branch=$(git symbolic-ref --short -q HEAD)
1213

14+
# functions
15+
find_current_data_version () {
16+
ver=0
17+
ver=$(curl -s "https://snapshot.notional.ventures/$chain_name/chain.json" |jq -r '.data_version // 0')
18+
echo $ver
19+
}
1320

14-
git_branch=$(git symbolic-ref --short -q HEAD)
1521

22+
# get the data version from chain.json, service name is rpc_$chain_name_$version
23+
data_version=$(find_current_data_version)
24+
25+
rpc_service_name="rpc_${chain_name}_${data_version}"
1626

1727
# delete existing service
18-
docker service rm $chain_name
28+
docker service rm $rpc_service_name
1929

2030
docker service create \
21-
--name $chain_name \
31+
--name $rpc_service_name \
2232
--replicas 1 \
2333
--network cosmosia \
34+
--label 'cosmosia.service=rpc' \
2435
--endpoint-mode dnsrr \
2536
--restart-condition any \
2637
archlinux:latest \

rpc_monitor/cronjob_get_status.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
cd $HOME/cosmosia/rpc_monitor
33

44
RPC_SERVICES=$(curl -s https://raw.githubusercontent.com/notional-labs/cosmosia/main/data/chain_registry.ini |egrep -o "\[.*\]" | sed 's/^\[\(.*\)\]$/\1/')
5+
6+
rpc_service_verions=$(curl -sG -XGET http://tasks.web_config:2375/services --data-urlencode 'filters={"label":["cosmosia.service=rpc"]}' |jq -r '.[].Spec.Name')
7+
RPC_SERVICES="${RPC_SERVICES}"$'\n'"${rpc_service_verions}"
8+
# echo "RPC_SERVICES=$RPC_SERVICES"
9+
10+
511
#TMP_DIR="$HOME/tmp"
612
TMP_DIR="./web/build"
713
TMP_STATUS_FILE="$TMP_DIR/status.json"

0 commit comments

Comments
 (0)