-
Notifications
You must be signed in to change notification settings - Fork 469
/
test-node.bash
executable file
·172 lines (150 loc) · 5.33 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
#!/bin/bash
set -e
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=true
redundantsequencers=0
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
;;
--build)
force_build=true
shift
;;
--validate)
validate=true
shift
;;
--no-blockscout)
blockscout=false
shift
;;
--no-run)
run=false
shift
;;
--detach)
detach=true
shift
;;
--redundantsequencers)
redundantsequencers=$2
if ! [[ $redundantsequencers =~ "[0-3]" ]] ; then
echo "redundantsequencers must be between 0 and 3"
fi
shift
shift
;;
*)
echo Usage: $0 \[OPTIONS..]
echo $0 script [SCRIPT-ARGS]
echo
echo OPTIONS:
echo --build: rebuild docker image
echo --init: remove all data, rebuild, deploy new rollup
echo --validate: heavy computation, validating all blocks in WASM
echo --redundantsequencers redundant sequencers [0-3]
echo --detach: detach from nodes after running them
echo --no-run: does not launch nodes \(usefull with build or init\)
echo
echo script rus inside a separate docker. For SCRIPT-ARGS, run $0 script --help
exit 0
esac
done
if $force_init; then
force_build=true
fi
NODES="sequencer poster"
if [ $redundantsequencers -gt 0 ]; then
NODES="$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 $validate; then
NODES="$NODES validator"
else
NODES="$NODES staker-unsafe"
fi
if $blockscout; then
NODES="$NODES blockscout"
fi
if $force_build; then
echo == Building..
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
echo == Generating l1 keys
docker-compose run --entrypoint sh geth -c "echo passphrase > /root/.ethereum/passphrase"
docker-compose run --entrypoint sh geth -c "echo e887f7d17d07cc7b8004053fb8826f6657084e88904bb61590e498ca04704cf2 > /root/.ethereum/tmp-funnelkey"
docker-compose run geth account import --password /root/.ethereum/passphrase --keystore /keystore /root/.ethereum/tmp-funnelkey
docker-compose run --entrypoint sh geth -c "rm /root/.ethereum/tmp-funnelkey"
docker-compose run geth account new --password /root/.ethereum/passphrase --keystore /keystore
docker-compose run geth account new --password /root/.ethereum/passphrase --keystore /keystore
docker-compose run --entrypoint sh geth -c "chown -R 1000:1000 /keystore"
docker-compose run --entrypoint sh geth -c "chown -R 1000:1000 /config"
echo == Funding validator and sequencer
docker-compose run testnode-scripts send-l1 --ethamount 1000 --to validator
docker-compose run testnode-scripts send-l1 --ethamount 1000 --to sequencer
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
echo == Writing configs
docker-compose run testnode-scripts write-config
echo == Initializing redis
docker-compose run testnode-scripts redis-init --redundancy $redundantsequencers
docker-compose run testnode-scripts bridge-funds --ethamount 100000
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