2018-12-19 12:58:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-09-05 10:55:47 +00:00
|
|
|
set -eo pipefail
|
2019-01-25 17:35:22 +00:00
|
|
|
|
2019-02-28 21:21:29 +00:00
|
|
|
# Read in variables
|
2019-09-05 10:55:47 +00:00
|
|
|
source "$(dirname "$0")/vars.sh"
|
|
|
|
|
|
|
|
# set up the environment
|
|
|
|
source "${SIM_ROOT}/../../env.sh"
|
2019-02-28 21:21:29 +00:00
|
|
|
|
2019-03-28 15:18:59 +00:00
|
|
|
cd "$SIM_ROOT"
|
2019-01-14 11:35:23 +00:00
|
|
|
mkdir -p "$SIMULATION_DIR"
|
2019-03-07 13:59:28 +00:00
|
|
|
mkdir -p "$VALIDATORS_DIR"
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-03-28 15:18:59 +00:00
|
|
|
cd "$GIT_ROOT"
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2019-10-17 13:18:58 +00:00
|
|
|
NIMFLAGS="-d:chronicles_log_level=DEBUG --hints:off --warnings:off --verbosity:0 --opt:speed --debuginfo"
|
2019-01-16 23:01:15 +00:00
|
|
|
|
2019-07-03 07:35:05 +00:00
|
|
|
# Run with "SHARD_COUNT=4 ./start.sh" to change these
|
2019-09-01 15:02:49 +00:00
|
|
|
DEFS=""
|
|
|
|
|
2019-11-12 05:35:52 +00:00
|
|
|
DEFS+="-d:MAX_COMMITTEES_PER_SLOT=${MAX_COMMITTEES_PER_SLOT:-1} " # Spec default: 64
|
|
|
|
DEFS+="-d:SLOTS_PER_EPOCH=${SLOTS_PER_EPOCH:-16} " # Spec default: 32
|
|
|
|
DEFS+="-d:SECONDS_PER_SLOT=${SECONDS_PER_SLOT:-6} " # Spec default: 12
|
2019-01-09 01:01:07 +00:00
|
|
|
|
2019-08-14 10:25:39 +00:00
|
|
|
LAST_VALIDATOR_NUM=$(( NUM_VALIDATORS - 1 ))
|
2019-03-07 13:59:28 +00:00
|
|
|
LAST_VALIDATOR="$VALIDATORS_DIR/v$(printf '%07d' $LAST_VALIDATOR_NUM).deposit.json"
|
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
echo "Building $BEACON_NODE_BIN ($DEFS)"
|
2019-09-05 10:55:47 +00:00
|
|
|
nim c -o:"$BEACON_NODE_BIN" $NIMFLAGS $DEFS beacon_chain/beacon_node
|
2019-07-12 14:24:11 +00:00
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
if [ ! -f "${LAST_VALIDATOR}" ]; then
|
|
|
|
echo Building $DEPLOY_DEPOSIT_CONTRACT_BIN
|
2019-10-03 09:21:28 +00:00
|
|
|
nim c -o:"$DEPLOY_DEPOSIT_CONTRACT_BIN" $NIMFLAGS $DEFS -d:release beacon_chain/deposit_contract
|
2019-02-28 21:21:29 +00:00
|
|
|
|
2019-07-18 11:36:53 +00:00
|
|
|
if [ "$DEPOSIT_WEB3_URL_ARG" != "" ]; then
|
2019-10-03 09:21:28 +00:00
|
|
|
DEPOSIT_CONTRACT_ADDRESS=$($DEPLOY_DEPOSIT_CONTRACT_BIN deploy $DEPOSIT_WEB3_URL_ARG)
|
2019-08-14 10:25:39 +00:00
|
|
|
export DEPOSIT_CONTRACT_ADDRESS
|
2019-07-18 11:36:53 +00:00
|
|
|
fi
|
2019-07-12 14:24:11 +00:00
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
$BEACON_NODE_BIN makeDeposits \
|
2019-10-29 02:43:23 +00:00
|
|
|
--quickstart-deposits="${NUM_VALIDATORS}" \
|
2019-10-29 19:48:32 +00:00
|
|
|
--deposits-dir="$VALIDATORS_DIR" \
|
2019-07-18 11:36:53 +00:00
|
|
|
$DEPOSIT_WEB3_URL_ARG \
|
2019-10-28 23:04:52 +00:00
|
|
|
--deposit-contract="${DEPOSIT_CONTRACT_ADDRESS}"
|
2019-01-09 01:01:07 +00:00
|
|
|
fi
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-08-14 10:25:39 +00:00
|
|
|
if [ ! -f "${SNAPSHOT_FILE}" ]; then
|
2019-03-27 20:17:01 +00:00
|
|
|
$BEACON_NODE_BIN \
|
2019-11-11 01:28:13 +00:00
|
|
|
--data-dir="${SIMULATION_DIR}/node-$MASTER_NODE" \
|
2019-03-27 20:17:01 +00:00
|
|
|
createTestnet \
|
2019-10-28 23:04:52 +00:00
|
|
|
--validators-dir="${VALIDATORS_DIR}" \
|
|
|
|
--total-validators="${NUM_VALIDATORS}" \
|
|
|
|
--output-genesis="${SNAPSHOT_FILE}" \
|
|
|
|
--output-bootstrap-file="${NETWORK_BOOTSTRAP_FILE}" \
|
|
|
|
--bootstrap-address=127.0.0.1 \
|
2019-11-11 01:28:13 +00:00
|
|
|
--bootstrap-port=$(( BASE_P2P_PORT + MASTER_NODE )) \
|
2019-10-28 23:04:52 +00:00
|
|
|
--genesis-offset=5 # Delay in seconds
|
2018-12-19 12:58:53 +00:00
|
|
|
fi
|
|
|
|
|
2018-12-28 16:51:40 +00:00
|
|
|
# Delete any leftover address files from a previous session
|
2019-08-14 10:25:39 +00:00
|
|
|
if [ -f "${MASTER_NODE_ADDRESS_FILE}" ]; then
|
|
|
|
rm "${MASTER_NODE_ADDRESS_FILE}"
|
2018-12-28 16:51:40 +00:00
|
|
|
fi
|
|
|
|
|
2019-02-20 02:22:25 +00:00
|
|
|
# multitail support
|
|
|
|
MULTITAIL="${MULTITAIL:-multitail}" # to allow overriding the program name
|
|
|
|
USE_MULTITAIL="${USE_MULTITAIL:-no}" # make it an opt-in
|
|
|
|
type "$MULTITAIL" &>/dev/null || USE_MULTITAIL="no"
|
|
|
|
|
2019-10-17 13:18:58 +00:00
|
|
|
# Prometheus config (continued inside the loop)
|
|
|
|
mkdir -p "${METRICS_DIR}"
|
|
|
|
cat > "${METRICS_DIR}/prometheus.yml" <<EOF
|
|
|
|
global:
|
|
|
|
scrape_interval: 1s
|
|
|
|
|
|
|
|
scrape_configs:
|
|
|
|
- job_name: "nimbus"
|
|
|
|
static_configs:
|
|
|
|
EOF
|
|
|
|
|
2019-10-28 13:28:45 +00:00
|
|
|
PROCESS_DASHBOARD_BIN="${SIM_ROOT}/../../build/process_dashboard"
|
|
|
|
|
|
|
|
if [ ! -f "$PROCESS_DASHBOARD_BIN" ]; then
|
|
|
|
nim c -d:release --outdir:build tests/simulation/process_dashboard.nim
|
|
|
|
fi
|
|
|
|
|
2019-10-17 13:18:58 +00:00
|
|
|
# use the exported Grafana dashboard for a single node to create one for all nodes
|
|
|
|
"${SIM_ROOT}/../../build/process_dashboard" \
|
2019-11-11 01:28:13 +00:00
|
|
|
--nodes=${TOTAL_NODES} \
|
2019-10-17 13:18:58 +00:00
|
|
|
--in="${SIM_ROOT}/beacon-chain-sim-node0-Grafana-dashboard.json" \
|
|
|
|
--out="${SIM_ROOT}/beacon-chain-sim-all-nodes-Grafana-dashboard.json"
|
|
|
|
|
2019-03-28 15:18:59 +00:00
|
|
|
# Kill child processes on Ctrl-C by sending SIGTERM to the whole process group,
|
|
|
|
# passing the negative PID of this shell instance to the "kill" command.
|
|
|
|
# Trap and ignore SIGTERM, so we don't kill this process along with its children.
|
|
|
|
if [ "$USE_MULTITAIL" = "no" ]; then
|
|
|
|
trap '' SIGTERM
|
2019-08-14 10:25:39 +00:00
|
|
|
trap 'kill -- -$$' SIGINT EXIT
|
2019-03-28 15:18:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
COMMANDS=()
|
2019-03-07 13:59:28 +00:00
|
|
|
|
2019-11-11 01:28:13 +00:00
|
|
|
for i in $(seq $MASTER_NODE $TOTAL_USER_NODES); do
|
|
|
|
if [[ "$i" != "$MASTER_NODE" && "$USE_MULTITAIL" == "no" ]]; then
|
2018-12-28 16:51:40 +00:00
|
|
|
# Wait for the master node to write out its address file
|
2019-08-14 10:25:39 +00:00
|
|
|
while [ ! -f "${MASTER_NODE_ADDRESS_FILE}" ]; do
|
2018-12-28 16:51:40 +00:00
|
|
|
sleep 0.1
|
|
|
|
done
|
2018-12-19 12:58:53 +00:00
|
|
|
fi
|
|
|
|
|
2019-10-29 20:13:24 +00:00
|
|
|
CMD="${SIM_ROOT}/run_node.sh $i"
|
2019-02-20 02:22:25 +00:00
|
|
|
|
2019-10-17 13:18:58 +00:00
|
|
|
if [[ "$USE_MULTITAIL" != "no" ]]; then
|
|
|
|
if [[ "$i" == "0" ]]; then
|
2019-02-20 02:22:25 +00:00
|
|
|
SLEEP="0"
|
|
|
|
else
|
2019-02-21 04:42:17 +00:00
|
|
|
SLEEP="2"
|
2019-02-20 02:22:25 +00:00
|
|
|
fi
|
|
|
|
# "multitail" closes the corresponding panel when a command exits, so let's make sure it doesn't exit
|
|
|
|
COMMANDS+=( " -cT ansi -t 'node #$i' -l 'sleep $SLEEP; $CMD; echo [node execution completed]; while true; do sleep 100; done'" )
|
|
|
|
else
|
2019-08-14 10:25:39 +00:00
|
|
|
eval "${CMD}" &
|
2019-02-20 02:22:25 +00:00
|
|
|
fi
|
2019-10-17 13:18:58 +00:00
|
|
|
|
|
|
|
# Prometheus config
|
|
|
|
cat >> "${METRICS_DIR}/prometheus.yml" <<EOF
|
|
|
|
- targets: ['127.0.0.1:$(( $BASE_METRICS_PORT + $i ))']
|
|
|
|
labels:
|
|
|
|
node: '$i'
|
|
|
|
EOF
|
2018-12-19 12:58:53 +00:00
|
|
|
done
|
|
|
|
|
2019-10-17 13:18:58 +00:00
|
|
|
if [[ "$USE_MULTITAIL" != "no" ]]; then
|
2019-02-28 21:21:29 +00:00
|
|
|
eval $MULTITAIL -s 3 -M 0 -x \"Nimbus beacon chain\" "${COMMANDS[@]}"
|
2019-02-20 02:22:25 +00:00
|
|
|
else
|
|
|
|
wait # Stop when all nodes have gone down
|
|
|
|
fi
|