Skip to content

Commit

Permalink
fix: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Jan 8, 2025
1 parent 01271d4 commit 04c526b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 31 deletions.
29 changes: 27 additions & 2 deletions spartan/aztec-network/eth-devnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,37 @@

## Args

TODO:
Args can be supplied via environment variables.

- add the deployment mnemonic etc
### NUMBER_OF_KEYS

This determines the number of accounts that will be prefunded with eth on the execution layer.

### MNEMONIC

The seed phrase from which the keys will be derived.

### BLOCK_TIME

The time in seconds between blocks.

### GAS_LIMIT

The gas limit for the execution layer.

### CHAIN_ID

The chain id for the execution layer.

---

## Common Pitfalls

If you are struggling to get the network up and running, it is usually due to the genesis.json file having different values from the config.yaml + genesis.ssz file. Make sure that you do not edit any of them by accident after ./create.sh is run.
Note that this script places the configuration values within the /out folder, it will not actually run the testnet.

SSZ files are not passable thorugh config maps, so they must be base64 encoded, then decoded in the container before running.

Generating an Ethereum testnet requires a few ingredients:

## Genesis.json file
Expand Down
56 changes: 27 additions & 29 deletions spartan/aztec-network/eth-devnet/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set -euo pipefail

REPO=$(git rev-parse --show-toplevel)/spartan/aztec-network/eth-devnet
DIR_PATH=$(git rev-parse --show-toplevel)/spartan/aztec-network/eth-devnet

## Genesis configuration values are provided as environment variables
NUMBER_OF_KEYS=${NUMBER_OF_KEYS:-16}
Expand Down Expand Up @@ -88,36 +88,36 @@ prefund_accounts() {
# Uses the eth2-testnet-generator to generate beacon genesis state (genesis.ssz file)
# The selected eth1 block
create_beacon_genesis() {
local mnemonics_path="$1"
local beacon_config_path="$2"
local execution_genesis_path="$3"
local execution_genesis_path="$1"
local beacon_mnemonics_path="./config/mnemonics.yaml"
local beacon_config_path="./config/config.yaml"
local beacon_genesis_path="./out"

echo "Creating beacon genesis using:"
echo " Mnemonics path: $mnemonics_path"
echo " Beacon mnemonics path: $beacon_mnemonics_path"
echo " Beacon config path: $beacon_config_path"
echo " Execution genesis path: $execution_genesis_path"

# update the templates block time if it is provided
cp "$REPO/$beacon_config_path" "$REPO/out/config.yaml"
cp "$DIR_PATH/$beacon_config_path" "$DIR_PATH/out/config.yaml"
if [[ -n "${BLOCK_TIME:-}" ]]; then
yq eval ".SECONDS_PER_SLOT = ${BLOCK_TIME}" -i "$REPO/out/config.yaml"
yq eval ".SECONDS_PER_ETH1_BLOCK = ${BLOCK_TIME}" -i "$REPO/out/config.yaml"
yq eval ".SECONDS_PER_SLOT = ${BLOCK_TIME}" -i "$DIR_PATH/out/config.yaml"
yq eval ".SECONDS_PER_ETH1_BLOCK = ${BLOCK_TIME}" -i "$DIR_PATH/out/config.yaml"
fi

# Update the chain id if it is provided
if [[ -n "${CHAIN_ID:-}" ]]; then
yq eval ".DEPOSIT_CHAIN_ID = ${CHAIN_ID}" -i "$REPO/out/config.yaml"
yq eval ".DEPOSIT_NETWORK_ID = ${CHAIN_ID}" -i "$REPO/out/config.yaml"
yq eval ".DEPOSIT_CHAIN_ID = ${CHAIN_ID}" -i "$DIR_PATH/out/config.yaml"
yq eval ".DEPOSIT_NETWORK_ID = ${CHAIN_ID}" -i "$DIR_PATH/out/config.yaml"
fi

# Run the protolamba's eth2 testnet genesis container
echo "$REPO/config:/app/config"
echo "$REPO/out:/app/out"
echo "$DIR_PATH/config:/app/config"
echo "$DIR_PATH/out:/app/out"

docker run --rm \
-v "$REPO/config:/app/config" \
-v "$REPO/out:/app/out" \
-v "$DIR_PATH/config:/app/config" \
-v "$DIR_PATH/out:/app/out" \
maddiaa/eth2-testnet-genesis deneb \
--config="./out/config.yaml" \
--preset-phase0=minimal \
Expand All @@ -128,7 +128,7 @@ create_beacon_genesis() {
--eth1-config="./out/genesis.json" \
--state-output="${beacon_genesis_path}/genesis.ssz" \
--tranches-dir="$beacon_genesis_path" \
--mnemonics="$mnemonics_path" \
--mnemonics="$beacon_mnemonics_path" \
--eth1-withdrawal-address="0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
--eth1-match-genesis-time

Expand All @@ -141,31 +141,29 @@ create_beacon_genesis() {
}

create_deposit_contract_block() {
echo 0 > "$REPO/out/deposit_contract_block.txt"
echo "Deposit contract block created at $REPO/out/deposit_contract_block.txt"
echo 0 > "$DIR_PATH/out/deposit_contract_block.txt"
echo "Deposit contract block created at $DIR_PATH/out/deposit_contract_block.txt"
}

## The ssz file must be written in base64 in order for a config map to accept it
write_ssz_file_base64() {
local ssz_file="$REPO/out/genesis.ssz"
local output_file="$REPO/out/genesis-ssz"
local ssz_file="$DIR_PATH/out/genesis.ssz"
local output_file="$DIR_PATH/out/genesis-ssz"
base64 -w 0 "$ssz_file" > "$output_file"
echo "SSZ file base64 encoded at $output_file"
}

# Main
beacon_config_path="$DIR_PATH/config/config.yaml"
genesis_json_path="$DIR_PATH/config/genesis.json"

# TODO: FIX THIS Files are relative to the mounted repo
mnemonics_path="./config/mnemonics.yaml"
beacon_config_path="./config/config.yaml"
execution_genesis_path="./config/genesis.json"

mkdir -p "$REPO/out"
mkdir -p "$DIR_PATH/out"

create_execution_genesis "$REPO/config/genesis.json" "$REPO/out/genesis.json"
create_beacon_genesis "$mnemonics_path" "$beacon_config_path" "$REPO/out/genesis.json"
create_execution_genesis "$DIR_PATH/config/genesis.json" "$DIR_PATH/out/genesis.json"
create_beacon_genesis "$DIR_PATH/out/genesis.json"
create_deposit_contract_block
write_ssz_file_base64

cp "$REPO/$beacon_config_path" "$REPO/out/config.yaml"
cp "$REPO/config/jwt-secret.hex" "$REPO/out/jwt-secret.hex"
cp "$beacon_config_path" "$DIR_PATH/out/config.yaml"
cp "$DIR_PATH/config/jwt-secret.hex" "$DIR_PATH/out/jwt-secret.hex"
echo "Genesis files copied to ./out"

0 comments on commit 04c526b

Please sign in to comment.