#!/bin/bash set -eo pipefail # Read in variables # shellcheck source=/dev/null source "$(dirname "$0")/vars.sh" cd "$SIM_ROOT" mkdir -p "$SIMULATION_DIR" mkdir -p "$VALIDATORS_DIR" cd "$GIT_ROOT" CUSTOM_NIMFLAGS="${NIMFLAGS} -d:chronicles_sinks:textlines,json[file]" # Run with "SLOTS_PER_EPOCH=8 ./start.sh" to change these DEFS="" DEFS+="-d:MAX_COMMITTEES_PER_SLOT=${MAX_COMMITTEES_PER_SLOT:-1} " # Spec default: 64 DEFS+="-d:SLOTS_PER_EPOCH=${SLOTS_PER_EPOCH:-6} " # Spec default: 32 DEFS+="-d:SECONDS_PER_SLOT=${SECONDS_PER_SLOT:-6} " # Spec default: 12 LAST_VALIDATOR_NUM=$(( NUM_VALIDATORS - 1 )) LAST_VALIDATOR="$VALIDATORS_DIR/v$(printf '%07d' $LAST_VALIDATOR_NUM).deposit.json" # Windows detection if uname | grep -qiE "mingw|msys"; then MAKE="mingw32-make" EXE_SUFFIX=".exe" else MAKE="make" EXE_SUFFIX="" fi build_beacon_node () { OUTPUT_BIN=$1; shift PARAMS="$CUSTOM_NIMFLAGS $DEFS $@" echo "Building $OUTPUT_BIN ($PARAMS)" $MAKE NIMFLAGS="-o:$OUTPUT_BIN $PARAMS" LOG_LEVEL="${LOG_LEVEL:-DEBUG}" beacon_node } build_beacon_node $BEACON_NODE_BIN -d:"NETWORK_TYPE=$NETWORK_TYPE" if [[ "$BOOTSTRAP_NODE_NETWORK_TYPE" != "$NETWORK_TYPE" ]]; then build_beacon_node $BOOTSTRAP_NODE_BIN \ --nimcache:nimcache/bootstrap_node \ -d:"NETWORK_TYPE=$BOOTSTRAP_NODE_NETWORK_TYPE" else cp $BEACON_NODE_BIN $BOOTSTRAP_NODE_BIN fi if [ ! -f "${LAST_VALIDATOR}" ]; then echo Building $DEPLOY_DEPOSIT_CONTRACT_BIN $MAKE NIMFLAGS="-o:\"$DEPLOY_DEPOSIT_CONTRACT_BIN\" $CUSTOM_NIMFLAGS $DEFS" deposit_contract if [ "$DEPOSIT_WEB3_URL_ARG" != "" ]; then DEPOSIT_CONTRACT_ADDRESS=$($DEPLOY_DEPOSIT_CONTRACT_BIN deploy $DEPOSIT_WEB3_URL_ARG) export DEPOSIT_CONTRACT_ADDRESS fi $BEACON_NODE_BIN makeDeposits \ --quickstart-deposits="${NUM_VALIDATORS}" \ --deposits-dir="$VALIDATORS_DIR" \ $DEPOSIT_WEB3_URL_ARG \ --deposit-contract="${DEPOSIT_CONTRACT_ADDRESS}" fi if [ ! -f "${SNAPSHOT_FILE}" ]; then $BEACON_NODE_BIN \ --data-dir="${SIMULATION_DIR}/node-$MASTER_NODE" \ createTestnet \ --validators-dir="${VALIDATORS_DIR}" \ --total-validators="${NUM_VALIDATORS}" \ --output-genesis="${SNAPSHOT_FILE}" \ --output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \ --bootstrap-address=127.0.0.1 \ --bootstrap-port=$(( BASE_P2P_PORT + MASTER_NODE )) \ --genesis-offset=5 # Delay in seconds fi rm -f beacon_node.log # Delete any leftover address files from a previous session if [ -f "${MASTER_NODE_ADDRESS_FILE}" ]; then rm "${MASTER_NODE_ADDRESS_FILE}" fi # to allow overriding the program names MULTITAIL="${MULTITAIL:-multitail}" TMUX="${TMUX:-tmux}" TMUX_SESSION_NAME="${TMUX_SESSION_NAME:-nbc-network-sim}" # Using tmux or multitail is an opt-in USE_MULTITAIL="${USE_MULTITAIL:-no}" type "$MULTITAIL" &>/dev/null || { echo $MULTITAIL is missing; USE_MULTITAIL="no"; } USE_TMUX="${USE_TMUX:-no}" type "$TMUX" &>/dev/null || { echo $TMUX is missing; USE_TMUX="no"; } # Prometheus config (continued inside the loop) mkdir -p "${METRICS_DIR}" cat > "${METRICS_DIR}/prometheus.yml" <> "${METRICS_DIR}/prometheus.yml" <