forked from lavanet/lava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_provider.sh
executable file
·126 lines (106 loc) · 3.16 KB
/
start_provider.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
# vim:sw=4:ts=4:et
set -e
info() {
echo "INF: $@"
}
debug() {
echo "DBG: $@"
}
error() {
echo "ERR: $@"
exit 1
}
check_env_vars() {
# no need to check LAVA_USER and LAVA_ADDRESS: see check_lava_addr()
env_vars="LAVA_KEYRING \
LAVA_STAKE_AMOUNT \
LAVA_GEOLOCATION \
LAVA_RPC_NODE \
LAVA_CHAIN_ID \
LAVA_GAS_MODE \
LAVA_GAS_ADJUST \
LAVA_GAS_PRICE \
LAVA_LISTEN_IP \
LAVA_PORTAL_PORT \
LAVA_RELAY_ENDPOINT \
LAVA_RELAY_NODE_URL \
LAVA_RELAY_CHAIN_ID \
LAVA_RELAY_IFACE \
LAVA_LOG_LEVEL \
"
for ev in $env_vars; do
eval "v=\$$ev"
test -z "${v}" && errmsg="${errmsg} ${ev}\n"
done
if [ -n "$errmsg" ]; then
error "some env variables not defined:\n${errmsg%%\\n}"
fi
}
check_lava_addr() {
lavad keys list --keyring-backend "${LAVA_KEYRING}"
if [ -z "${LAVA_ADDRESS}" ]; then
LAVA_ADDRESS=$(lavad keys show "${LAVA_USER}" --keyring-backend "${LAVA_KEYRING}" | \
grep address | awk '{print $2}')
if [ -z "${LAVA_ADDRESS}" ]; then
error "unable to fetch the user's lava address"
fi
else
lavad keys list --keyring-backend "${LAVA_KEYRING}" | \
grep -q ${LAVA_ADDRESS} || \
error "unable to find the requested lava address"
fi
}
provider_staked_amount() {
lavad query pairing providers \
"${LAVA_RELAY_CHAIN_ID}" \
--node "${LAVA_RPC_NODE}" \
--chain-id "${LAVA_CHAIN_ID}" \
| sed -n '/Staked Providers:/{n;p}' \
| grep "${LAVA_ADDRESS}" \
| sed 's/^.*{\([0-9]*ulava\).*$/\1/'
}
stake_provider() {
info "staking provider - this may take a while"
lavad tx pairing stake-provider -y \
"${LAVA_RELAY_CHAIN_ID}" \
"${LAVA_STAKE_AMOUNT}" \
"${LAVA_RELAY_ENDPOINT}" \
"${LAVA_GEOLOCATION}" \
--from "${LAVA_ADDRESS}" \
--provider-moniker "dummyMoniker" \
--node "${LAVA_RPC_NODE}" \
--chain-id "${LAVA_CHAIN_ID}" \
--keyring-backend "${LAVA_KEYRING}" \
--gas-adjustment "${LAVA_GAS_ADJUST}" \
--gas-prices "${LAVA_GAS_PRICE}" \
--gas "${LAVA_GAS_MODE}" \
--log_level "${LAVA_LOG_LEVEL}" ||
error "unable to stake provider"
}
# check sanity of env vars
check_env_vars
# check (and maybe get) lava address
check_lava_addr
# check that provider is staked with right amount
stake_amount=$(provider_staked_amount)
if [ -z $stake_amount ]; then
info "provider not staked: staking provider"
stake_provider
elif [ $stake_amount -lt ${LAVA_STAKE_AMOUNT} ]; then
info "provider staked amount to small: increasing amount"
stake_provider
fi
debug "starting provider server"
exec lavad portal_server \
"${LAVA_LISTEN_IP}" \
"${LAVA_PORTAL_PORT}" \
"${LAVA_RELAY_NODE_URL}" \
"${LAVA_RELAY_CHAIN_ID}" \
"${LAVA_RELAY_IFACE}" \
--from "${LAVA_ADDRESS}" \
--node "${LAVA_RPC_NODE}" \
--chain-id "${LAVA_CHAIN_ID}" \
--geolocation "${LAVA_GEOLOCATION}" \
--log_level "${LAVA_LOG_LEVEL}" ||
error "unable to start provider"