-
Notifications
You must be signed in to change notification settings - Fork 64
/
entrypoint.sh
executable file
·260 lines (247 loc) · 9.65 KB
/
entrypoint.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
#!/bin/bash -e
export DEFAULT_ENV_FILE="/defaults/defaults.env"
# Load the default env vars into the environment
source $DEFAULT_ENV_FILE
if [ -f /config/values.env ];
then
# Use user provided env vars if it exists
export FULL_ENV_FILE="/config/values.env"
# Pull these values out of the env file since they can be very large and cause
# "arguments list too long" errors in the shell.
grep -v "ADDITIONAL_PRELOADED_CONTRACTS" $FULL_ENV_FILE | grep -v "EL_PREMINE_ADDRS" > /tmp/values-short.env
# print the value of ADDITIONAL_PRELOADED_CONTRACTS
else
grep -v "ADDITIONAL_PRELOADED_CONTRACTS" $DEFAULT_ENV_FILE | grep -v "EL_PREMINE_ADDRS" > /tmp/values-short.env
fi
# Load the env vars entered by the user without the larger values into the environment
source /tmp/values-short.env
SERVER_ENABLED="${SERVER_ENABLED:-false}"
SERVER_PORT="${SERVER_PORT:-8000}"
gen_shared_files(){
. /apps/el-gen/.venv/bin/activate
set -x
# Shared files
mkdir -p /data/metadata
if ! [ -f "/data/jwt/jwtsecret" ]; then
mkdir -p /data/jwt
echo -n 0x$(openssl rand -hex 32 | tr -d "\n") > /data/jwt/jwtsecret
fi
if [ -f "/data/metadata/genesis.json" ]; then
terminalTotalDifficulty=$(cat /data/metadata/genesis.json | jq -r '.config.terminalTotalDifficulty | tostring')
sed -i "s/TERMINAL_TOTAL_DIFFICULTY:.*/TERMINAL_TOTAL_DIFFICULTY: $terminalTotalDifficulty/" /data/metadata/config.yaml
fi
}
gen_el_config(){
. /apps/el-gen/.venv/bin/activate
set -x
if ! [ -f "/data/metadata/genesis.json" ]; then
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
mkdir -p /data/metadata
python3 /apps/envsubst.py < /config/el/genesis-config.yaml > $tmp_dir/genesis-config.yaml
cat $tmp_dir/genesis-config.yaml
python3 /apps/el-gen/genesis_geth.py $tmp_dir/genesis-config.yaml > /data/metadata/genesis.json
python3 /apps/el-gen/genesis_chainspec.py $tmp_dir/genesis-config.yaml > /data/metadata/chainspec.json
python3 /apps/el-gen/genesis_besu.py $tmp_dir/genesis-config.yaml > /data/metadata/besu.json
else
echo "el genesis already exists. skipping generation..."
fi
}
gen_minimal_config() {
declare -A replacements=(
[MIN_PER_EPOCH_CHURN_LIMIT]=2
[MIN_EPOCHS_FOR_BLOCK_REQUESTS]=272
[WHISK_EPOCHS_PER_SHUFFLING_PHASE]=4
[WHISK_PROPOSER_SELECTION_GAP]=1
[MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA]=64000000000
[MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT]=128000000000
)
for key in "${!replacements[@]}"; do
sed -i "s/$key:.*/$key: ${replacements[$key]}/" /data/metadata/config.yaml
done
}
gen_cl_config(){
. /apps/el-gen/.venv/bin/activate
set -x
# Consensus layer: Check if genesis already exists
if ! [ -f "/data/metadata/genesis.ssz" ]; then
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
mkdir -p /data/metadata
mkdir -p /data/parsed
HUMAN_READABLE_TIMESTAMP=$(date -u -d @"$GENESIS_TIMESTAMP" +"%Y-%b-%d %I:%M:%S %p %Z")
COMMENT="# $HUMAN_READABLE_TIMESTAMP"
export MAX_REQUEST_BLOB_SIDECARS_ELECTRA=$(($MAX_REQUEST_BLOCKS_DENEB * $MAX_BLOBS_PER_BLOCK_ELECTRA))
export MAX_REQUEST_BLOB_SIDECARS_EIP7594=$(($MAX_REQUEST_BLOCKS_DENEB * $MAX_BLOBS_PER_BLOCK_EIP7594))
python3 /apps/envsubst.py < /config/cl/config.yaml > /data/metadata/config.yaml
sed -i "s/#HUMAN_TIME_PLACEHOLDER/$COMMENT/" /data/metadata/config.yaml
python3 /apps/envsubst.py < /config/cl/mnemonics.yaml > $tmp_dir/mnemonics.yaml
# Conditionally override values if preset is "minimal"
if [[ "$PRESET_BASE" == "minimal" ]]; then
gen_minimal_config
fi
cp $tmp_dir/mnemonics.yaml /data/metadata/mnemonics.yaml
# Create deposit_contract.txt and deploy_block.txt
grep DEPOSIT_CONTRACT_ADDRESS /data/metadata/config.yaml | cut -d " " -f2 > /data/metadata/deposit_contract.txt
echo $CL_EXEC_BLOCK > /data/metadata/deposit_contract_block.txt
echo $BEACON_STATIC_ENR > /data/metadata/bootstrap_nodes.txt
# Envsubst mnemonics
python3 /apps/envsubst.py < /config/cl/mnemonics.yaml > $tmp_dir/mnemonics.yaml
# Generate genesis
if [[ $ALTAIR_FORK_EPOCH != 0 ]]; then
genesis_args+=(
phase0
--config /data/metadata/config.yaml
--mnemonics $tmp_dir/mnemonics.yaml
--tranches-dir /data/metadata/tranches
--state-output /data/metadata/genesis.ssz
--preset-phase0 $PRESET_BASE
)
elif [[ $BELLATRIX_FORK_EPOCH != 0 ]]; then
genesis_args+=(
altair
--config /data/metadata/config.yaml
--mnemonics $tmp_dir/mnemonics.yaml
--tranches-dir /data/metadata/tranches
--state-output /data/metadata/genesis.ssz
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
)
elif [[ $CAPELLA_FORK_EPOCH != 0 ]]; then
genesis_args+=(
bellatrix
--config /data/metadata/config.yaml
--mnemonics $tmp_dir/mnemonics.yaml
--tranches-dir /data/metadata/tranches
--state-output /data/metadata/genesis.ssz
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
--preset-bellatrix $PRESET_BASE
)
elif [[ $DENEB_FORK_EPOCH != 0 ]]; then
genesis_args+=(
capella
--config /data/metadata/config.yaml
--mnemonics $tmp_dir/mnemonics.yaml
--tranches-dir /data/metadata/tranches
--state-output /data/metadata/genesis.ssz
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
--preset-bellatrix $PRESET_BASE
--preset-capella $PRESET_BASE
)
else
genesis_args+=(
deneb
--config /data/metadata/config.yaml
--mnemonics $tmp_dir/mnemonics.yaml
--tranches-dir /data/metadata/tranches
--state-output /data/metadata/genesis.ssz
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
--preset-bellatrix $PRESET_BASE
--preset-capella $PRESET_BASE
--preset-deneb $PRESET_BASE
)
fi
if [[ $WITHDRAWAL_TYPE == "0x01" ]]; then
genesis_args+=(--eth1-withdrawal-address $WITHDRAWAL_ADDRESS)
fi
if [[ $SHADOW_FORK_FILE != "" ]]; then
genesis_args+=(--shadow-fork-block-file=$SHADOW_FORK_FILE --eth1-config "")
elif [[ $SHADOW_FORK_RPC != "" ]]; then
genesis_args+=(--shadow-fork-eth1-rpc=$SHADOW_FORK_RPC --eth1-config "")
elif [[ $ALTAIR_FORK_EPOCH == 0 ]] && [[ $BELLATRIX_FORK_EPOCH == 0 ]]; then
genesis_args+=(--eth1-config /data/metadata/genesis.json)
fi
if ! [ -z "$CL_ADDITIONAL_VALIDATORS" ]; then
if [[ $CL_ADDITIONAL_VALIDATORS = /* ]]; then
validators_file=$CL_ADDITIONAL_VALIDATORS
else
validators_file="/config/$CL_ADDITIONAL_VALIDATORS"
fi
genesis_args+=(--additional-validators $validators_file)
fi
if [[ $ALTAIR_FORK_EPOCH != 0 ]]; then
zcli_args=(
pretty
phase0
BeaconState
--preset-phase0 $PRESET_BASE
/data/metadata/genesis.ssz
)
elif [[ $BELLATRIX_FORK_EPOCH != 0 ]]; then
zcli_args=(
pretty
altair
BeaconState
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
/data/metadata/genesis.ssz
)
elif [[ $CAPELLA_FORK_EPOCH != 0 ]]; then
zcli_args=(
pretty
bellatrix
BeaconState
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
--preset-bellatrix $PRESET_BASE
/data/metadata/genesis.ssz
)
elif [[ $DENEB_FORK_EPOCH != 0 ]]; then
zcli_args=(
pretty
capella
BeaconState
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
--preset-bellatrix $PRESET_BASE
/data/metadata/genesis.ssz
)
else
zcli_args=(
pretty
deneb
BeaconState
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
--preset-bellatrix $PRESET_BASE
--preset-capella $PRESET_BASE
/data/metadata/genesis.ssz
)
fi
/usr/local/bin/eth2-testnet-genesis "${genesis_args[@]}"
/usr/local/bin/zcli "${zcli_args[@]}" > /data/parsed/parsedConsensusGenesis.json
echo "Genesis args: ${genesis_args[@]}"
echo "Genesis block number: $(jq -r '.latest_execution_payload_header.block_number' /data/parsed/parsedConsensusGenesis.json)"
echo "Genesis block hash: $(jq -r '.latest_execution_payload_header.block_hash' /data/parsed/parsedConsensusGenesis.json)"
jq -r '.eth1_data.block_hash' /data/parsed/parsedConsensusGenesis.json| tr -d '\n' > /data/metadata/deposit_contract_block_hash.txt
jq -r '.genesis_validators_root' /data/parsed/parsedConsensusGenesis.json | tr -d '\n' > /data/metadata/genesis_validators_root.txt
else
echo "cl genesis already exists. skipping generation..."
fi
}
gen_all_config(){
gen_el_config
gen_cl_config
gen_shared_files
}
case $1 in
el)
gen_el_config
;;
cl)
gen_cl_config
;;
all)
gen_all_config
;;
*)
set +x
echo "Usage: [all|cl|el]"
exit 1
;;
esac
# Start webserver
if [ "$SERVER_ENABLED" = true ] ; then
cd /data && exec python3 -m http.server "$SERVER_PORT"
fi