-
Notifications
You must be signed in to change notification settings - Fork 1
/
spin-node.sh
executable file
·226 lines (197 loc) · 7.21 KB
/
spin-node.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
#!/bin/bash
# set -e
currentDir=$(pwd)
scriptDir=$(dirname $0)
# scriptDir="$currentDir/$scriptDir"
echo "currentDir=$currentDir"
echo "scriptDir=$scriptDir"
# parse args and set defaults
# source "$(dirname $0)/parse-args.sh"
# parse env and set defaults
source "$(dirname $0)/parse-env.sh"
# build static client input args
source "$scriptDir/client-args.sh"
# ready datadir
source "$scriptDir/ready-datadir.sh"
# additional step for setting geth genesis now that we have datadir
if [ "$ELCLIENT" == "geth" ]
then
if [ -n "$ELCLIENT_IMAGE" ] && [ ! -n "$GETH_INIT_IMAGE" ]
then
GETH_INIT_IMAGE=$ELCLIENT_IMAGE
fi;
if [ -n "$GETH_INIT_IMAGE" ]
then
setupCmd="docker run --rm -v $configDir:/config -v $DATADIR:/data $GETH_INIT_IMAGE --datadir $elDataDirSource/geth $EXTRA_EL_SETUP_PARAMS1 init /config/genesis.json $EXTRA_EL_SETUP_PARAMS2"
else
setupCmd="$ELCLIENT_BINARY --datadir $elDataDirSource/geth $EXTRA_EL_SETUP_PARAMS1 init $configDir/genesis.json $EXTRA_EL_SETUP_PARAMS2"
fi;
echo ""
echo ""
echo "--------------------------------------------------------------------------------------"
echo "--------------------------------------------------------------------------------------"
echo "$setupCmd"
echo "--------------------------------------------------------------------------------------"
echo ""
echo ""
echo ""
$setupCmd
fi;
# util for running docker or direct cmds or cleanup
source "$scriptDir/util-fns.sh"
EL_PORT_ARGS="$EL_PORT_ARGS $EXTRA_EL_PARAMS"
if [ "$MULTIPEER" == "peer1" ]
then
case $ELCLIENT in
ethereumjs)
ejsCmd="npm run client:start:ts -- --dataDir $DATADIR/ethereumjs --gethGenesis $configDir/genesis.json --rpc --rpcEngine --rpcEngineAuth false $EL_PORT_ARGS"
;;
geth)
if [ -n "$ELCLIENT_IMAGE" ]
then
# geth will be mounted in docker with DATADIR to /data
ejsCmd="docker run --rm --name execution${MULTIPEER} -v $DATADIR:/data --network host $ELCLIENT_IMAGE $EL_PORT_ARGS"
else
ejsCmd="$ELCLIENT_BINARY $EL_PORT_ARGS"
fi;
;;
*)
echo "ELCLIENT=$ELCLIENT not implemented"
exit;
esac
run_cmd "$ejsCmd"
ejsPid=$!
echo "ejsPid: $ejsPid"
# generate the genesis hash and time
ejsId=0
if [ ! -n "$GENESIS_HASH" ]
then
# We should curl and get genesis hash, but for now lets assume it will be provided
while [ ! -n "$GENESIS_HASH" ]
do
sleep 3
echo "Fetching genesis hash from ethereumjs ..."
ejsId=$(( ejsId +1 ))
responseCmd="curl --location --request POST 'http://localhost:8545' --header 'Content-Type: application/json' --data-raw '{
\"jsonrpc\": \"2.0\",
\"method\": \"eth_getBlockByNumber\",
\"params\": [
\"0x0\",
true
],
\"id\": $ejsId
}' 2>/dev/null | jq \".result.hash\""
# echo "$responseCmd"
GENESIS_HASH=$(eval "$responseCmd")
done;
fi
# if genesis time is coming from forkscheduler use it else set it up
if [ -n "$GENESIS_TIME" ]
then
genTime=$GENESIS_TIME
else
genTime="$(date +%s)"
genTime=$((genTime + 30))
fi;
echo $genTime > "$origDataDir/genesisTime"
echo $GENESIS_HASH > "$origDataDir/genesisHash"
else
# We should curl and get genesis hash, but for now lets assume it will be provided
while [ ! -n "$CL_GENESIS_HASH" ]
do
sleep 3
echo "Fetching genesis block from peer1/cl ..."
ejsId=$(( ejsId +1 ))
responseCmd="curl --location --request GET 'http://localhost:9596/eth/v1/beacon/headers/genesis' --header 'Content-Type: application/json' 2>/dev/null | jq \".data.root\""
CL_GENESIS_HASH=$(eval "$responseCmd")
done;
# We should curl and get boot enr
while [ ! -n "$bootEnrs" ]
do
sleep 3
echo "Fetching bootEnrs block from peer1/cl ..."
ejsId=$(( ejsId +1 ))
responseCmd="curl --location --request GET 'http://localhost:9596/eth/v1/node/identity' --header 'Content-Type: application/json' 2>/dev/null | jq \".data.enr\""
bootEnrs=$(eval "$responseCmd")
done;
# We should curl and get boot enr
while [ ! -n "$elBootnode" ]
do
sleep 3
echo "Fetching elBootnode block from peer1/el ..."
ejsId=$(( ejsId +1 ))
responseCmd="curl -X POST -H 'Content-Type: application/json' http://localhost:8545 --data '{\"jsonrpc\": \"2.0\", \"id\": 42, \"method\": \"admin_nodeInfo\", \"params\": []}' | jq \".result.enode\""
elBootnode=$(eval "$responseCmd")
done;
EL_PORT_ARGS="$EL_PORT_ARGS --bootnodes $elBootnode"
CL_PORT_ARGS="$CL_PORT_ARGS --bootnodes $bootEnrs"
GENESIS_HASH=$(cat "$origDataDir/genesisHash")
genTime=$(cat "$origDataDir/genesisTime")
if [ ! -n "$GENESIS_HASH" ] || [ ! -n "$genTime" ]
then
echo "missing GENESIS_HASH=$GENESIS_HASH or genTime=$genTime in origDataDir=$origDataDir"
exit;
fi;
case $ELCLIENT in
ethereumjs)
ejsCmd="npm run client:start -- --dataDir $DATADIR/ethereumjs --gethGenesis $configDir/$NETWORK.json --rpc --rpcEngine --rpcEngineAuth false $EL_PORT_ARGS"
;;
geth)
if [ -n "$ELCLIENT_IMAGE" ]
then
# geth will be mounted in docker with DATADIR to /data
ejsCmd="docker run --rm --name execution${MULTIPEER} -v $DATADIR:/data --network host $ELCLIENT_IMAGE $EL_PORT_ARGS"
else
ejsCmd="$ELCLIENT_BINARY $EL_PORT_ARGS"
fi;
;;
*)
echo "ELCLIENT=$ELCLIENT not implemented"
esac
run_cmd "$ejsCmd"
ejsPid=$!
echo "ejsPid: $ejsPid"
fi;
echo "genesisHash=${GENESIS_HASH}"
echo "genTime=${genTime}"
CL_PORT_ARGS="--genesisEth1Hash $GENESIS_HASH --params.ALTAIR_FORK_EPOCH 0 --params.BELLATRIX_FORK_EPOCH 0 $EXTRA_CL_PARAMS --params.TERMINAL_TOTAL_DIFFICULTY 0x01 --genesisTime $genTime ${CL_PORT_ARGS} --suggestedFeeRecipient 0xcccccccccccccccccccccccccccccccccccccccc --network.maxPeers 55 --targetPeers 50"
if [ ! -n "$LODE_BINARY" ]
then
if [ ! -n "$LODE_IMAGE" ]
then
LODE_IMAGE="chainsafe/lodestar:latest"
fi;
lodeCmd="docker run --rm --name beacon${MULTIPEER} -v $DATADIR:/data --network host $LODE_IMAGE dev --dataDir $clDataDirSource/lodestar --jwt-secret $clDataDirSource/jwtsecret $CL_PORT_ARGS"
else
lodeCmd="$LODE_BINARY dev --dataDir $clDataDirSource/lodestar --jwt-secret $clDataDirSource/jwtsecret $CL_PORT_ARGS"
fi;
if [ -n LODE_IMAGE ]
then
echo "pulling latest LODE_IMAGE=$LODE_IMAGE"
docker pull $LODE_IMAGE
fi;
run_cmd "$lodeCmd"
lodePid=$!
echo "lodePid: $lodePid"
trap "echo exit signal received;cleanup" SIGINT SIGTERM
if [ -n "$ejsPid" ] && [ -n "$lodePid" ] && [ -n "$RUN_SCENARIOS" ] && [ "$MULTIPEER" == "peer1" ]
then
# currently we only run 1 scenario, can be later parsed as "," separated array
postCmd="$scriptDir/./tx-post.sh $scriptDir/testscenarios/$RUN_SCENARIOS.json"
run_cmd "$postCmd"
postPid=$!
echo "postPid: $postPid"
fi;
if [ ! -n "$DETACHED" ] && [ -n "$ejsPid" ] && [ -n "$lodePid" ]
then
echo "launched ejsPid=$ejsPid lodePid=$lodePid"
echo "use ctl + c on any of these (including this) terminals to stop the process"
wait -n $ejsPid $lodePid
fi
# if its not detached and is here, it means one of the processes exited/didn't launch
if [ ! -n "$DETACHED" ] && [ -n "$ejsPid$lodePid" ]
then
echo "cleaning up ejsPid=$ejsPid lodePid=$lodePid "
cleanup
fi;
echo "Script run finished, exiting ..."