Remove hard-coded variables from the manage_testnet_hosts script

This commit is contained in:
Zahary Karadjov 2019-10-29 15:41:10 +02:00
parent 3da4d4f23a
commit 1ef9f458ac
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
6 changed files with 82 additions and 49 deletions

View File

@ -111,6 +111,10 @@ proc addBootstrapNode(node: BeaconNode, bootstrapNode: BootstrapAddr) =
else:
node.bootstrapNodes.add bootstrapNode
proc useBootstrapFile(node: BeaconNode, bootstrapFile: string) =
for ln in lines(bootstrapFile):
node.addBootstrapNode BootstrapAddr.init(string ln)
proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async.} =
new result
result.onBeaconBlock = onBeaconBlock
@ -128,8 +132,11 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async
let bootstrapFile = string conf.bootstrapNodesFile
if bootstrapFile.len > 0:
for ln in lines(bootstrapFile):
result.addBootstrapNode BootstrapAddr.init(string ln)
result.useBootstrapFile(bootstrapFile)
let siteLocalBootstrapFile = conf.dataDir / "bootstrap_nodes.txt"
if fileExists(siteLocalBootstrapFile):
result.useBootstrapFile(siteLocalBootstrapFile)
result.attachedValidators = ValidatorPool.init

View File

@ -1,55 +1,73 @@
import
strformat, ospaths
strformat, ospaths, confutils
type
Command = enum
restart_nodes
redist_validators
CliConfig = object
network: string
case cmd {.command.}: Command
of restart_nodes:
discard
of redist_validators:
depositsDir {.
longform: "deposits-dir" }: string
networkDataDir {.
longform: "network-data-dir"}: string
totalValidators {.
longform: "total-validators" }: int
totalUserValidators {.
longform: "user-validators" }: int
var conf = load CliConfig
var
serverCount = 10
instancesCount = 2
totalValidators = 1000
userValidators = 200
systemValidators = totalValidators - userValidators
systemValidators = conf.totalValidators - conf.totalUserValidators
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
baseIdx = conf.totalUserValidators + 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:
for j in 0 ..< instancesCount:
let firstIdx = baseIdx + j * validatorsPerNode
let lastIdx = firstIdx + validatorsPerNode - 1
yield (server, &"beacon-node-{network}-{j}", firstIdx, lastIdx)
yield (server, &"beacon-node-{conf.network}-{j+1}", firstIdx, lastIdx)
case cmd
of "restart-nodes":
case conf.cmd
of restart_nodes:
for n in nodes():
echo &"ssh {n.server} docker restart {n.container}"
of "redist-validators":
let depositsDir = paramStr(5)
of redist_validators:
for n in nodes():
var keysList = ""
var
keysList = ""
networkDataFiles = conf.networkDataDir & "/{genesis.ssz,bootstrap_nodes.txt}"
for i in n.firstValidator..n.lastValidator:
let validatorKey = fmt"v{i:07}.privkey"
keysList.add " "
keysList.add depositsDir / validatorKey
keysList.add conf.depositsDir / validatorKey
let dockerPath = &"/docker/{n.container}/data/BeaconNode/{network}"
echo &"rsync {keysList} {n.server}:/tmp/nimbus-keys"
echo &"ssh {n.server} 'sudo mkdir -p {dockerPath}/validators && sudo rm -f {dockerPath}/validators/* && " &
&"sudo mv /tmp/nimbus-keys/* {dockerPath}/validators/ && " &
let dockerPath = &"/docker/{n.container}/data/BeaconNode/{conf.network}"
echo &"echo Distributing keys {n.firstValidator}..{n.lastValidator} to container {n.container}@{n.server} ... && \\"
echo &" ssh {n.server} 'sudo rm -rf /tmp/nimbus && mkdir -p /tmp/nimbus' && \\"
echo &" rsync {networkDataFiles} {n.server}:/tmp/nimbus/net-data/ && \\"
echo &" rsync {keysList} {n.server}:/tmp/nimbus/keys/ && \\"
echo &" ssh {n.server} 'sudo mkdir -p {dockerPath}/validators && sudo rm -f {dockerPath}/validators/* && " &
&"sudo mv /tmp/nimbus/keys/* {dockerPath}/validators/ && " &
&"sudo mv /tmp/nimbus/net-data/* {dockerPath}/ && " &
&"sudo chown dockremap:docker -R {dockerPath}'"
else:
echo "Unrecognized command: ", cmd

View File

@ -1,11 +1,13 @@
#!/bin/bash
# TODO This script will no longer be necessary once we switch
# to the native LibP2P
# Deal with previous execution of the deamon leaving behind
# socket files that prevent the deamon from launching again
# inside the container.
# killall p2pd
# rm -rf /tmp/*
# inside the container:
killall p2pd
rm -rf /tmp/*
if [[ "$2" == "" ]]; then
# TODO This is a normal execution of a long-running testnet node.

View File

@ -9,7 +9,7 @@ const
configFile = "config.yaml"
clientsOrg = "zah" # "eth2-clients"
testnetsRepo = "eth2-testnets"
testnetsRepoGitUrl = "git://github.com/" & clientsOrg & "/" & testnetsRepo
testnetsRepoGitUrl = "https://github.com/" & clientsOrg & "/" & testnetsRepo
proc validateTestnetName(parts: openarray[string]): auto =
if parts.len != 2:

View File

@ -41,6 +41,8 @@ ETH2_TESTNETS_ABS=$(cd "$ETH2_TESTNETS"; pwd)
NETWORK_DIR_ABS="$ETH2_TESTNETS_ABS/nimbus/$NETWORK_NAME"
DATA_DIR_ABS=$(mkdir -p "$DATA_DIR"; cd "$DATA_DIR"; pwd)
DEPOSITS_DIR_ABS="$DATA_DIR_ABS/deposits"
DEPOSIT_CONTRACT_ADDRESS=""
DEPOSIT_CONTRACT_ADDRESS_ARG=""
if [ "$WEB3_URL" != "" ]; then
WEB3_URL_ARG="--web3-url=$WEB3_URL"
@ -52,24 +54,21 @@ DOCKER_BEACON_NODE="docker run -v $DEPOSITS_DIR_ABS:/deposits_dir -v $NETWORK_DI
make deposit_contract
DEPOSIT_CONTRACT_ADDRESS_ARG=""
if [ "$ETH1_PRIVATE_KEY" != "" ]; then
DEPOSIT_CONTRACT_ADDRESS=$(./build/deposit_contract deploy $WEB3_URL_ARG --private-key=$ETH1_PRIVATE_KEY)
DEPOSIT_CONTRACT_ADDRESS_ARG="--deposit-contract=$DEPOSIT_CONTRACT_ADDRESS"
fi
cd docker
export NETWORK=$NETWORK_NAME
export GIT_REVISION=$(git rev-parse HEAD)
make build NETWORK=$NETWORK_NAME 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 \
--quickstart-deposits=$QUICKSTART_VALIDATORS \
--random-deposits=$RANDOM_VALIDATORS \
--deposits-dir=/deposits_dir
fi
$DOCKER_BEACON_NODE makeDeposits \
--quickstart-deposits=$QUICKSTART_VALIDATORS \
--random-deposits=$RANDOM_VALIDATORS \
--deposits-dir=/deposits_dir
TOTAL_VALIDATORS="$(( $QUICKSTART_VALIDATORS + $RANDOM_VALIDATORS ))"
@ -92,7 +91,7 @@ fi
if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
echo Persisting testnet data to git...
pushd "$ETH2_TESTNETS_ABS"
pushd "$NETWORK_DIR_ABS"
git add genesis.ssz bootstrap_nodes.txt deposit_contract.txt
git commit -m "Reset of Nimbus $NETWORK_NAME"
git push
@ -101,7 +100,14 @@ 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.
nim --verbosity:0 manage_testnet_hosts.nims $NETWORK_NAME redist-validators $DEPOSITS_DIR_ABS > /tmp/reset-network.sh
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
bash /tmp/reset-network.sh
echo Uploading bootstrap node network key

View File

@ -3,7 +3,7 @@ NETWORK_TYPE=libp2p_daemon
SHARD_COUNT=16
SLOTS_PER_EPOCH=16
SECONDS_PER_SLOT=30
QUICKSTART_VALIDATORS=192
RANDOM_VALIDATORS=0
QUICKSTART_VALIDATORS=32
RANDOM_VALIDATORS=160
BOOTSTRAP_PORT=9000
WEB3_URL=wss://goerli.infura.io/ws/v3/809a18497dd74102b5f37d25aae3c85a