forked from Battlelore21/general-ton-node
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.sh
executable file
·117 lines (98 loc) · 3.71 KB
/
init.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
#!/usr/bin/env bash
set -x
if [ ! -d /var/ton-work/contracts ]; then
cp -r /var/ton-work-copy/* /var/ton-work
fi
cd /var/ton-work/db
cron &
if [ -z "$PUBLIC_IP" ]; then
export PUBLIC_IP=127.0.0.1
fi
if [ -z "$CONSOLE_PORT" ]; then
export CONSOLE_PORT=50001
fi
if [ -z "$PUBLIC_PORT" ]; then
export PUBLIC_PORT=50000
fi
if ( [ -d "state" ] && [ "$(ls -A ./state)" ]); then
echo "Found non-empty state; Skip initialization";
wget -O my-ton-global.config.json ${CONFIG}
cat ${CONFIG}
else
echo "Initializing network";
./prepare_network.sh
fi
if [[ "$SERVECONFIG" == 1 ]]; then
echo "Serving config"
python -m SimpleHTTPServer "$HTTPPORT" &
fi
if [[ "$DHT_SERVER" == 1 ]]; then
echo "Start DHT server on $BIND_IP:$DHT_PORT"
cd dht-server
IP=$PUBLIC_IP; IPNUM=0; for (( i=0 ; i<4 ; ++i )); do ((IPNUM=$IPNUM+${IP%%.*}*$((256**$((3-${i})))))); IP=${IP#*.}; done
[ $IPNUM -gt $((2**31)) ] && IPNUM=$(($IPNUM - $((2**32))))
DHT_NODES=$(generate-random-id -m dht -k ./dht_key -a "{
\"@type\": \"adnl.addressList\",
\"addrs\": [
{
\"@type\": \"adnl.address.udp\",
\"ip\": $IPNUM,
\"port\": $DHT_PORT
}
],
\"version\": 0,
\"reinit_date\": 0,
\"priority\": 0,
\"expire_at\": 0
}")
dht_server.sh &
cd ..
echo $DHT_NODES > ./dht_node.conf
else
DHT_KEY=$(python -c "f=open('config.json', 'r'); import json; j=json.load(f); k=j['dht'][0]['id']; import base64; import codecs; print('%064X' % int(codecs.encode(base64.b64decode(k), 'hex'), 16))")
echo "DHT key: $DHT_KEY"
IP=$PUBLIC_IP; IPNUM=0; for (( i=0 ; i<4 ; ++i )); do ((IPNUM=$IPNUM+${IP%%.*}*$((256**$((3-${i})))))); IP=${IP#*.}; done
[ $IPNUM -gt $((2**31)) ] && IPNUM=$(($IPNUM - $((2**32))))
DHT_NODES=$(generate-random-id -m dht -k /var/ton-work/db/keyring/$DHT_KEY -a "{
\"@type\": \"adnl.addressList\",
\"addrs\": [
{
\"@type\": \"adnl.address.udp\",
\"ip\": $IPNUM,
\"port\": $PUBLIC_PORT
}
],
\"version\": 0,
\"reinit_date\": 0,
\"priority\": 0,
\"expire_at\": 0
}")
echo $DHT_NODES > ./dht_node.conf
fi
if [ ! -z "$LITESERVER" ]; then
cd /var/ton-work/db
LITESERVER_PUB=$(python -c 'import codecs; f=open("liteserver.pub", "rb+"); pub=f.read()[4:]; print(codecs.encode(pub,"base64").replace("\n",""))')
IP=$PUBLIC_IP; IPNUM=0; for (( i=0 ; i<4 ; ++i )); do ((IPNUM=$IPNUM+${IP%%.*}*$((256**$((3-${i})))))); IP=${IP#*.}; done
[ $IPNUM -gt $((2**31)) ] && IPNUM=$(($IPNUM - $((2**32))))
LITESERVERSCONFIG="{\"id\":{\"key\":\"$LITESERVER_PUB\", \"@type\":\"pub.ed25519\"}, \"port\":\"$LITE_PORT\", \"ip\":$IPNUM, \"ws\":\"ws://$PUBLIC_IP:$WS_PORT\" }"
echo $LITESERVERSCONFIG > liteserver.conf
if [[ "$WS_PROXY" == 1 ]]; then
echo "Start WS proxy on $BIND_IP:$WS_PORT"
ws_proxy.sh &
fi
if [[ "$BLOCK_EXPLORER" == 1 ]]; then
echo "Start BLOCKCHAIN explorer on $BIND_IP:$BLOCK_PORT"
block_explorer.sh &
fi
fi
if [[ "$GENESIS" == 1 ]]; then
cp my-ton-global.config.json initial-ton-global.config.json
fi
while [ 1 = 1 ]
do
echo "Start validator on $BIND_IP:$PUBLIC_PORT"
validator-engine -t $CORE_COUNT -C /var/ton-work/db/my-ton-global.config.json --db /var/ton-work/db --ip "$BIND_IP:$PUBLIC_PORT" >> /var/ton-work/logs/node.log 2>&1
date -u >> /var/ton-work/logs/node.log
echo "validator-engine exited" >> /var/ton-work/logs/node.log
date -u >> /var/ton-work/logs/node-restarts.log
done