-
Notifications
You must be signed in to change notification settings - Fork 63
/
entrypoint.sh
executable file
·167 lines (157 loc) · 6.29 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
#!/bin/bash -e
export FULL_ENV_FILE="/defaults/defaults.env"
if [ -f /config/values.env ];
then
export FULL_ENV_FILE="/config/values.env"
fi
# 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
source /tmp/values-short.env
SERVER_ENABLED="${SERVER_ENABLED:-false}"
SERVER_PORT="${SERVER_PORT:-8000}"
WITHDRAWAL_ADDRESS="${WITHDRAWAL_ADDRESS:-0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134}"
PRESET_BASE="${PRESET_BASE:-mainnet}"
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/el-gen/envsubst.py < /config/el/genesis-config.yaml > $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"
envsubst < /config/cl/config.yaml > /data/metadata/config.yaml
sed -i "s/#HUMAN_TIME_PLACEHOLDER/$COMMENT/" /data/metadata/config.yaml
envsubst < /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
envsubst < /config/cl/mnemonics.yaml > $tmp_dir/mnemonics.yaml
# Generate genesis
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
)
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 "")
else
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
zcli_args=(
pretty
deneb
BeaconState
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
--preset-bellatrix $PRESET_BASE
--preset-capella $PRESET_BASE
--preset-deneb $PRESET_BASE
/data/metadata/genesis.ssz
)
/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