2018-12-19 14:58:53 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-02-15 10:33:32 -06:00
|
|
|
set -eux
|
2018-12-19 14:58:53 +02:00
|
|
|
|
2019-01-25 11:35:22 -06:00
|
|
|
# Kill children on ctrl-c
|
|
|
|
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
|
|
|
|
|
2019-02-28 15:21:29 -06:00
|
|
|
# Read in variables
|
|
|
|
. $(dirname $0)/vars.sh
|
|
|
|
|
2019-01-17 01:01:15 +02:00
|
|
|
# Set a default value for the env vars usually supplied by nimbus Makefile
|
|
|
|
|
2019-03-13 13:44:30 +01:00
|
|
|
NUM_VALIDATORS=${VALIDATORS:-100}
|
|
|
|
NUM_NODES=${NODES:-9}
|
2018-12-19 14:58:53 +02:00
|
|
|
|
2019-02-28 15:21:29 -06:00
|
|
|
cd $SIM_ROOT
|
2019-01-14 13:35:23 +02:00
|
|
|
mkdir -p "$SIMULATION_DIR"
|
2019-03-07 07:59:28 -06:00
|
|
|
mkdir -p "$VALIDATORS_DIR"
|
2018-12-19 14:58:53 +02:00
|
|
|
|
2019-02-28 15:21:29 -06:00
|
|
|
cd $GIT_ROOT
|
2019-01-17 01:01:15 +02:00
|
|
|
mkdir -p $BUILD_OUTPUTS_DIR
|
|
|
|
|
2019-02-14 13:32:33 -06:00
|
|
|
# Run with "SHARD_COUNT=4 ./start.sh" to change these
|
2019-02-18 16:58:34 +01:00
|
|
|
DEFS="-d:SHARD_COUNT=${SHARD_COUNT:-4} " # Spec default: 1024
|
2019-02-28 15:21:29 -06:00
|
|
|
DEFS+="-d:SLOTS_PER_EPOCH=${SLOTS_PER_EPOCH:-8} " # Spec default: 64
|
2019-02-21 11:20:50 -06:00
|
|
|
DEFS+="-d:SECONDS_PER_SLOT=${SECONDS_PER_SLOT:-6} " # Spec default: 6
|
2019-01-09 03:01:07 +02:00
|
|
|
|
2019-03-07 07:59:28 -06:00
|
|
|
LAST_VALIDATOR_NUM=$(( $NUM_VALIDATORS - 1 ))
|
|
|
|
LAST_VALIDATOR="$VALIDATORS_DIR/v$(printf '%07d' $LAST_VALIDATOR_NUM).deposit.json"
|
|
|
|
|
|
|
|
if [ ! -f $LAST_VALIDATOR ]; then
|
2019-02-28 15:21:29 -06:00
|
|
|
if [[ -z "$SKIP_BUILDS" ]]; then
|
|
|
|
nim c -o:"$VALIDATOR_KEYGEN_BIN" $DEFS -d:release beacon_chain/validator_keygen
|
|
|
|
fi
|
|
|
|
|
2019-03-07 07:59:28 -06:00
|
|
|
$VALIDATOR_KEYGEN_BIN --validators=$NUM_VALIDATORS --outputDir="$VALIDATORS_DIR"
|
2019-01-09 03:01:07 +02:00
|
|
|
fi
|
2018-12-19 14:58:53 +02:00
|
|
|
|
2019-02-28 15:21:29 -06:00
|
|
|
if [[ -z "$SKIP_BUILDS" ]]; then
|
2019-03-08 22:23:14 -06:00
|
|
|
nim c -o:"$BEACON_NODE_BIN" $DEFS --opt:speed --debuginfo beacon_chain/beacon_node
|
2018-12-19 14:58:53 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f $SNAPSHOT_FILE ]; then
|
2019-03-19 19:22:17 +02:00
|
|
|
$BEACON_NODE_BIN --dataDir=$SIMULATION_DIR/node-0 createTestnet \
|
|
|
|
--networkId=1000 \
|
|
|
|
--validatorsDir=$VALIDATORS_DIR \
|
2019-03-07 07:59:28 -06:00
|
|
|
--numValidators=$NUM_VALIDATORS \
|
2019-03-19 19:22:17 +02:00
|
|
|
--outputGenesis=$SNAPSHOT_FILE \
|
|
|
|
--outputNetwork=$NETWORK_METADATA_FILE \
|
|
|
|
--bootstrapAddress=127.0.0.1 \
|
2019-03-20 03:34:04 +02:00
|
|
|
--bootstrapPort=50000 \
|
2019-03-07 07:59:28 -06:00
|
|
|
--genesisOffset=5 # Delay in seconds
|
2018-12-19 14:58:53 +02:00
|
|
|
fi
|
|
|
|
|
2018-12-28 18:51:40 +02: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 03:22:25 +01: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=()
|
|
|
|
|
2019-03-07 07:59:28 -06:00
|
|
|
LAST_NODE=$(( $NUM_NODES - 1 ))
|
|
|
|
|
|
|
|
for i in $(seq 0 $LAST_NODE); do
|
2018-12-19 14:58:53 +02:00
|
|
|
if [[ "$i" == "0" ]]; then
|
2019-02-28 15:21:29 -06:00
|
|
|
sleep 0
|
2019-02-20 03:22:25 +01:00
|
|
|
elif [ "$USE_MULTITAIL" = "no" ]; then
|
2018-12-28 18:51:40 +02: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 14:58:53 +02:00
|
|
|
fi
|
|
|
|
|
2019-02-28 15:21:29 -06:00
|
|
|
CMD="$SIM_ROOT/run_node.sh $i"
|
2019-02-20 03:22:25 +01:00
|
|
|
|
|
|
|
if [ "$USE_MULTITAIL" != "no" ]; then
|
|
|
|
if [ "$i" = "0" ]; then
|
|
|
|
SLEEP="0"
|
|
|
|
else
|
2019-02-20 22:42:17 -06:00
|
|
|
SLEEP="2"
|
2019-02-20 03:22:25 +01: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 14:58:53 +02:00
|
|
|
done
|
|
|
|
|
2019-02-20 03:22:25 +01:00
|
|
|
if [ "$USE_MULTITAIL" != "no" ]; then
|
2019-02-28 15:21:29 -06:00
|
|
|
eval $MULTITAIL -s 3 -M 0 -x \"Nimbus beacon chain\" "${COMMANDS[@]}"
|
2019-02-20 03:22:25 +01:00
|
|
|
else
|
|
|
|
wait # Stop when all nodes have gone down
|
|
|
|
fi
|