#!/bin/bash set -exu set -o pipefail # Check if jq is installed if ! command -v jq &> /dev/null; then echo "Error: jq is not installed. Please install jq first." exit 1 fi # Check if curl is installed if ! command -v curl &> /dev/null; then echo "Error: curl is not installed. Please install curl first." exit 1 fi # NETWORK_DIR is where all files for the testnet will be stored, # including logs and storage i=1 NETWORK_DIR=./network NODE_DIR=$NETWORK_DIR/node-$i NUM_NODES=2 PRYSM_BEACON_RPC_PORT=4000 PRYSM_BEACON_GRPC_GATEWAY_PORT=4100 PRYSM_BEACON_P2P_TCP_PORT=4200 PRYSM_BEACON_P2P_UDP_PORT=4300 PRYSM_BEACON_MONITORING_PORT=4400 GETH_AUTH_RPC_PORT=8200 trap 'echo "Error on line $LINENO"; exit 1' ERR # Function to handle the cleanup cleanup() { echo "Caught Ctrl+C. Killing active background processes and exiting." kill $(jobs -p) # Kills all background processes started in this script exit } # Trap the SIGINT signal and call the cleanup function when it's caught trap 'cleanup' SIGINT PRYSM_BEACON_BINARY=./dependencies/prysm/out/beacon-chain # If PRYSM_BOOTSTRAP_NODE is not set, execute the command and capture the result into the variable # This allows subsequent nodes to discover the first node, treating it as the bootnode PRYSM_BOOTSTRAP_NODE=$(curl -s localhost:4100/eth/v1/node/identity | jq -r '.data.enr') # Check if the result starts with enr if [[ $PRYSM_BOOTSTRAP_NODE == enr* ]]; then echo "PRYSM_BOOTSTRAP_NODE is valid: $PRYSM_BOOTSTRAP_NODE" else echo "PRYSM_BOOTSTRAP_NODE does NOT start with enr" exit 1 fi # Calculate how many nodes to wait for to be in sync with. Not a hard rule MIN_SYNC_PEERS=$((NUM_NODES/2)) echo $MIN_SYNC_PEERS is minimum number of synced peers required # Start prysm consensus client for this node $PRYSM_BEACON_BINARY \ --datadir=$NODE_DIR/consensus/beacondata \ --min-sync-peers=$MIN_SYNC_PEERS \ --genesis-state=$NODE_DIR/consensus/genesis.ssz \ --bootstrap-node=$PRYSM_BOOTSTRAP_NODE \ --interop-eth1data-votes \ --chain-config-file=$NODE_DIR/consensus/config.yml \ --contract-deployment-block=0 \ --chain-id=${CHAIN_ID:-210597} \ --rpc-host=0.0.0.0 \ --rpc-port=$((PRYSM_BEACON_RPC_PORT + i)) \ --grpc-gateway-host=0.0.0.0 \ --grpc-gateway-port=$((PRYSM_BEACON_GRPC_GATEWAY_PORT + i)) \ --execution-endpoint=http://localhost:$((GETH_AUTH_RPC_PORT + i)) \ --accept-terms-of-use \ --jwt-secret=$NODE_DIR/execution/jwtsecret \ --suggested-fee-recipient=0x9B4c5629199C5456C8bCEBd3d7F84fF23da9336e \ --minimum-peers-per-subnet=0 \ --p2p-tcp-port=$((PRYSM_BEACON_P2P_TCP_PORT + i)) \ --p2p-udp-port=$((PRYSM_BEACON_P2P_UDP_PORT + i)) \ --monitoring-port=$((PRYSM_BEACON_MONITORING_PORT + i)) \ --verbosity=info \ --slasher \ --enable-debug-rpc-endpoints > "$NODE_DIR/logs/beacon.log"