Automated scripts for resetting the Status testnets

For detailed instructions, please see

https://github.com/status-im/nimbus-private/blob/master/testnets-maintenance.md
This commit is contained in:
Zahary Karadjov 2019-09-10 18:13:27 -04:00
parent e59bb6ecab
commit 0eaa433e84
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
8 changed files with 166 additions and 38 deletions

5
.gitignore vendored
View File

@ -28,3 +28,8 @@ build/
# State sim # TODO - move in another folder
0000-*.json
# Testnet resetting working directories
testnet-reset-data/
nim-eth2-testnet-data/

View File

@ -907,8 +907,8 @@ when isMainModule:
totalValidators: config.totalValidators,
lastUserValidator: config.lastUserValidator)
Json.saveFile(config.outputNetwork.string, testnetMetadata, pretty = true)
echo "Wrote ", config.outputNetwork.string
Json.saveFile(config.outputNetworkMetadata.string, testnetMetadata, pretty = true)
echo "Wrote ", config.outputNetworkMetadata.string
of updateTestnet:
discard waitFor updateTestnetMetadata(config)
@ -950,7 +950,7 @@ when isMainModule:
of makeDeposits:
let deposits = generateDeposits(
config.totalDeposits, config.depositDir, config.randomKeys)
config.totalDeposits, config.depositsDir, config.randomKeys)
if config.depositWeb3Url.len() > 0 and config.depositContractAddress.len() > 0:
waitFor sendDeposits(

View File

@ -134,12 +134,15 @@ type
outputGenesis* {.
desc: "Output file where to write the initial state snapshot".}: OutFile
outputNetwork* {.
outputNetworkMetadata* {.
desc: "Output file where to write the initial state snapshot".}: OutFile
withGenesisRoot* {.
desc: "Include a genesis root in network.json", defaultValue: false.}: bool
outputBootstrapNodes* {.
desc: "Output file with list of bootstrap nodes for the network".}: OutFile
of importValidator:
keyFiles* {.
longform: "keyfile"
@ -152,7 +155,7 @@ type
totalDeposits* {.
desc: "Total number of deposits and keys to generate".}: int
depositDir* {.
depositsDir* {.
desc: "Folder to write deposits to", defaultValue: "validators".}: string
randomKeys* {.

View File

@ -16,32 +16,39 @@ ARG GIT_REVISION
RUN export GOROOT=/usr/local/go \
&& export PATH=$GOROOT/bin:$PATH \
&& git clone https://github.com/status-im/nimbus.git \
&& cd nimbus \
&& git clone https://github.com/status-im/nim-beacon-chain.git \
&& cd nim-beacon-chain \
&& git reset --hard ${GIT_REVISION} \
&& make update deps vendor/go/bin/p2pd nat-libs \
&& git submodule update --init --recursive
RUN cd nim-beacon-chain \
&& make build-system-checks
# TODO: The command above exits with 1, so we cannot chain it cleanly
RUN cd nim-beacon-chain \
&& export PATH=/usr/local/go/bin:$PATH \
&& make update deps \
&& cp vendor/go/bin/p2pd /usr/bin/p2pd \
&& cp docker/beacon_node/run_in_docker.sh /usr/bin/run_beacon_node.sh
&& cp docker/run_in_docker.sh /usr/bin/run_beacon_node.sh
ARG NETWORK
ARG NETWORK_TYPE
RUN cd nimbus \
RUN cd nim-beacon-chain \
&& set -a \
&& . vendor/nim-beacon-chain/scripts/${NETWORK}.env \
&& . scripts/${NETWORK}.env \
&& ./env.sh nim \
-o:/usr/bin/beacon_node \
-d:release \
--debugger:native \
--debugInfo \
-d:"network_type=${NETWORK_TYPE}" \
-d:const_preset=${CONST_PRESET} \
-d:SHARD_COUNT=${SHARD_COUNT} \
-d:SLOTS_PER_EPOCH=${SLOTS_PER_EPOCH} \
-d:SECONDS_PER_SLOT=${SECONDS_PER_SLOT} \
-d:chronicles_log_level=DEBUG \
-d:chronicles_sinks=json \
c vendor/nim-beacon-chain/beacon_chain/beacon_node.nim
-d:"SHARD_COUNT=${SHARD_COUNT}" \
-d:"SLOTS_PER_EPOCH=${SLOTS_PER_EPOCH}" \
-d:"SECONDS_PER_SLOT=${SECONDS_PER_SLOT}" \
-d:"chronicles_log_level=DEBUG" \
-d:"chronicles_sinks=json" \
c beacon_chain/beacon_node.nim
# --------------------------------- #
# Starting new image to reduce size #
@ -60,4 +67,6 @@ COPY --from=build /usr/bin/p2pd /usr/bin/p2pd
MAINTAINER Zahary Karadjov <zahary@status.im>
LABEL description="Nimbus installation that can act as an ETH2 network bootstrap node."
ENTRYPOINT ["/usr/bin/run_beacon_node.sh"]
RUN echo Built from Git revision: ${GIT_REVISION}
ENTRYPOINT ["/usr/bin/beacon_node"]

View File

@ -0,0 +1,46 @@
import
strformat
var
serverCount = 10
instancesCount = 2
totalValidators = 1000
userValidators = 200
systemValidators = totalValidators - userValidators
validatorsPerServer = systemValidators div serverCount
validatorsPerNode = validatorsPerServer div instancesCount
if paramCount() < 4:
echo "Usage: nim --verbosity:0 manage_testnet_hosts.nim NETWORK COMMAND"
quit 1
let
network = paramStr(3)
cmd = paramStr(4)
iterator nodes: tuple[server, container: string, firstValidator, lastValidator: int] =
for i in 0 ..< serverCount:
let
baseIdx = userValidators + i * validatorsPerServer
nodeName = if i == 0: "master-01" else: &"node-0{i}"
server = &"{nodeName}.do-ams3.nimbus.test.statusim.net"
for j in 1 .. instancesCount:
let firstIdx = baseIdx + j * validatorsPerNode
let lastIdx = firstIdx + validatorsPerNode - 1
yield (server, &"beacon-node-{network}-{j}", firstIdx, lastIdx)
case cmd
of "restart-nodes":
for n in nodes():
echo &"ssh {n.server} docker restart {n.container}"
of "redist-validators":
for n in nodes():
let dockerPath = &"/docker/{n.container}/data/BeaconNode/{network}"
echo &"ssh {n.server} 'sudo mkdir -p {dockerPath}/validators && sudo rm -f {dockerPath}/validators/* && " &
&"sudo ~/nimbus/vendor/nim-beacon-chain/scripts/download_validator_keys.sh {network} {n.firstValidator} {n.lastValidator} {dockerPath} && " &
&"sudo chown dockremap:docker -R {dockerPath}'"
else:
echo "Unrecognized command: ", cmd

View File

@ -29,3 +29,8 @@ The `beacon_node` binary has a `createTestnet` command.
Replace ENV vars with values that make sense to you.
Full tutorial coming soon.
## Maintaining the Status testnets
For detailed instructions, please see https://github.com/status-im/nimbus-private/blob/master/testnets-maintenance.md

View File

@ -10,34 +10,94 @@ source "$NETWORK_NAME.env"
cd ..
if [ -f .env ]; then
# allow server overrides for WWW_DIR and DATA_DIR
# allow server overrides for ETH2_TESTNET_DATA_DIR and DATA_DIR
source .env
fi
PUBLIC_IP=$(curl -s ifconfig.me)
NETWORK_DIR=$WWW_DIR/$NETWORK_NAME
echo ${BOOTSTRAP_HOST:="master-01.do-ams3.nimbus.test.statusim.net"} > /dev/null
NIM_FLAGS="-d:release -d:const_preset=$CONST_PRESET -d:SECONDS_PER_SLOT=$SECONDS_PER_SLOT -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH ${2:-}"
echo Execution plan:
nim c -d:"network_type=$NETWORK_TYPE" $NIM_FLAGS beacon_chain/beacon_node
echo "Testnet name : $NETWORK_NAME"
echo "Testnet files repo : ${ETH2_TESTNET_DATA_DIR:="nim-eth2-testnet-data"}"
echo "Beacon node data dir : ${DATA_DIR:="testnet-reset-data"}"
echo "Bootstrap node ip : ${BOOTSTRAP_IP:="$(dig +short $BOOTSTRAP_HOST)"}"
echo "Reset testnet at end : ${PUBLISH_TESTNET_RESETS:="1"}"
if [ ! -f $NETWORK_DIR/genesis.json ]; then
rm -f $NETWORK_DIR/*
beacon_chain/beacon_node makeDeposits \
--totalDeposits=$VALIDATOR_COUNT \
--depositDir="$NETWORK_DIR" \
--randomKeys=true
while true; do
read -p "Continue?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
if [[ ! -d "$ETH2_TESTNET_DATA_DIR" ]]; then
git clone git@github.com:status-im/nim-eth2-testnet-data "$ETH2_TESTNET_DATA_DIR"
fi
beacon_chain/beacon_node \
ETH2_TESTNET_DATA_DIR_ABS=$(cd "$ETH2_TESTNET_DATA_DIR"; pwd)
DATA_DIR_ABS=$(mkdir -p "$DATA_DIR"; cd "$DATA_DIR"; pwd)
NETWORK_DIR_ABS="$ETH2_TESTNET_DATA_DIR_ABS/www/$NETWORK_NAME"
DOCKER_BEACON_NODE="docker run -v $NETWORK_DIR_ABS:/network_dir -v $DATA_DIR_ABS:/data_dir statusteam/nimbus_beacon_node:$NETWORK_NAME"
cd docker
export GIT_REVISION=$(git rev-parse HEAD)
make build
if [ ! -f $NETWORK_DIR_ABS/genesis.ssz ]; then
rm -f $NETWORK_DIR_ABS/*
$DOCKER_BEACON_NODE makeDeposits \
--totalDeposits=$VALIDATOR_COUNT \
--depositsDir=/network_dir \
--randomKeys=false
fi
$DOCKER_BEACON_NODE \
--network=$NETWORK_NAME \
--dataDir=$DATA_DIR/node-0 \
--dataDir=/data_dir \
createTestnet \
--validatorsDir=$NETWORK_DIR \
--validatorsDir=/network_dir \
--totalValidators=$VALIDATOR_COUNT \
--lastUserValidator=$LAST_USER_VALIDATOR \
--outputGenesis=$NETWORK_DIR/genesis.json \
--outputNetwork=$NETWORK_DIR/network.json \
--bootstrapAddress=$PUBLIC_IP \
--outputGenesis=/network_dir/genesis.json \
--outputBootstrapNodes=/network_dir/bootstrap_nodes.txt \
--outputNetworkMetadata=/network_dir/network.json \
--bootstrapAddress=$BOOTSTRAP_IP \
--bootstrapPort=$BOOTSTRAP_PORT \
--genesisOffset=600 # Delay in seconds
--genesisOffset=60 # Delay in seconds
if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
echo Persisting testnet data to git...
pushd "$ETH2_TESTNET_DATA_DIR_ABS"
git add --all
git commit -m "Testnet reset"
git push
popd
echo Updating https://serenity-testnets.status.im/${NETWORK_NAME}...
ssh $BOOTSTRAP_HOST <<-SSH
cd /opt/nim-eth2-testnet-data
git reset --hard HEAD
git checkout master
git pull
SSH
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.
nim --verbosity:0 manage_testnet_hosts.nims $NETWORK_NAME redist-validators > /tmp/reset-network.sh
bash /tmp/reset-network.sh
echo Uploading bootstrap node network key
BOOTSTRAP_NODE_DOCKER_PATH=/docker/beacon-node-$NETWORK_NAME-1/data/BeaconNode/$NETWORK_NAME/
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

View File

@ -45,7 +45,7 @@ if [ ! -f "${LAST_VALIDATOR}" ]; then
$BEACON_NODE_BIN makeDeposits \
--totalDeposits="${NUM_VALIDATORS}" \
--depositDir="$VALIDATORS_DIR" \
--depositsDir="$VALIDATORS_DIR" \
--randomKeys=false \
$DEPOSIT_WEB3_URL_ARG \
--depositContractAddress="${DEPOSIT_CONTRACT_ADDRESS}"