2019-03-19 19:50:22 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
cd $(dirname "$0")
|
|
|
|
|
|
|
|
NETWORK_NAME=$1
|
|
|
|
source "$NETWORK_NAME.env"
|
|
|
|
|
|
|
|
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 ${BOOTSTRAP_HOST:="master-01.do-ams3.nimbus.test.statusim.net"} > /dev/null
|
2019-03-19 19:50:22 +00:00
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
echo Execution plan:
|
2019-06-24 12:57:22 +00:00
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
echo "Testnet name : $NETWORK_NAME"
|
2019-10-29 02:43:23 +00:00
|
|
|
echo "Testnet files repo : ${ETH2_TESTNETS:="build/eth2-testnets"}"
|
|
|
|
echo "Beacon node data dir : ${DATA_DIR:="build/testnet-reset-data"}"
|
2019-09-10 22:13:27 +00:00
|
|
|
echo "Bootstrap node ip : ${BOOTSTRAP_IP:="$(dig +short $BOOTSTRAP_HOST)"}"
|
|
|
|
echo "Reset testnet at end : ${PUBLISH_TESTNET_RESETS:="1"}"
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
while true; do
|
|
|
|
read -p "Continue?" yn
|
|
|
|
case $yn in
|
|
|
|
[Yy]* ) break;;
|
|
|
|
[Nn]* ) exit 1;;
|
|
|
|
* ) echo "Please answer yes or no.";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-10-29 02:43:23 +00:00
|
|
|
if [[ ! -d "$ETH2_TESTNETS" ]]; then
|
|
|
|
git clone git@github.com:zah/eth2-testnets "$ETH2_TESTNETS"
|
2019-09-10 22:13:27 +00:00
|
|
|
fi
|
|
|
|
|
2019-10-29 02:43:23 +00:00
|
|
|
ETH2_TESTNETS_ABS=$(cd "$ETH2_TESTNETS"; pwd)
|
|
|
|
NETWORK_DIR_ABS="$ETH2_TESTNETS_ABS/nimbus/$NETWORK_NAME"
|
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"
|
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"
|
|
|
|
|
|
|
|
DOCKER_BEACON_NODE="docker run -v $DEPOSITS_DIR_ABS:/deposits_dir -v $NETWORK_DIR_ABS:/network_dir -v $DATA_DIR_ABS:/data_dir statusteam/nimbus_beacon_node:$NETWORK_NAME"
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-10-25 14:53:31 +00:00
|
|
|
make deposit_contract
|
|
|
|
|
|
|
|
if [ "$ETH1_PRIVATE_KEY" != "" ]; then
|
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-25 14:53:31 +00:00
|
|
|
fi
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
cd docker
|
2019-10-29 13:41:10 +00:00
|
|
|
export NETWORK=$NETWORK_NAME
|
|
|
|
export GIT_REVISION=$(git rev-parse HEAD)
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
make build
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
$DOCKER_BEACON_NODE makeDeposits \
|
|
|
|
--quickstart-deposits=$QUICKSTART_VALIDATORS \
|
|
|
|
--random-deposits=$RANDOM_VALIDATORS \
|
|
|
|
--deposits-dir=/deposits_dir
|
2019-06-24 12:57:22 +00:00
|
|
|
|
2019-10-29 03:58:31 +00:00
|
|
|
TOTAL_VALIDATORS="$(( $QUICKSTART_VALIDATORS + $RANDOM_VALIDATORS ))"
|
2019-10-29 02:43:23 +00:00
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
$DOCKER_BEACON_NODE \
|
2019-10-28 23:04:52 +00:00
|
|
|
--data-dir=/data_dir \
|
2019-06-24 12:57:22 +00:00
|
|
|
createTestnet \
|
2019-10-29 03:58:31 +00:00
|
|
|
--validators-dir=/deposits_dir \
|
2019-10-29 02:43:23 +00:00
|
|
|
--total-validators=$TOTAL_VALIDATORS \
|
2019-10-29 03:58:31 +00:00
|
|
|
--last-user-validator=$QUICKSTART_VALIDATORS \
|
2019-10-29 02:43:23 +00:00
|
|
|
--output-genesis=/network_dir/genesis.ssz \
|
2019-10-28 23:04:52 +00:00
|
|
|
--output-bootstrap-file=/network_dir/bootstrap_nodes.txt \
|
|
|
|
--bootstrap-address=$BOOTSTRAP_IP \
|
|
|
|
--bootstrap-port=$BOOTSTRAP_PORT \
|
2019-10-25 14:53:31 +00:00
|
|
|
$WEB3_URL_ARG $DEPOSIT_CONTRACT_ADDRESS_ARG \
|
2019-10-28 23:04:52 +00:00
|
|
|
--genesis-offset=60 # Delay in seconds
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-10-29 02:43:23 +00:00
|
|
|
if [[ ! -z "$DEPOSIT_CONTRACT_ADDRESS" ]]; then
|
|
|
|
echo $DEPOSIT_CONTRACT_ADDRESS > "$ETH2_TESTNETS_ABS/deposit_contract.txt"
|
|
|
|
fi
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
|
|
|
|
echo Persisting testnet data to git...
|
2019-10-29 13:41:10 +00:00
|
|
|
pushd "$NETWORK_DIR_ABS"
|
2019-10-29 03:58:31 +00:00
|
|
|
git add genesis.ssz bootstrap_nodes.txt deposit_contract.txt
|
2019-10-29 02:43:23 +00:00
|
|
|
git commit -m "Reset of Nimbus $NETWORK_NAME"
|
2019-09-10 22:13:27 +00:00
|
|
|
git push
|
|
|
|
popd
|
|
|
|
|
|
|
|
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-10-29 13:41:10 +00:00
|
|
|
nim --verbosity:0 manage_testnet_hosts.nims redist_validators \
|
|
|
|
--network=$NETWORK_NAME \
|
|
|
|
--deposits-dir="$DEPOSITS_DIR_ABS" \
|
|
|
|
--network-data-dir="$NETWORK_DIR_ABS" \
|
|
|
|
--user-validators=$QUICKSTART_VALIDATORS \
|
|
|
|
--total-validators=$TOTAL_VALIDATORS \
|
|
|
|
> /tmp/reset-network.sh
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
bash /tmp/reset-network.sh
|
|
|
|
|
|
|
|
echo Uploading bootstrap node network key
|
2019-10-29 16:35:21 +00:00
|
|
|
BOOTSTRAP_NODE_DOCKER_PATH=/docker/beacon-node-$NETWORK_NAME-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"
|
|
|
|
|
|
|
|
echo Publishing docker image...
|
|
|
|
make push
|
|
|
|
fi
|