Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove dups, rename metadata #124

Merged
merged 8 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
data/*
.idea/
_snapshot_eth_getBlockByNumber.json
_snapshot_eth_getBlockByNumber.json
output/*
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ mkdir output

# Overwriting the config files and generating the EL and CL genesis
docker run --rm -it -u $UID -v $PWD/output:/data \
-v $PWD/config-example:/config \
-v $PWD/config/values.env:/config/values.env \
ethpandaops/ethereum-genesis-generator:latest all

# Just creating the EL genesis
docker run --rm -it -u $UID -v $PWD/output:/data \
-v $PWD/config-example:/config \
-v $PWD/config/values.env:/config/values.env \
ethpandaops/ethereum-genesis-generator:latest el

# Just creating the CL genesis
docker run --rm -it -u $UID -v $PWD/output:/data \
-v $PWD/config-example:/config \
-v $PWD/config/values.env:/config/values.env \
ethpandaops/ethereum-genesis-generator:latest cl
```
### Environment variables
Expand Down
38 changes: 38 additions & 0 deletions config-example/defaults.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export PRESET_BASE="${PRESET_BASE:-mainnet}"
export CHAIN_ID="${CHAIN_ID:-1337}"
export DEPOSIT_CONTRACT_ADDRESS="${DEPOSIT_CONTRACT_ADDRESS:-0x4242424242424242424242424242424242424242}"
export EL_AND_CL_MNEMONIC="${EL_AND_CL_MNEMONIC:-sleep moment list remain like wall lake industry canvas wonder ecology elite duck salad naive syrup frame brass utility club odor country obey pudding}"
export CL_ADDITIONAL_VALIDATORS="${CL_ADDITIONAL_VALIDATORS:-}"
export CL_EXEC_BLOCK="${CL_EXEC_BLOCK:-0}"
export SLOT_DURATION_IN_SECONDS="${SLOT_DURATION_IN_SECONDS:-12}"
export DEPOSIT_CONTRACT_BLOCK="${DEPOSIT_CONTRACT_BLOCK:-0x0000000000000000000000000000000000000000000000000000000000000000}"
export NUMBER_OF_VALIDATORS="${NUMBER_OF_VALIDATORS:-320}"
export GENESIS_FORK_VERSION="${GENESIS_FORK_VERSION:-0x10000000}"
export ALTAIR_FORK_VERSION="${ALTAIR_FORK_VERSION:-0x20000000}"
export BELLATRIX_FORK_VERSION="${BELLATRIX_FORK_VERSION:-0x30000000}"
export CAPELLA_FORK_VERSION="${CAPELLA_FORK_VERSION:-0x40000000}"
export DENEB_FORK_VERSION="${DENEB_FORK_VERSION:-0x50000000}"
export ELECTRA_FORK_VERSION="${ELECTRA_FORK_VERSION:-0x60000000}"
export ELECTRA_FORK_EPOCH="${ELECTRA_FORK_EPOCH:-2000}"
export EIP7594_FORK_VERSION="${EIP7594_FORK_VERSION:-0x70000000}"
export EIP7594_FORK_EPOCH="${EIP7594_FORK_EPOCH:-99999}"
export WITHDRAWAL_TYPE="${WITHDRAWAL_TYPE:-0x00}"
export WITHDRAWAL_ADDRESS="${WITHDRAWAL_ADDRESS:-0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134}"
export BEACON_STATIC_ENR="${BEACON_STATIC_ENR:-enr:-Iq4QJk4WqRkjsX5c2CXtOra6HnxN-BMXnWhmhEQO9Bn9iABTJGdjUOurM7Btj1ouKaFkvTRoju5vz2GPmVON2dffQKGAX53x8JigmlkgnY0gmlwhLKAlv6Jc2VjcDI1NmsxoQK6S-Cii_KmfFdUJL2TANL3ksaKUnNXvTCv1tLwXs0QgIN1ZHCCIyk}"
export SHADOW_FORK_RPC="${SHADOW_FORK_RPC:-}" # http://docker.for.mac.localhost:8545
export SHADOW_FORK_FILE="${SHADOW_FORK_FILE:-}" # /config/el/latest_block.json
export GENESIS_TIMESTAMP="${GENESIS_TIMESTAMP:-0}"
export GENESIS_DELAY="${GENESIS_DELAY:-60}"
export GENESIS_GASLIMIT="${GENESIS_GASLIMIT:-25000000}"
export MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT="${MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT:-8}"
export CHURN_LIMIT_QUOTIENT="${CHURN_LIMIT_QUOTIENT:-65536}"
export EJECTION_BALANCE="${EJECTION_BALANCE:-16000000000}"
export ETH1_FOLLOW_DISTANCE="${ETH1_FOLLOW_DISTANCE:-2048}"
export MIN_VALIDATOR_WITHDRAWABILITY_DELAY="${MIN_VALIDATOR_WITHDRAWABILITY_DELAY:-256}"
export SHARD_COMMITTEE_PERIOD="${SHARD_COMMITTEE_PERIOD:-256}"
export SAMPLES_PER_SLOT="${SAMPLES_PER_SLOT:-8}"
export CUSTODY_REQUIREMENT="${CUSTODY_REQUIREMENT:-1}"
export DATA_COLUMN_SIDECAR_SUBNET_COUNT="${DATA_COLUMN_SIDECAR_SUBNET_COUNT:-32}"
export TARGET_NUMBER_OF_PEERS="${TARGET_NUMBER_OF_PEERS:-70}"
export EL_PREMINE_ADDRS="${EL_PREMINE_ADDRS:-{}}"
export ADDITIONAL_PRELOADED_CONTRACTS="${ADDITIONAL_PRELOADED_CONTRACTS:-{}}" # '{"0x123463a4B065722E99115D6c222f267d9cABb524": {"balance": "1ETH","code": "0x123465","storage": {},"nonce": 0,"secretKey": "0x"}}'
41 changes: 0 additions & 41 deletions config-example/values.env

This file was deleted.

62 changes: 32 additions & 30 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash -e
source /config/values.env
eval "$(cat < /config/defaults.env)"
if [ -f /config/values.env ];
then
source /config/values.env
fi
SERVER_ENABLED="${SERVER_ENABLED:-false}"
SERVER_PORT="${SERVER_PORT:-8000}"
WITHDRAWAL_ADDRESS="${WITHDRAWAL_ADDRESS:-0xf97e180c050e5Ab072211Ad2C213Eb5AEE4DF134}"
Expand All @@ -8,27 +12,27 @@ gen_shared_files(){
. /apps/el-gen/.venv/bin/activate
set -x
# Shared files
mkdir -p /data/custom_config_data
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/custom_config_data/genesis.json" ]; then
terminalTotalDifficulty=$(cat /data/custom_config_data/genesis.json | jq -r '.config.terminalTotalDifficulty | tostring')
sed -i "s/TERMINAL_TOTAL_DIFFICULTY:.*/TERMINAL_TOTAL_DIFFICULTY: $terminalTotalDifficulty/" /data/custom_config_data/config.yaml
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/custom_config_data/genesis.json" ]; then
if ! [ -f "/data/metadata/genesis.json" ]; then
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
mkdir -p /data/custom_config_data
mkdir -p /data/metadata
envsubst < /config/el/genesis-config.yaml > $tmp_dir/genesis-config.yaml
python3 /apps/el-gen/genesis_geth.py $tmp_dir/genesis-config.yaml > /data/custom_config_data/genesis.json
python3 /apps/el-gen/genesis_chainspec.py $tmp_dir/genesis-config.yaml > /data/custom_config_data/chainspec.json
python3 /apps/el-gen/genesis_besu.py $tmp_dir/genesis-config.yaml > /data/custom_config_data/besu.json
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
Expand All @@ -45,39 +49,37 @@ gen_minimal_config() {
)

for key in "${!replacements[@]}"; do
sed -i "s/$key:.*/$key: ${replacements[$key]}/" /data/custom_config_data/config.yaml
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/custom_config_data/genesis.ssz" ]; then
if ! [ -f "/data/metadata/genesis.ssz" ]; then
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
mkdir -p /data/custom_config_data
envsubst < /config/cl/config.yaml > /data/custom_config_data/config.yaml
mkdir -p /data/metadata
envsubst < /config/cl/config.yaml > /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/custom_config_data/mnemonics.yaml
cp $tmp_dir/mnemonics.yaml /data/metadata/mnemonics.yaml
# Create deposit_contract.txt and deploy_block.txt
grep DEPOSIT_CONTRACT_ADDRESS /data/custom_config_data/config.yaml | cut -d " " -f2 > /data/custom_config_data/deposit_contract.txt
echo $CL_EXEC_BLOCK > /data/custom_config_data/deploy_block.txt
echo $CL_EXEC_BLOCK > /data/custom_config_data/deposit_contract_block.txt
echo $BEACON_STATIC_ENR > /data/custom_config_data/bootstrap_nodes.txt
echo "- $BEACON_STATIC_ENR" > /data/custom_config_data/boot_enr.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/custom_config_data/config.yaml
--config /data/metadata/config.yaml
--mnemonics $tmp_dir/mnemonics.yaml
--tranches-dir /data/custom_config_data/tranches
--state-output /data/custom_config_data/genesis.ssz
--tranches-dir /data/metadata/tranches
--state-output /data/metadata/genesis.ssz
--preset-phase0 $PRESET_BASE
--preset-altair $PRESET_BASE
--preset-bellatrix $PRESET_BASE
Expand All @@ -92,7 +94,7 @@ gen_cl_config(){
elif [[ $SHADOW_FORK_RPC != "" ]]; then
genesis_args+=(--shadow-fork-eth1-rpc=$SHADOW_FORK_RPC --eth1-config "")
else
genesis_args+=(--eth1-config /data/custom_config_data/genesis.json)
genesis_args+=(--eth1-config /data/metadata/genesis.json)
fi
if ! [ -z "$CL_ADDITIONAL_VALIDATORS" ]; then
if [[ $CL_ADDITIONAL_VALIDATORS = /* ]]; then
Expand All @@ -111,15 +113,15 @@ gen_cl_config(){
--preset-bellatrix $PRESET_BASE
--preset-capella $PRESET_BASE
--preset-deneb $PRESET_BASE
/data/custom_config_data/genesis.ssz
/data/metadata/genesis.ssz
)
/usr/local/bin/eth2-testnet-genesis "${genesis_args[@]}"
/usr/local/bin/zcli "${zcli_args[@]}" > /data/custom_config_data/parsedBeaconState.json
/usr/local/bin/zcli "${zcli_args[@]}" > /data/metadata/parsedBeaconState.json
echo "Genesis args: ${genesis_args[@]}"
echo "Genesis block number: $(jq -r '.latest_execution_payload_header.block_number' /data/custom_config_data/parsedBeaconState.json)"
echo "Genesis block hash: $(jq -r '.latest_execution_payload_header.block_hash' /data/custom_config_data/parsedBeaconState.json)"
jq -r '.eth1_data.block_hash' /data/custom_config_data/parsedBeaconState.json | tr -d '\n' > /data/custom_config_data/deposit_contract_block_hash.txt
jq -r '.genesis_validators_root' /data/custom_config_data/parsedBeaconState.json | tr -d '\n' > /data/custom_config_data/genesis_validators_root.txt
echo "Genesis block number: $(jq -r '.latest_execution_payload_header.block_number' /data/metadata/parsedBeaconState.json)"
echo "Genesis block hash: $(jq -r '.latest_execution_payload_header.block_hash' /data/metadata/parsedBeaconState.json)"
jq -r '.eth1_data.block_hash' /data/metadata/parsedBeaconState.json | tr -d '\n' > /data/metadata/deposit_contract_block_hash.txt
jq -r '.genesis_validators_root' /data/metadata/parsedBeaconState.json | tr -d '\n' > /data/metadata/genesis_validators_root.txt
else
echo "cl genesis already exists. skipping generation..."
fi
Expand Down