2018-12-19 12:58:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-02-15 16:33:32 +00:00
|
|
|
set -eux
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-01-25 17:35:22 +00:00
|
|
|
# Kill children on ctrl-c
|
|
|
|
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
|
|
|
|
|
2019-01-16 23:01:15 +00:00
|
|
|
# Set a default value for the env vars usually supplied by nimbus Makefile
|
|
|
|
: ${SKIP_BUILDS:=""}
|
|
|
|
: ${BUILD_OUTPUTS_DIR:="./build"}
|
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
NUMBER_OF_VALIDATORS=99
|
|
|
|
|
|
|
|
cd $(dirname "$0")
|
2019-02-27 02:21:47 +00:00
|
|
|
|
|
|
|
PWD_CMD="pwd"
|
|
|
|
# get native Windows paths on Mingw
|
|
|
|
uname | grep -qi mingw && PWD_CMD="pwd -W"
|
|
|
|
|
|
|
|
SIMULATION_DIR="$($PWD_CMD)/data"
|
2019-01-14 11:35:23 +00:00
|
|
|
mkdir -p "$SIMULATION_DIR"
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
STARTUP_FILE="$SIMULATION_DIR/startup.json"
|
|
|
|
SNAPSHOT_FILE="$SIMULATION_DIR/state_snapshot.json"
|
|
|
|
|
|
|
|
cd $(git rev-parse --show-toplevel)
|
2019-02-27 02:21:47 +00:00
|
|
|
ROOT_DIR="$($PWD_CMD)"
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-01-16 23:01:15 +00:00
|
|
|
mkdir -p $BUILD_OUTPUTS_DIR
|
|
|
|
|
2019-01-09 01:01:07 +00:00
|
|
|
BEACON_NODE_BIN=$BUILD_OUTPUTS_DIR/beacon_node
|
|
|
|
VALIDATOR_KEYGEN_BIN=$BUILD_OUTPUTS_DIR/validator_keygen
|
2019-02-14 19:32:33 +00:00
|
|
|
|
|
|
|
# Run with "SHARD_COUNT=4 ./start.sh" to change these
|
2019-02-18 15:58:34 +00:00
|
|
|
DEFS="-d:SHARD_COUNT=${SHARD_COUNT:-4} " # Spec default: 1024
|
|
|
|
DEFS+="-d:EPOCH_LENGTH=${EPOCH_LENGTH:-8} " # Spec default: 64
|
2019-02-21 17:20:50 +00:00
|
|
|
DEFS+="-d:SECONDS_PER_SLOT=${SECONDS_PER_SLOT:-6} " # Spec default: 6
|
2019-01-09 01:01:07 +00:00
|
|
|
|
2019-01-16 23:01:15 +00:00
|
|
|
if [[ -z "$SKIP_BUILDS" ]]; then
|
2019-02-14 19:32:33 +00:00
|
|
|
nim c -o:"$VALIDATOR_KEYGEN_BIN" $DEFS -d:release beacon_chain/validator_keygen
|
2019-02-19 23:35:02 +00:00
|
|
|
nim c -o:"$BEACON_NODE_BIN" $DEFS --opt:speed beacon_chain/beacon_node
|
2019-01-09 01:01:07 +00:00
|
|
|
fi
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
if [ ! -f $STARTUP_FILE ]; then
|
2019-02-15 16:33:32 +00:00
|
|
|
$VALIDATOR_KEYGEN_BIN --validators=$NUMBER_OF_VALIDATORS --outputDir="$SIMULATION_DIR"
|
2018-12-19 12:58:53 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $SNAPSHOT_FILE ]; then
|
2019-01-09 01:01:07 +00:00
|
|
|
$BEACON_NODE_BIN createChain \
|
2018-12-19 12:58:53 +00:00
|
|
|
--chainStartupData:$STARTUP_FILE \
|
2019-02-21 04:42:17 +00:00
|
|
|
--out:$SNAPSHOT_FILE --genesisOffset=5 # Delay in seconds
|
2018-12-19 12:58:53 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-21 19:42:37 +00:00
|
|
|
MASTER_NODE_ADDRESS_FILE="$SIMULATION_DIR/node-0/beacon_node.address"
|
2018-12-28 16:51:40 +00:00
|
|
|
|
|
|
|
# Delete any leftover address files from a previous session
|
|
|
|
if [ -f $MASTER_NODE_ADDRESS_FILE ]; then
|
|
|
|
rm $MASTER_NODE_ADDRESS_FILE
|
|
|
|
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"
|
|
|
|
COMMANDS=()
|
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
for i in $(seq 0 9); do
|
2018-12-28 16:51:40 +00:00
|
|
|
BOOTSTRAP_NODES_FLAG="--bootstrapNodesFile:$MASTER_NODE_ADDRESS_FILE"
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
if [[ "$i" == "0" ]]; then
|
|
|
|
BOOTSTRAP_NODES_FLAG=""
|
2019-02-20 02:22:25 +00:00
|
|
|
elif [ "$USE_MULTITAIL" = "no" ]; then
|
2018-12-28 16:51:40 +00:00
|
|
|
# Wait for the master node to write out its address file
|
|
|
|
while [ ! -f $MASTER_NODE_ADDRESS_FILE ]; do
|
|
|
|
sleep 0.1
|
|
|
|
done
|
2018-12-19 12:58:53 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-21 19:42:37 +00:00
|
|
|
DATA_DIR=$SIMULATION_DIR/node-$i
|
2018-12-28 16:51:40 +00:00
|
|
|
|
2019-02-20 02:22:25 +00:00
|
|
|
CMD="$BEACON_NODE_BIN \
|
|
|
|
--dataDir:\"$DATA_DIR\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}1.json\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}2.json\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}3.json\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}4.json\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}5.json\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}6.json\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}7.json\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}8.json\" \
|
|
|
|
--validator:\"$SIMULATION_DIR/validator-${i}9.json\" \
|
2018-12-19 12:58:53 +00:00
|
|
|
--tcpPort:5000$i \
|
|
|
|
--udpPort:5000$i \
|
2019-02-20 02:22:25 +00:00
|
|
|
--stateSnapshot:\"$SNAPSHOT_FILE\" \
|
|
|
|
$BOOTSTRAP_NODES_FLAG"
|
|
|
|
|
|
|
|
if [ "$USE_MULTITAIL" != "no" ]; then
|
|
|
|
if [ "$i" = "0" ]; then
|
|
|
|
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
|
|
|
|
eval $CMD &
|
|
|
|
fi
|
2018-12-19 12:58:53 +00:00
|
|
|
done
|
|
|
|
|
2019-02-20 02:22:25 +00:00
|
|
|
if [ "$USE_MULTITAIL" != "no" ]; then
|
|
|
|
eval $MULTITAIL -s 2 -M 0 -x \"beacon chain simulation\" "${COMMANDS[@]}"
|
|
|
|
else
|
|
|
|
wait # Stop when all nodes have gone down
|
|
|
|
fi
|
|
|
|
|