2019-03-19 19:50:22 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-01-13 12:21:22 +00:00
|
|
|
set -e
|
2019-03-19 19:50:22 +00:00
|
|
|
|
|
|
|
cd $(dirname "$0")
|
|
|
|
|
2019-11-13 01:27:46 +00:00
|
|
|
export NETWORK=$1
|
|
|
|
export NETWORK_NIM_FLAGS=$(./load-testnet-nim-flags.sh $NETWORK)
|
|
|
|
export GIT_REVISION=$(git rev-parse HEAD)
|
2019-03-19 19:50:22 +00:00
|
|
|
|
2019-11-14 18:48:30 +00:00
|
|
|
set -a
|
|
|
|
source $NETWORK.env
|
|
|
|
set +a
|
|
|
|
|
2019-03-19 19:50:22 +00:00
|
|
|
cd ..
|
|
|
|
|
|
|
|
if [ -f .env ]; then
|
2019-10-29 02:43:23 +00:00
|
|
|
# allow server overrides for ETH2_TESTNETS, DATA_DIR and ETH1_PRIVATE_KEY
|
2019-03-19 19:50:22 +00:00
|
|
|
source .env
|
|
|
|
fi
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
echo Execution plan:
|
2019-06-24 12:57:22 +00:00
|
|
|
|
2019-11-13 01:27:46 +00:00
|
|
|
echo "Testnet name : $NETWORK"
|
2020-01-28 20:28:52 +00:00
|
|
|
echo "Bootstrap node hostname : ${BOOTSTRAP_HOST:="master-01.aws-eu-central-1a.nimbus.test.statusim.net"}"
|
2019-11-05 13:00:11 +00:00
|
|
|
echo "Bootstrap node ip : ${BOOTSTRAP_IP:="$(dig +short $BOOTSTRAP_HOST)"}"
|
2019-11-14 18:48:30 +00:00
|
|
|
echo "Bootstrap node port : ${BOOTSTRAP_PORT:=9000}"
|
2019-11-05 13:00:11 +00:00
|
|
|
echo "Reset testnet at end : ${PUBLISH_TESTNET_RESETS:="1"}"
|
|
|
|
echo "Testnet metadata repo : ${ETH2_TESTNETS_GIT_URL:="git@github.com:${ETH2_TESTNETS_ORG:=eth2-clients}/eth2-testnets"}"
|
|
|
|
echo "Testnet metadata dir : ${ETH2_TESTNETS:="build/eth2-testnets"}"
|
2019-11-14 18:48:30 +00:00
|
|
|
echo "Beacon node data dir : ${DATA_DIR:="build/testnet-reset-data/$NETWORK"}"
|
2019-11-13 01:27:46 +00:00
|
|
|
echo "Nim build flags : $NETWORK_NIM_FLAGS"
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
while true; do
|
2020-02-09 02:22:42 +00:00
|
|
|
read -p "Continue? [Yn] " yn
|
2019-09-10 22:13:27 +00:00
|
|
|
case $yn in
|
2020-02-09 02:22:42 +00:00
|
|
|
* ) break;;
|
2019-09-10 22:13:27 +00:00
|
|
|
[Nn]* ) exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-11-07 20:10:59 +00:00
|
|
|
rm -rf "$ETH2_TESTNETS"
|
2019-11-05 13:00:11 +00:00
|
|
|
git clone --quiet --depth=1 $ETH2_TESTNETS_GIT_URL "$ETH2_TESTNETS"
|
2019-10-31 18:06:55 +00:00
|
|
|
|
2019-10-29 02:43:23 +00:00
|
|
|
ETH2_TESTNETS_ABS=$(cd "$ETH2_TESTNETS"; pwd)
|
2019-11-13 01:27:46 +00:00
|
|
|
NETWORK_DIR_ABS="$ETH2_TESTNETS_ABS/nimbus/$NETWORK"
|
2019-10-29 03:58:31 +00:00
|
|
|
DATA_DIR_ABS=$(mkdir -p "$DATA_DIR"; cd "$DATA_DIR"; pwd)
|
|
|
|
DEPOSITS_DIR_ABS="$DATA_DIR_ABS/deposits"
|
2020-06-01 19:48:20 +00:00
|
|
|
SECRETS_DIR_ABS="$DATA_DIR_ABS/secrets"
|
2019-10-29 13:41:10 +00:00
|
|
|
DEPOSIT_CONTRACT_ADDRESS=""
|
|
|
|
DEPOSIT_CONTRACT_ADDRESS_ARG=""
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-10-25 14:53:31 +00:00
|
|
|
if [ "$WEB3_URL" != "" ]; then
|
2019-10-28 23:04:52 +00:00
|
|
|
WEB3_URL_ARG="--web3-url=$WEB3_URL"
|
2019-10-25 14:53:31 +00:00
|
|
|
fi
|
|
|
|
|
2019-10-29 03:58:31 +00:00
|
|
|
mkdir -p "$DEPOSITS_DIR_ABS"
|
2020-06-01 19:48:20 +00:00
|
|
|
mkdir -p "$SECRETS_DIR_ABS"
|
2019-10-29 03:58:31 +00:00
|
|
|
|
2019-10-25 14:53:31 +00:00
|
|
|
if [ "$ETH1_PRIVATE_KEY" != "" ]; then
|
2020-02-11 17:41:25 +00:00
|
|
|
make deposit_contract
|
2019-10-31 18:06:55 +00:00
|
|
|
echo "Deploying deposit contract through $WEB3_URL_ARG..."
|
2019-10-29 00:20:47 +00:00
|
|
|
DEPOSIT_CONTRACT_ADDRESS=$(./build/deposit_contract deploy $WEB3_URL_ARG --private-key=$ETH1_PRIVATE_KEY)
|
|
|
|
DEPOSIT_CONTRACT_ADDRESS_ARG="--deposit-contract=$DEPOSIT_CONTRACT_ADDRESS"
|
2019-10-30 13:18:55 +00:00
|
|
|
echo "Done: $DEPOSIT_CONTRACT_ADDRESS"
|
2019-10-25 14:53:31 +00:00
|
|
|
fi
|
|
|
|
|
2020-06-15 22:20:31 +00:00
|
|
|
echo "Building a local beacon_node instance for 'deposits create' and 'createTestnet'"
|
2020-06-03 00:18:25 +00:00
|
|
|
make -j2 NIMFLAGS="-d:insecure -d:testnet_servers_image ${NETWORK_NIM_FLAGS}" beacon_node process_dashboard
|
|
|
|
|
|
|
|
echo "Generating Grafana dashboards for remote testnet servers"
|
|
|
|
for testnet in 0 1; do
|
|
|
|
./build/process_dashboard \
|
2020-06-10 15:21:32 +00:00
|
|
|
--in="grafana/beacon_nodes_Grafana_dashboard.json" \
|
|
|
|
--out="docker/remote_testnet${testnet}_Grafana_dashboard.json" \
|
2020-06-03 00:18:25 +00:00
|
|
|
--testnet="${testnet}"
|
|
|
|
done
|
2020-02-11 17:41:25 +00:00
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
cd docker
|
|
|
|
|
2020-01-13 13:48:19 +00:00
|
|
|
echo "Building Docker image..."
|
2020-02-11 17:41:25 +00:00
|
|
|
# CPU-specific CFLAGS that work on the servers are in MARCH_NIM_FLAGS,
|
|
|
|
# in docker/Makefile, and are enabled by default.
|
|
|
|
make build
|
2020-01-13 13:48:19 +00:00
|
|
|
|
2020-06-15 22:20:31 +00:00
|
|
|
../build/beacon_node deposits create \
|
2020-06-01 19:48:20 +00:00
|
|
|
--count=$TOTAL_VALIDATORS \
|
|
|
|
--out-validators-dir="$DEPOSITS_DIR_ABS" \
|
2020-06-15 22:20:31 +00:00
|
|
|
--out-secrets-dir="$SECRETS_DIR_ABS" \
|
|
|
|
--dont-send
|
2019-10-29 02:43:23 +00:00
|
|
|
|
2020-02-11 17:41:25 +00:00
|
|
|
../build/beacon_node createTestnet \
|
|
|
|
--data-dir="$DATA_DIR_ABS" \
|
|
|
|
--validators-dir="$DEPOSITS_DIR_ABS" \
|
2019-10-29 02:43:23 +00:00
|
|
|
--total-validators=$TOTAL_VALIDATORS \
|
2020-06-01 19:48:20 +00:00
|
|
|
--last-user-validator=$USER_VALIDATORS \
|
2020-02-11 17:41:25 +00:00
|
|
|
--output-genesis="$NETWORK_DIR_ABS/genesis.ssz" \
|
|
|
|
--output-bootstrap-file="$NETWORK_DIR_ABS/bootstrap_nodes.txt" \
|
2019-10-28 23:04:52 +00:00
|
|
|
--bootstrap-address=$BOOTSTRAP_IP \
|
|
|
|
--bootstrap-port=$BOOTSTRAP_PORT \
|
2019-10-25 14:53:31 +00:00
|
|
|
$WEB3_URL_ARG $DEPOSIT_CONTRACT_ADDRESS_ARG \
|
2020-02-09 02:22:42 +00:00
|
|
|
--genesis-offset=300 # Delay in seconds
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-10-31 18:06:55 +00:00
|
|
|
COMMITTED_FILES=" genesis.ssz bootstrap_nodes.txt "
|
2019-10-29 18:22:25 +00:00
|
|
|
|
2019-10-29 02:43:23 +00:00
|
|
|
if [[ ! -z "$DEPOSIT_CONTRACT_ADDRESS" ]]; then
|
2019-11-13 01:27:46 +00:00
|
|
|
echo $DEPOSIT_CONTRACT_ADDRESS > "$ETH2_TESTNETS_ABS/nimbus/$NETWORK/deposit_contract.txt"
|
2019-10-31 18:06:55 +00:00
|
|
|
COMMITTED_FILES+=" deposit_contract.txt "
|
2019-10-29 02:43:23 +00:00
|
|
|
fi
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
|
|
|
|
echo Redistributing validator keys to server nodes...
|
|
|
|
# TODO If we try to use direct piping here, bash doesn't execute all of the commands.
|
|
|
|
# The reasons for this are unclear at the moment.
|
2019-11-05 13:00:11 +00:00
|
|
|
|
2020-06-03 00:18:25 +00:00
|
|
|
../env.sh nim --verbosity:0 --hints:off manage_testnet_hosts.nims reset_network \
|
2019-11-13 01:27:46 +00:00
|
|
|
--network=$NETWORK \
|
2019-10-29 13:41:10 +00:00
|
|
|
--deposits-dir="$DEPOSITS_DIR_ABS" \
|
2020-06-03 09:07:43 +00:00
|
|
|
--secrets-dir="$SECRETS_DIR_ABS" \
|
2019-10-29 13:41:10 +00:00
|
|
|
--network-data-dir="$NETWORK_DIR_ABS" \
|
2020-06-01 19:48:20 +00:00
|
|
|
--user-validators=$USER_VALIDATORS \
|
2019-10-29 13:41:10 +00:00
|
|
|
> /tmp/reset-network.sh
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
bash /tmp/reset-network.sh
|
2019-11-19 15:30:54 +00:00
|
|
|
rm /tmp/reset-network.sh
|
2019-09-10 22:13:27 +00:00
|
|
|
|
|
|
|
echo Uploading bootstrap node network key
|
2019-11-13 01:27:46 +00:00
|
|
|
BOOTSTRAP_NODE_DOCKER_PATH=/docker/beacon-node-$NETWORK-1/data/BeaconNode/
|
2019-09-10 22:13:27 +00:00
|
|
|
scp "$DATA_DIR_ABS/privkey.protobuf" $BOOTSTRAP_HOST:/tmp/
|
|
|
|
ssh $BOOTSTRAP_HOST "sudo install -o dockremap -g docker /tmp/privkey.protobuf $BOOTSTRAP_NODE_DOCKER_PATH"
|
|
|
|
|
2020-01-22 19:11:15 +00:00
|
|
|
echo "Publishing Docker image..."
|
|
|
|
make push-last
|
|
|
|
|
2019-10-29 18:22:25 +00:00
|
|
|
echo Persisting testnet data to git...
|
|
|
|
pushd "$NETWORK_DIR_ABS"
|
|
|
|
git add $COMMITTED_FILES
|
2019-11-13 01:27:46 +00:00
|
|
|
git commit -m "Reset of Nimbus $NETWORK"
|
2019-10-29 18:22:25 +00:00
|
|
|
git push
|
|
|
|
popd
|
2020-01-13 12:55:09 +00:00
|
|
|
|
2020-06-03 00:18:25 +00:00
|
|
|
../env.sh nim --verbosity:0 --hints:off manage_testnet_hosts.nims restart_nodes \
|
2020-01-22 19:11:15 +00:00
|
|
|
--network=$NETWORK \
|
|
|
|
> /tmp/restart-nodes.sh
|
2019-11-19 15:30:54 +00:00
|
|
|
|
2020-01-22 19:11:15 +00:00
|
|
|
bash /tmp/restart-nodes.sh
|
|
|
|
rm /tmp/restart-nodes.sh
|
|
|
|
fi
|