forked from MaxeASN/nitro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-node.bash
executable file
·319 lines (280 loc) · 9.53 KB
/
test-node.bash
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/usr/bin/env bash
set -e
NITRO_NODE_VERSION=offchainlabs/nitro-node:v2.0.14-2baa834-dev
BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.0.0-c8db5b1
mydir=`dirname $0`
cd "$mydir"
if ! which docker-compose > /dev/null; then
echo == Error! docker-compose not installed
echo please install docker-compose and have it in PATH
echo see https://docs.docker.com/compose/install/
exit 1
fi
if [[ $# -gt 0 ]] && [[ $1 == "script" ]]; then
shift
docker-compose run testnode-scripts "$@"
exit $?
fi
num_volumes=`docker volume ls --filter label=com.docker.compose.project=nitro -q | wc -l`
if [[ $num_volumes -eq 0 ]]; then
force_init=true
else
force_init=false
fi
run=true
force_build=false
validate=false
detach=false
blockscout=false
tokenbridge=true
consensusclient=false
redundantsequencers=0
dev_build_nitro=false
dev_build_blockscout=false
batchposters=1
devprivkey=b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659
l1chainid=1337
while [[ $# -gt 0 ]]; do
case $1 in
--init)
if ! $force_init; then
echo == Warning! this will remove all previous data
read -p "are you sure? [y/n]" -n 1 response
if [[ $response == "y" ]] || [[ $response == "Y" ]]; then
force_init=true
echo
else
exit 0
fi
fi
shift
;;
--dev)
shift
if [[ $# -eq 0 || $1 == -* ]]; then
# If no argument after --dev, set both flags to true
dev_build_nitro=true
dev_build_blockscout=true
else
while [[ $# -gt 0 && $1 != -* ]]; do
if [[ $1 == "nitro" ]]; then
dev_build_nitro=true
elif [[ $1 == "blockscout" ]]; then
dev_build_blockscout=true
fi
shift
done
fi
;;
--build)
force_build=true
shift
;;
--validate)
validate=true
shift
;;
--blockscout)
blockscout=true
shift
;;
--no-tokenbridge)
tokenbridge=false
shift
;;
--no-run)
run=false
shift
;;
--detach)
detach=true
shift
;;
--batchposters)
batchposters=$2
if ! [[ $batchposters =~ [0-3] ]] ; then
echo "batchposters must be between 0 and 3 value:$batchposters."
exit 1
fi
shift
shift
;;
--pos)
consensusclient=true
l1chainid=32382
shift
;;
--redundantsequencers)
redundantsequencers=$2
if ! [[ $redundantsequencers =~ [0-3] ]] ; then
echo "redundantsequencers must be between 0 and 3 value:$redundantsequencers."
exit 1
fi
shift
shift
;;
*)
echo Usage: $0 \[OPTIONS..]
echo $0 script [SCRIPT-ARGS]
echo
echo OPTIONS:
echo --build: rebuild docker images
echo --dev: build nitro and blockscout dockers from source \(otherwise - pull docker\)
echo --init: remove all data, rebuild, deploy new rollup
echo --pos: l1 is a proof-of-stake chain \(using prysm for consensus\)
echo --validate: heavy computation, validating all blocks in WASM
echo --batchposters: batch posters [0-3]
echo --redundantsequencers redundant sequencers [0-3]
echo --detach: detach from nodes after running them
echo --blockscout: build or launch blockscout
echo --no-tokenbridge: don\'t build or launch tokenbridge
echo --no-run: does not launch nodes \(usefull with build or init\)
echo
echo script runs inside a separate docker. For SCRIPT-ARGS, run $0 script --help
exit 0
esac
done
if $force_init; then
force_build=true
fi
if $dev_build_nitro; then
if [[ "$(docker images -q nitro-node-dev:latest 2> /dev/null)" == "" ]]; then
force_build=true
fi
fi
if $dev_build_blockscout; then
if [[ "$(docker images -q blockscout:latest 2> /dev/null)" == "" ]]; then
force_build=true
fi
fi
NODES="sequencer"
INITIAL_SEQ_NODES="sequencer"
if [ $redundantsequencers -gt 0 ]; then
NODES="$NODES sequencer_b"
INITIAL_SEQ_NODES="$INITIAL_SEQ_NODES sequencer_b"
fi
if [ $redundantsequencers -gt 1 ]; then
NODES="$NODES sequencer_c"
fi
if [ $redundantsequencers -gt 2 ]; then
NODES="$NODES sequencer_d"
fi
if [ $batchposters -gt 0 ]; then
NODES="$NODES poster"
fi
if [ $batchposters -gt 1 ]; then
NODES="$NODES poster_b"
fi
if [ $batchposters -gt 2 ]; then
NODES="$NODES poster_c"
fi
if $validate; then
NODES="$NODES validator"
else
NODES="$NODES staker-unsafe"
fi
if $blockscout; then
NODES="$NODES blockscout"
fi
if $force_build; then
echo == Building..
if $dev_build_nitro; then
docker build . -t nitro-node-dev --target nitro-node-dev
fi
if $dev_build_blockscout; then
if $blockscout; then
docker build blockscout -t blockscout -f blockscout/docker/Dockerfile
fi
fi
LOCAL_BUILD_NODES=testnode-scripts
if $tokenbridge; then
LOCAL_BUILD_NODES="$LOCAL_BUILD_NODES testnode-tokenbridge"
fi
docker-compose build --no-rm $LOCAL_BUILD_NODES
fi
if $dev_build_nitro; then
docker tag nitro-node-dev:latest nitro-node-dev-testnode
else
docker pull $NITRO_NODE_VERSION
docker tag $NITRO_NODE_VERSION nitro-node-dev-testnode
fi
if $dev_build_blockscout; then
if $blockscout; then
docker tag blockscout:latest blockscout-testnode
fi
else
if $blockscout; then
docker pull $BLOCKSCOUT_VERSION
docker tag $BLOCKSCOUT_VERSION blockscout-testnode
fi
fi
if $force_build; then
docker-compose build --no-rm $NODES testnode-scripts
fi
if $force_init; then
echo == Removing old data..
docker-compose down
leftoverContainers=`docker container ls -a --filter label=com.docker.compose.project=nitro -q | xargs echo`
if [ `echo $leftoverContainers | wc -w` -gt 0 ]; then
docker rm $leftoverContainers
fi
docker volume prune -f --filter label=com.docker.compose.project=nitro
leftoverVolumes=`docker volume ls --filter label=com.docker.compose.project=nitro -q | xargs echo`
if [ `echo $leftoverVolumes | wc -w` -gt 0 ]; then
docker volume rm $leftoverVolumes
fi
echo == Generating l1 keys
docker-compose run testnode-scripts write-accounts
docker-compose run --entrypoint sh geth -c "echo passphrase > /datadir/passphrase"
docker-compose run --entrypoint sh geth -c "chown -R 1000:1000 /keystore"
docker-compose run --entrypoint sh geth -c "chown -R 1000:1000 /config"
if $consensusclient; then
echo == Writing configs
docker-compose run testnode-scripts write-geth-genesis-config
echo == Writing configs
docker-compose run testnode-scripts write-prysm-config
echo == Initializing go-ethereum genesis configuration
docker-compose run geth init --datadir /datadir/ /config/geth_genesis.json
echo == Starting geth
docker-compose up -d geth
echo == Creating prysm genesis
docker-compose up create_beacon_chain_genesis
echo == Running prysm
docker-compose up -d prysm_beacon_chain
docker-compose up -d prysm_validator
else
docker-compose up -d geth
fi
echo == Funding validator and sequencer
docker-compose run testnode-scripts send-l1 --ethamount 1000 --to validator --wait
docker-compose run testnode-scripts send-l1 --ethamount 1000 --to sequencer --wait
echo == create l1 traffic
docker-compose run testnode-scripts send-l1 --ethamount 1000 --to user_l1user --wait
docker-compose run testnode-scripts send-l1 --ethamount 0.0001 --from user_l1user --to user_l1user_b --wait --delay 500 --times 500 > /dev/null &
echo == Deploying L2
sequenceraddress=`docker-compose run testnode-scripts print-address --account sequencer | tail -n 1 | tr -d '\r\n'`
docker-compose run --entrypoint /usr/local/bin/deploy poster --l1conn ws://geth:8546 --l1keystore /home/user/l1keystore --sequencerAddress $sequenceraddress --ownerAddress $sequenceraddress --l1DeployAccount $sequenceraddress --l1deployment /config/deployment.json --authorizevalidators 10 --wasmrootpath /home/user/target/machines --l1chainid=$l1chainid
echo == Writing configs
docker-compose run testnode-scripts write-config
echo == Initializing redis
docker-compose run testnode-scripts redis-init --redundancy $redundantsequencers
echo == Funding l2 funnel
docker-compose up -d $INITIAL_SEQ_NODES
docker-compose run testnode-scripts bridge-funds --ethamount 100000 --wait
if $tokenbridge; then
echo == Deploying token bridge
docker-compose run -e ARB_KEY=$devprivkey -e ETH_KEY=$devprivkey testnode-tokenbridge gen:network
docker-compose run --entrypoint sh testnode-tokenbridge -c "cat localNetwork.json"
echo
fi
fi
if $run; then
UP_FLAG=""
if $detach; then
UP_FLAG="-d"
fi
echo == Launching Sequencer
echo if things go wrong - use --init to create a new chain
echo
docker-compose up $UP_FLAG $NODES
fi