This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_lotus.sh
executable file
·265 lines (208 loc) · 9.17 KB
/
start_lotus.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#! /bin/bash
###################################################################################
# #
# Lotus Testnode Start Script - Marcel Wuersten - 2022 - University of Bern #
# #
###################################################################################
# Define env vars
export LOTUS_SKIP_GENESIS_CHECK=_yes_
export LOTUS_PATH=~/.lotus
export LOTUS_MINER_PATH=~/.lotusminer
# create general directories
mkdir -p ~/.lotus
mkdir -p ~/.lotusminer
mkdir -p ~/.genesis-sectors
while ! rediscli r fil-nodes; do
sleep 1
done
nodeCount=$(rediscli r fil-nodes)
if [ "$(hostname)" == "lotus-node-0" ]; then
echo "Start genesis"
for i in $(seq 0 $nodeCount)
do
mkdir -p /config/lotus-node-${i}/
mkdir -p /config/lotus-node-${i}/cache
mkdir -p /config/lotus-node-${i}/sealed
# Generating bls keys for pre-sealing sectors
mv ./bls-$(lotus-shed keyinfo new bls).keyinfo /config/lotus-node-${i}/keyPreSeal.keyinfo
# Generating libp2p ed25519 peer key
mv ./libp2p-host-$(lotus-shed keyinfo new libp2p-host).keyinfo /config/lotus-node-${i}/keyPeer.keyinfo
# Pre-sealing sectors
minerId=$((1000 + ${i}))
lotus-seed pre-seal --miner-addr t0${minerId} --sector-size 2KiB --num-sectors 2 --sector-offset 0 --key /config/lotus-node-${i}/keyPreSeal.keyinfo
mv /root/.genesis-sectors/pre-seal-t0${minerId}.json /config/lotus-node-${i}/
mv /root/.genesis-sectors/cache/s-t0${minerId}-0 /config/lotus-node-${i}/cache/
mv /root/.genesis-sectors/cache/s-t0${minerId}-1 /config/lotus-node-${i}/cache/
mv /root/.genesis-sectors/sealed/s-t0${minerId}-0 /config/lotus-node-${i}/sealed/
mv /root/.genesis-sectors/sealed/s-t0${minerId}-1 /config/lotus-node-${i}/sealed/
mv /root/.genesis-sectors/sectorstore.json /config/lotus-node-${i}/
done
# Generate network configuration
lotus-seed genesis new --network-name fil-testnet genesis.json
echo "genesis creation done"
# Set Network start time, to avoid catchup at start
# GENESISDELAY is a time in seconds added to the current time to delay the network start by some amount of time
GENESISDELAY=120
GENESISTMP=$(mktemp)
GENESISTIMESTAMP=$(date --utc +%FT%H:%M:00Z)
TIMESTAMP=$(echo $(date -d ${GENESISTIMESTAMP} +%s) + ${GENESISDELAY} | bc)
jq --arg Timestamp ${TIMESTAMP} ' . + { Timestamp: $Timestamp|tonumber } ' < "genesis.json" > ${GENESISTMP}
mv ${GENESISTMP} "genesis.json"
# Add miners to genesis
for i in $(seq 0 $nodeCount)
do
lotus-seed genesis add-miner genesis.json /config/lotus-node-${i}/pre-seal-t0$((1000 + ${i})).json
done
# Generate genesis car file
lotus-seed genesis car --out fil-testnet.car genesis.json
mv fil-testnet.car /config/fil-testnet.car
rediscli w fil-genesis-done now
echo "Done Genesis"
fi
rediscli w "$(hostname)" ready
while ! rediscli r fil-genesis-done; do
sleep 1
done
# Importing keys to lotus repository
mkdir -p $LOTUS_PATH/keystore && chmod 0600 $LOTUS_PATH/keystore
lotus-shed keyinfo import /config/$(hostname)/keyPreSeal.keyinfo
lotus-shed keyinfo import /config/$(hostname)/keyPeer.keyinfo
# Generate Tmux session
tmux new-session -s lotus -d
if [ "$(hostname)" == "lotus-node-0" ]; then
for i in $(seq 0 $nodeCount)
do
while ! rediscli r lotus-node-${i}; do
sleep 1
done
done
# Start Genesis Node Daemon
tmux new-window -t lotus:1 lotus daemon --genesis=/config/fil-testnet.car --bootstrap=false
# Wait till started
lotus wait-api
# Write ip to config
lotus net listen | head -n 1 > /config/$(hostname).txt
lotus-miner init --genesis-miner --actor=t01000 --sector-size=2KiB --pre-sealed-sectors=/config/lotus-node-0 --pre-sealed-metadata=/config/lotus-node-0/pre-seal-t01000.json --nosync
tmux new-window -t lotus:3 lotus-miner run --nosync
rediscli w fil-start-other-node now
if [[ $(rediscli r nettopology) =~ "ring" ]] || [[ $(rediscli r nettopology) =~ "full" ]]; then
until [ -f /config/lotus-node-${nodeCount}.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-${nodeCount}.txt)
fi
else
while ! rediscli r fil-start-other-node; do
sleep 1
done
# Start Node Daemon
tmux new-window -t lotus:1 lotus daemon --genesis=/config/fil-testnet.car --bootstrap=false
lotus wait-api
lotus net listen | head -n 1 > /config/$(hostname).txt
sleep 15
if [[ $(rediscli r nettopology) =~ "ring" ]]; then
until [ -f /config/lotus-node-$((-1 + $(hostname | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'))).txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-$((-1 + $(hostname | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'))).txt)
elif [[ $(rediscli r nettopology) =~ "full" ]]; then
for i in $(seq 0 $((-1 + $(hostname | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'))))
do
until [ -f /config/lotus-node-${i}.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-${i}.txt)
done
elif [[ $(rediscli r nettopology) =~ "tree" ]]; then
if [ "$(hostname)" == "lotus-node-1" ] || [ "$(hostname)" == "lotus-node-2" ] ; then
until [ -f /config/lotus-node-0.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-0.txt)
elif [ "$(hostname)" == "lotus-node-3" ] || [ "$(hostname)" == "lotus-node-4" ] ; then
until [ -f /config/lotus-node-1.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-1.txt)
elif [ "$(hostname)" == "lotus-node-5" ] || [ "$(hostname)" == "lotus-node-6" ] ; then
until [ -f /config/lotus-node-2.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-2.txt)
elif [ "$(hostname)" == "lotus-node-7" ] || [ "$(hostname)" == "lotus-node-8" ] ; then
until [ -f /config/lotus-node-3.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-3.txt)
elif [ "$(hostname)" == "lotus-node-9" ] || [ "$(hostname)" == "lotus-node-10" ] ; then
until [ -f /config/lotus-node-4.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-4.txt)
elif [ "$(hostname)" == "lotus-node-11" ] || [ "$(hostname)" == "lotus-node-12" ] ; then
until [ -f /config/lotus-node-5.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-5.txt)
elif [ "$(hostname)" == "lotus-node-13" ] || [ "$(hostname)" == "lotus-node-14" ] ; then
until [ -f /config/lotus-node-6.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-6.txt)
elif [ "$(hostname)" == "lotus-node-15" ] || [ "$(hostname)" == "lotus-node-16" ] ; then
until [ -f /config/lotus-node-7.txt ]
do
sleep 5
done
lotus net connect $(</config/lotus-node-7.txt)
fi
else
lotus net connect $(</config/lotus-node-0.txt) # fall back to star
fi
sleep 5
lotus wait-api
lotus-miner init --actor=t0$((1000 + $(hostname | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'))) --sector-size=2KiB --pre-sealed-sectors=/config/$(hostname) --pre-sealed-metadata=/config/$(hostname)/pre-seal-t0$((1000 + $(hostname | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/'))).json --nosync
tmux new-window -t lotus:3 lotus-miner run --nosync
#echo "Create Miner"
#echo "Create Wallets"
#ownerWallet=$(lotus wallet new bls)
#workerWallet=$(lotus wallet new bls)
#node0Ip=$(cat /config/gen.ip |sed 's/ *$//g')
#echo "Transfer funds"
#fundOwner=$(curl http://${node0Ip}?lotus%20send%20${ownerWallet}%201000)
#fundWorker=$(curl http://${node0Ip}?lotus%20send%20${workerWallet}%201000)
#echo "fund Owner Id:${fundOwner}"
#echo "fund Worker Id:${fundWorker}"
#sleep 60
#lotus state wait-msg ${fundOwner}
#lotus state wait-msg ${fundWorker}
#echo "init miner"
#lotus-miner init --sector-size=2KiB --owner=${ownerWallet} --worker=$workerWallet --nosync
#tmux new-window -t lotus:3 lotus-miner run --nosync
#echo "Set miner actor address"
#lotus-miner actor set-addrs /ip4/$(hostname -I)/tcp/24001
#lotus-miner sectors pledge
#lotus-miner sectors pledge
#lotus-miner sectors seal 0
#lotus-miner sectors seal 1
fi
rediscli w "$(hostname)-started" ready
echo "start remote code execution"
rce > ~/rce.log 2>&1
# Port Forward localhost bound port 1234
#socat tcp-listen:8000,reuseaddr,fork tcp:localhost:1234 &
# Run forever until exit
while :
do
sleep 1
done