diff --git a/compose/docker-compose-fixturenet-eth.yml b/compose/docker-compose-fixturenet-eth.yml index ad79814c..00377d21 100644 --- a/compose/docker-compose-fixturenet-eth.yml +++ b/compose/docker-compose-fixturenet-eth.yml @@ -8,9 +8,6 @@ services: environment: RUN_BOOTNODE: "true" image: cerc/fixturenet-eth-geth:local - networks: - fixturenet-eth-net: - ipv4_address: 172.16.254.10 fixturenet-eth-geth-1: hostname: fixturenet-eth-geth-1 @@ -21,8 +18,6 @@ services: - fixturenet-eth-bootnode-geth ports: - "8545" - networks: - fixturenet-eth-net: fixturenet-eth-geth-2: hostname: fixturenet-eth-geth-2 @@ -31,17 +26,12 @@ services: image: cerc/fixturenet-eth-geth:local depends_on: - fixturenet-eth-bootnode-geth - networks: - fixturenet-eth-net: fixturenet-eth-bootnode-lighthouse: hostname: fixturenet-eth-bootnode-lighthouse environment: RUN_BOOTNODE: "true" image: cerc/fixturenet-eth-lighthouse:local - networks: - fixturenet-eth-net: - ipv4_address: 172.16.254.11 fixturenet-eth-lighthouse-1: hostname: fixturenet-eth-lighthouse-1 @@ -57,8 +47,6 @@ services: - fixturenet-eth-geth-1 ports: - "8001" - networks: - fixturenet-eth-net: fixturenet-eth-lighthouse-2: hostname: fixturenet-eth-lighthouse-2 @@ -73,14 +61,3 @@ services: depends_on: - fixturenet-eth-bootnode-lighthouse - fixturenet-eth-geth-2 - networks: - fixturenet-eth-net: - -networks: - # When the bootnode ENR is generated during the build, it requires a specific IP. - # The easiest way to do that is to use a private network. - fixturenet-eth-net: - driver: bridge - ipam: - config: - - subnet: 172.16.254.0/28 diff --git a/config/fixturenet-eth/fixturenet-eth.env b/config/fixturenet-eth/fixturenet-eth.env index c4088e69..8cb2bf4b 100644 --- a/config/fixturenet-eth/fixturenet-eth.env +++ b/config/fixturenet-eth/fixturenet-eth.env @@ -7,5 +7,4 @@ ENODE="enode://af22c29c316ad069cf48a09a4ad5cf04a251b411e45098888d114c6dd7f489a13 # JWT shared by geth and lighthouse for authentication. JWT="0x6cdcac3501046a08e186730dd8bd136cfaf0fdc1fc955f6e15ad3068c0ff2af0" -# Should match the definition of fixturenet-eth-net. -NETRESTRICT="172.16.254.0/28" +ENR_URL="http://fixturenet-eth-bootnode-lighthouse:3000/bootnode/enr.dat" diff --git a/container-build/cerc-fixturenet-eth-geth/genesis/accounts/mnemonic_to_csv.py b/container-build/cerc-fixturenet-eth-geth/genesis/accounts/mnemonic_to_csv.py index 730426bd..365c3775 100644 --- a/container-build/cerc-fixturenet-eth-geth/genesis/accounts/mnemonic_to_csv.py +++ b/container-build/cerc-fixturenet-eth-geth/genesis/accounts/mnemonic_to_csv.py @@ -12,6 +12,6 @@ if len(sys.argv) > 1: with open(testnet_config_path) as stream: data = yaml.safe_load(stream) -for key, value in data['eth1_premine'].items(): +for key, value in data['el_premine'].items(): acct = w3.eth.account.from_mnemonic(data['mnemonic'], account_path=key, passphrase='') print("%s,%s,%s" % (key, acct.address, acct.key.hex())) diff --git a/container-build/cerc-fixturenet-eth-geth/genesis/el/build_el.sh b/container-build/cerc-fixturenet-eth-geth/genesis/el/build_el.sh index 5eeeba51..0070707d 100755 --- a/container-build/cerc-fixturenet-eth-geth/genesis/el/build_el.sh +++ b/container-build/cerc-fixturenet-eth-geth/genesis/el/build_el.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e # See: https://github.com/skylenet/ethereum-genesis-generator/blob/master/entrypoint.sh @@ -8,5 +9,7 @@ mkdir -p ../build/el tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) envsubst < el-config.yaml > $tmp_dir/genesis-config.yaml -python3 /apps/el-gen/genesis_geth.py $tmp_dir/genesis-config.yaml > ../build/el/geth.json +ttd=`cat $tmp_dir/genesis-config.yaml | grep terminal_total_difficulty | awk '{ print $2 }'` + +python3 /apps/el-gen/genesis_geth.py $tmp_dir/genesis-config.yaml | jq ".config.terminalTotalDifficulty=$ttd" > ../build/el/geth.json python3 ../accounts/mnemonic_to_csv.py $tmp_dir/genesis-config.yaml > ../build/el/accounts.csv diff --git a/container-build/cerc-fixturenet-eth-geth/genesis/el/el-config.yaml b/container-build/cerc-fixturenet-eth-geth/genesis/el/el-config.yaml index 7beb9c80..ed8d4885 100644 --- a/container-build/cerc-fixturenet-eth-geth/genesis/el/el-config.yaml +++ b/container-build/cerc-fixturenet-eth-geth/genesis/el/el-config.yaml @@ -1,17 +1,16 @@ mnemonic: "viable ketchup woman library opinion copy rhythm attend rose knock penalty practice photo bundle budget dentist enter round bind holiday useful arch danger lobster" -eth1_premine: +el_premine: "m/44'/60'/0'/0/0": 10000000ETH "m/44'/60'/0'/0/1": 10000000ETH "m/44'/60'/0'/0/2": 10000000ETH "m/44'/60'/0'/0/3": 10000000ETH "m/44'/60'/0'/0/4": 10000000ETH "m/44'/60'/0'/0/5": 10000000ETH -eth1_premine_addrs: {} +el_premine_addrs: {} chain_id: 1212 deposit_contract_address: "0x1212121212121212121212121212121212121212" -eth1_genesis_timestamp: 0 -terminal_total_difficulty: 10000000 -mergeForkBlock: 100 +genesis_timestamp: 0 +terminal_total_difficulty: 1000 clique: enabled: false diff --git a/container-build/cerc-fixturenet-eth-geth/run-el.sh b/container-build/cerc-fixturenet-eth-geth/run-el.sh index 84ff72f4..b6d0ce83 100755 --- a/container-build/cerc-fixturenet-eth-geth/run-el.sh +++ b/container-build/cerc-fixturenet-eth-geth/run-el.sh @@ -2,6 +2,7 @@ ETHERBASE=`cat /opt/testnet/build/el/accounts.csv | head -1 | cut -d',' -f2` NETWORK_ID=`cat /opt/testnet/el/el-config.yaml | grep 'chain_id' | awk '{ print $2 }'` +NETRESTRICT=`ip addr | grep inet | grep -v '127.0' | awk '{print $2}'` if [ "true" == "$RUN_BOOTNODE" ]; then geth \ @@ -29,6 +30,9 @@ else --authrpc.jwtsecret="/opt/testnet/build/el/jwtsecret" \ --networkid=${NETWORK_ID} \ --netrestrict="${NETRESTRICT}" \ + --gcmode archive \ + --txlookuplimit=0 \ + --cache.preimages \ --syncmode=full \ --mine \ --miner.threads=1 \ diff --git a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh index 026d40e1..6fa1d8d4 100755 --- a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh +++ b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/beacon_node.sh @@ -10,7 +10,7 @@ set -Eeuo pipefail source ./vars.env SUBSCRIBE_ALL_SUBNETS= -DEBUG_LEVEL=${DEBUG_LEVEL:-info} +DEBUG_LEVEL=${DEBUG_LEVEL:-debug} # Get positional arguments data_dir=$DATADIR/node_${NODE_NUMBER} @@ -18,9 +18,6 @@ network_port=9001 http_port=8001 authrpc_port=8551 -ENR=`cat $DATADIR/bootnode/enr.dat` -ENR_IP=`ip addr | grep 172 | awk '{print $2}' | cut -d '/' -f1` - exec lighthouse \ --debug-level $DEBUG_LEVEL \ bn \ diff --git a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh index 50d460fc..f6f5cc73 100755 --- a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh +++ b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/bootnode.sh @@ -13,6 +13,22 @@ DEBUG_LEVEL=${1:-info} echo "Starting bootnode" +if [ ! -f "$DATADIR/bootnode/enr.dat" ]; then + echo "Generating bootnode enr" + lcli \ + generate-bootnode-enr \ + --ip $ENR_IP \ + --udp-port $BOOTNODE_PORT \ + --tcp-port $BOOTNODE_PORT \ + --genesis-fork-version $GENESIS_FORK_VERSION \ + --output-dir $DATADIR/bootnode + + bootnode_enr=`cat $DATADIR/bootnode/enr.dat` + echo "- $bootnode_enr" > $TESTNET_DIR/boot_enr.yaml + + echo "Generated bootnode enr and written to $TESTNET_DIR/boot_enr.yaml" +fi + exec lighthouse boot_node \ --testnet-dir $TESTNET_DIR \ --port $BOOTNODE_PORT \ diff --git a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/build_cl.sh b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/build_cl.sh index 32b3e6f4..92018d7a 100755 --- a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/build_cl.sh +++ b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/build_cl.sh @@ -57,18 +57,3 @@ lcli \ $GENESIS_VALIDATOR_COUNT echo Created genesis state in $TESTNET_DIR - -echo "Generating bootnode enr" - -lcli \ - generate-bootnode-enr \ - --ip $BOOTNODE_IP \ - --udp-port $BOOTNODE_PORT \ - --tcp-port $BOOTNODE_PORT \ - --genesis-fork-version $GENESIS_FORK_VERSION \ - --output-dir $DATADIR/bootnode - -bootnode_enr=`cat $DATADIR/bootnode/enr.dat` -echo "- $bootnode_enr" > $TESTNET_DIR/boot_enr.yaml - -echo "Generated bootnode enr and written to $TESTNET_DIR/boot_enr.yaml" diff --git a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/vars.env b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/vars.env index b7e2a939..d68cbdcc 100644 --- a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/vars.env +++ b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/vars.env @@ -4,6 +4,8 @@ DATADIR=${DATADIR:-../build/cl} # Directory for the eth2 config TESTNET_DIR=${TESTNET_DIR:-$DATADIR/testnet} JWTSECRET=${JWTSECRET:-$DATADIR/jwtsecret} +ENR=${ENR:="SET_AT_RUNTIME"} +ENR_IP=`ip addr | grep inet | grep -v '127.0.0.1' | sort | head -1 | awk '{print $2}' | cut -d '/' -f1` GENESIS_FORK_VERSION=${GENESIS_FORK_VERSION:-0x12121212} @@ -22,12 +24,11 @@ VC_COUNT=${VC_COUNT:-$BN_COUNT} GENESIS_DELAY=${GENESIS_DELAY:-0} # Port for P2P communication with bootnode -BOOTNODE_IP=${BOOTNODE_IP:-172.16.254.11} BOOTNODE_PORT=${BOOTNODE_PORT:-4242} # Hard fork configuration -ALTAIR_FORK_EPOCH=${ALTAIR_FORK_EPOCH:-1} -MERGE_FORK_EPOCH=${MERGE_FORK_EPOCH:-2} +ALTAIR_FORK_EPOCH=${ALTAIR_FORK_EPOCH:-0} +MERGE_FORK_EPOCH=${MERGE_FORK_EPOCH:-0} # Spec version (mainnet or minimal) SPEC_PRESET=${SPEC_PRESET:-mainnet} @@ -43,10 +44,11 @@ VC_ARGS=${VC_ARGS:-""} EXECUTION_ENDPOINT=${EXECUTION_ENDPOINT:-http://localhost:8551} +ETH1_GENESIS_JSON=${ETH1_GENESIS_JSON:-"../build/el/geth.json"} ETH1_CONFIG_YAML=${ETH1_CONFIG_YAML:-"../el/el-config.yaml"} -ETH1_CHAIN_ID=${ETH1_CHAIN_ID:-`cat $ETH1_CONFIG_YAML | grep 'chain_id' | awk '{ print $2 }'`} -ETH1_TTD=${ETH1_TTD:-`cat $ETH1_CONFIG_YAML | grep 'terminal_total_difficulty' | awk '{ print $2 }'`} +ETH1_CHAIN_ID=${ETH1_CHAIN_ID:-`cat $ETH1_GENESIS_JSON | jq -r '.config.chainId'`} +ETH1_TTD=${ETH1_TTD:-`cat $ETH1_GENESIS_JSON | jq -r '.config.terminalTotalDifficulty'`} ETH1_DEPOSIT_CONTRACT_ADDRESS=${ETH1_DEPOSIT_CONTRACT_ADDRESS:-`cat $ETH1_CONFIG_YAML | grep 'deposit_contract_address' | awk '{ print $2 }' | sed 's/"//g'`} ETH1_DEPOSIT_CONTRACT_BLOCK=${ETH1_DEPOSIT_CONTRACT_BLOCK:-0x0} SUGGESTED_FEE_RECIPIENT=`cat ../build/el/accounts.csv | head -1 | cut -d',' -f2` diff --git a/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh b/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh index 9e7c653e..07346e58 100755 --- a/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh +++ b/container-build/cerc-fixturenet-eth-lighthouse/run-cl.sh @@ -1,18 +1,22 @@ #!/bin/bash if [ "true" == "$RUN_BOOTNODE" ]; then + cd /opt/testnet/build/cl + python3 -m http.server 3000 & + + cd /opt/testnet/cl ./bootnode.sh 2>&1 | tee /var/log/lighthouse_bootnode.log else while [ 1 -eq 1 ]; do - echo "Waiting on DAG ..." + echo "Waiting on geth ..." sleep 5 result=`wget --no-check-certificate --quiet \ -O - \ --method POST \ --timeout=0 \ --header 'Content-Type: application/json' \ - --body-data '{ "jsonrpc": "2.0", "id": 1, "method": "eth_getBlockByNumber", "params": ["0x3", false] }' "${ETH1_ENDPOINT:-localhost:8545}" | jq -r '.result'` + --body-data '{ "jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": [] }' "${ETH1_ENDPOINT:-localhost:8545}" | jq -r '.result'` if [ ! -z "$result" ] && [ "null" != "$result" ]; then break fi @@ -34,6 +38,18 @@ else done fi + if [ ! -z "$ENR_URL" ]; then + while [ 1 -eq 1 ]; do + echo "Waiting on ENR for boot node..." + sleep 5 + result=`wget --no-check-certificate --quiet -O - --timeout=0 $ENR_URL` + if [ ! -z "$result" ]; then + export ENR="$result" + break; + fi + done + fi + export JWTSECRET="/opt/testnet/build/cl/jwtsecret" echo -n "$JWT" > $JWTSECRET diff --git a/container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh b/container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh new file mode 100755 index 00000000..e02fc14b --- /dev/null +++ b/container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +STATUSES=("geth to generate DAG" "beacon phase0" "beacon altair" "beacon bellatrix pre-merge" "beacon bellatrix merge") +STATUS=0 + + +LIGHTHOUSE_BASE_URL=${LIGHTHOUSE_BASE_URL} +GETH_BASE_URL=${GETH_BASE_URL} + +if [ -z "$LIGHTHOUSE_BASE_URL" ]; then + LIGHTHOUSE_PORT=`docker ps -f "name=fixturenet-eth-lighthouse-1-1" --format "{{.Ports}}" | head -1 | cut -d':' -f2 | cut -d'-' -f1` + LIGHTHOUSE_BASE_URL="http://localhost:${LIGHTHOUSE_PORT}" +fi + +if [ -z "$GETH_BASE_URL" ]; then + GETH_PORT=`docker ps -f "name=fixturenet-eth-geth-1-1" --format "{{.Ports}}" | head -1 | cut -d':' -f2 | cut -d'-' -f1` + GETH_BASE_URL="http://localhost:${GETH_PORT}" +fi + +function inc_status() { + echo " DONE!" + STATUS=$((STATUS + 1)) + if [ $STATUS -lt ${#STATUSES[@]} ]; then + echo -n "Waiting for ${STATUSES[$STATUS]}..." + fi +} + +echo -n "Waiting for ${STATUSES[$STATUS]}..." +while [ $STATUS -lt ${#STATUSES[@]} ]; do + sleep 1 + echo -n "." + case $STATUS in + 0) + result=`wget --no-check-certificate --quiet -O - --method POST --header 'Content-Type: application/json' \ + --body-data '{ "jsonrpc": "2.0", "id": 1, "method": "eth_getBlockByNumber", "params": ["0x3", false] }' $GETH_BASE_URL | jq -r '.result'` + if [ ! -z "$result" ] && [ "null" != "$result" ]; then + inc_status + fi + ;; + 1) + result=`wget --no-check-certificate --quiet -O - "$LIGHTHOUSE_BASE_URL/eth/v2/beacon/blocks/head" | jq -r '.data.message.slot'` + if [ ! -z "$result" ] && [ $result -gt 0 ]; then + inc_status + fi + ;; + 2) + result=`wget --no-check-certificate --quiet -O - "$LIGHTHOUSE_BASE_URL/eth/v2/beacon/blocks/head" | jq -r '.version'` + if [ ! -z "$result" ] && ([ "$result" == "altair" ] || [ "$result" == "bellatrix" ]); then + inc_status + fi + ;; + 3) + result=`wget --no-check-certificate --quiet -O - "$LIGHTHOUSE_BASE_URL/eth/v2/beacon/blocks/head" | jq -r '.version'` + if [ ! -z "$result" ] && [ "$result" == "bellatrix" ]; then + inc_status + fi + ;; + 4) + result=`wget --no-check-certificate --quiet -O - "$LIGHTHOUSE_BASE_URL/eth/v2/beacon/blocks/head" | jq -r '.data.message.body.execution_payload.block_number'` + if [ ! -z "$result" ] && [ $result -gt 0 ]; then + inc_status + fi + ;; + esac +done