Remove hard-coded variables from the manage_testnet_hosts script
This commit is contained in:
parent
3da4d4f23a
commit
1ef9f458ac
|
@ -111,6 +111,10 @@ proc addBootstrapNode(node: BeaconNode, bootstrapNode: BootstrapAddr) =
|
||||||
else:
|
else:
|
||||||
node.bootstrapNodes.add bootstrapNode
|
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.} =
|
proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async.} =
|
||||||
new result
|
new result
|
||||||
result.onBeaconBlock = onBeaconBlock
|
result.onBeaconBlock = onBeaconBlock
|
||||||
|
@ -128,8 +132,11 @@ proc init*(T: type BeaconNode, conf: BeaconNodeConf): Future[BeaconNode] {.async
|
||||||
|
|
||||||
let bootstrapFile = string conf.bootstrapNodesFile
|
let bootstrapFile = string conf.bootstrapNodesFile
|
||||||
if bootstrapFile.len > 0:
|
if bootstrapFile.len > 0:
|
||||||
for ln in lines(bootstrapFile):
|
result.useBootstrapFile(bootstrapFile)
|
||||||
result.addBootstrapNode BootstrapAddr.init(string ln)
|
|
||||||
|
let siteLocalBootstrapFile = conf.dataDir / "bootstrap_nodes.txt"
|
||||||
|
if fileExists(siteLocalBootstrapFile):
|
||||||
|
result.useBootstrapFile(siteLocalBootstrapFile)
|
||||||
|
|
||||||
result.attachedValidators = ValidatorPool.init
|
result.attachedValidators = ValidatorPool.init
|
||||||
|
|
||||||
|
|
|
@ -1,55 +1,73 @@
|
||||||
import
|
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
|
var
|
||||||
serverCount = 10
|
serverCount = 10
|
||||||
instancesCount = 2
|
instancesCount = 2
|
||||||
|
|
||||||
totalValidators = 1000
|
systemValidators = conf.totalValidators - conf.totalUserValidators
|
||||||
userValidators = 200
|
|
||||||
|
|
||||||
systemValidators = totalValidators - userValidators
|
|
||||||
validatorsPerServer = systemValidators div serverCount
|
validatorsPerServer = systemValidators div serverCount
|
||||||
validatorsPerNode = validatorsPerServer div instancesCount
|
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] =
|
iterator nodes: tuple[server, container: string, firstValidator, lastValidator: int] =
|
||||||
for i in 0 ..< serverCount:
|
for i in 0 ..< serverCount:
|
||||||
let
|
let
|
||||||
baseIdx = userValidators + i * validatorsPerServer
|
baseIdx = conf.totalUserValidators + i * validatorsPerServer
|
||||||
nodeName = if i == 0: "master-01" else: &"node-0{i}"
|
nodeName = if i == 0: "master-01" else: &"node-0{i}"
|
||||||
server = &"{nodeName}.do-ams3.nimbus.test.statusim.net"
|
server = &"{nodeName}.do-ams3.nimbus.test.statusim.net"
|
||||||
|
|
||||||
for j in 1 .. instancesCount:
|
for j in 0 ..< instancesCount:
|
||||||
let firstIdx = baseIdx + j * validatorsPerNode
|
let firstIdx = baseIdx + j * validatorsPerNode
|
||||||
let lastIdx = firstIdx + validatorsPerNode - 1
|
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
|
case conf.cmd
|
||||||
of "restart-nodes":
|
of restart_nodes:
|
||||||
for n in nodes():
|
for n in nodes():
|
||||||
echo &"ssh {n.server} docker restart {n.container}"
|
echo &"ssh {n.server} docker restart {n.container}"
|
||||||
|
|
||||||
of "redist-validators":
|
of redist_validators:
|
||||||
let depositsDir = paramStr(5)
|
|
||||||
for n in nodes():
|
for n in nodes():
|
||||||
var keysList = ""
|
var
|
||||||
|
keysList = ""
|
||||||
|
networkDataFiles = conf.networkDataDir & "/{genesis.ssz,bootstrap_nodes.txt}"
|
||||||
|
|
||||||
for i in n.firstValidator..n.lastValidator:
|
for i in n.firstValidator..n.lastValidator:
|
||||||
let validatorKey = fmt"v{i:07}.privkey"
|
let validatorKey = fmt"v{i:07}.privkey"
|
||||||
keysList.add " "
|
keysList.add " "
|
||||||
keysList.add depositsDir / validatorKey
|
keysList.add conf.depositsDir / validatorKey
|
||||||
|
|
||||||
let dockerPath = &"/docker/{n.container}/data/BeaconNode/{network}"
|
let dockerPath = &"/docker/{n.container}/data/BeaconNode/{conf.network}"
|
||||||
echo &"rsync {keysList} {n.server}:/tmp/nimbus-keys"
|
echo &"echo Distributing keys {n.firstValidator}..{n.lastValidator} to container {n.container}@{n.server} ... && \\"
|
||||||
echo &"ssh {n.server} 'sudo mkdir -p {dockerPath}/validators && sudo rm -f {dockerPath}/validators/* && " &
|
echo &" ssh {n.server} 'sudo rm -rf /tmp/nimbus && mkdir -p /tmp/nimbus' && \\"
|
||||||
&"sudo mv /tmp/nimbus-keys/* {dockerPath}/validators/ && " &
|
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}'"
|
&"sudo chown dockremap:docker -R {dockerPath}'"
|
||||||
else:
|
|
||||||
echo "Unrecognized command: ", cmd
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
#!/bin/bash
|
#!/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
|
# Deal with previous execution of the deamon leaving behind
|
||||||
# socket files that prevent the deamon from launching again
|
# socket files that prevent the deamon from launching again
|
||||||
# inside the container.
|
# inside the container:
|
||||||
|
killall p2pd
|
||||||
# killall p2pd
|
rm -rf /tmp/*
|
||||||
# rm -rf /tmp/*
|
|
||||||
|
|
||||||
if [[ "$2" == "" ]]; then
|
if [[ "$2" == "" ]]; then
|
||||||
# TODO This is a normal execution of a long-running testnet node.
|
# TODO This is a normal execution of a long-running testnet node.
|
||||||
|
|
|
@ -9,7 +9,7 @@ const
|
||||||
configFile = "config.yaml"
|
configFile = "config.yaml"
|
||||||
clientsOrg = "zah" # "eth2-clients"
|
clientsOrg = "zah" # "eth2-clients"
|
||||||
testnetsRepo = "eth2-testnets"
|
testnetsRepo = "eth2-testnets"
|
||||||
testnetsRepoGitUrl = "git://github.com/" & clientsOrg & "/" & testnetsRepo
|
testnetsRepoGitUrl = "https://github.com/" & clientsOrg & "/" & testnetsRepo
|
||||||
|
|
||||||
proc validateTestnetName(parts: openarray[string]): auto =
|
proc validateTestnetName(parts: openarray[string]): auto =
|
||||||
if parts.len != 2:
|
if parts.len != 2:
|
||||||
|
|
|
@ -41,6 +41,8 @@ ETH2_TESTNETS_ABS=$(cd "$ETH2_TESTNETS"; pwd)
|
||||||
NETWORK_DIR_ABS="$ETH2_TESTNETS_ABS/nimbus/$NETWORK_NAME"
|
NETWORK_DIR_ABS="$ETH2_TESTNETS_ABS/nimbus/$NETWORK_NAME"
|
||||||
DATA_DIR_ABS=$(mkdir -p "$DATA_DIR"; cd "$DATA_DIR"; pwd)
|
DATA_DIR_ABS=$(mkdir -p "$DATA_DIR"; cd "$DATA_DIR"; pwd)
|
||||||
DEPOSITS_DIR_ABS="$DATA_DIR_ABS/deposits"
|
DEPOSITS_DIR_ABS="$DATA_DIR_ABS/deposits"
|
||||||
|
DEPOSIT_CONTRACT_ADDRESS=""
|
||||||
|
DEPOSIT_CONTRACT_ADDRESS_ARG=""
|
||||||
|
|
||||||
if [ "$WEB3_URL" != "" ]; then
|
if [ "$WEB3_URL" != "" ]; then
|
||||||
WEB3_URL_ARG="--web3-url=$WEB3_URL"
|
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
|
make deposit_contract
|
||||||
|
|
||||||
DEPOSIT_CONTRACT_ADDRESS_ARG=""
|
|
||||||
|
|
||||||
if [ "$ETH1_PRIVATE_KEY" != "" ]; then
|
if [ "$ETH1_PRIVATE_KEY" != "" ]; then
|
||||||
DEPOSIT_CONTRACT_ADDRESS=$(./build/deposit_contract deploy $WEB3_URL_ARG --private-key=$ETH1_PRIVATE_KEY)
|
DEPOSIT_CONTRACT_ADDRESS=$(./build/deposit_contract deploy $WEB3_URL_ARG --private-key=$ETH1_PRIVATE_KEY)
|
||||||
DEPOSIT_CONTRACT_ADDRESS_ARG="--deposit-contract=$DEPOSIT_CONTRACT_ADDRESS"
|
DEPOSIT_CONTRACT_ADDRESS_ARG="--deposit-contract=$DEPOSIT_CONTRACT_ADDRESS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd docker
|
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
|
$DOCKER_BEACON_NODE makeDeposits \
|
||||||
rm -f $NETWORK_DIR_ABS/*
|
--quickstart-deposits=$QUICKSTART_VALIDATORS \
|
||||||
$DOCKER_BEACON_NODE makeDeposits \
|
--random-deposits=$RANDOM_VALIDATORS \
|
||||||
--quickstart-deposits=$QUICKSTART_VALIDATORS \
|
--deposits-dir=/deposits_dir
|
||||||
--random-deposits=$RANDOM_VALIDATORS \
|
|
||||||
--deposits-dir=/deposits_dir
|
|
||||||
fi
|
|
||||||
|
|
||||||
TOTAL_VALIDATORS="$(( $QUICKSTART_VALIDATORS + $RANDOM_VALIDATORS ))"
|
TOTAL_VALIDATORS="$(( $QUICKSTART_VALIDATORS + $RANDOM_VALIDATORS ))"
|
||||||
|
|
||||||
|
@ -92,7 +91,7 @@ fi
|
||||||
|
|
||||||
if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
|
if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
|
||||||
echo Persisting testnet data to git...
|
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 add genesis.ssz bootstrap_nodes.txt deposit_contract.txt
|
||||||
git commit -m "Reset of Nimbus $NETWORK_NAME"
|
git commit -m "Reset of Nimbus $NETWORK_NAME"
|
||||||
git push
|
git push
|
||||||
|
@ -101,7 +100,14 @@ if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
|
||||||
echo Redistributing validator keys to server nodes...
|
echo Redistributing validator keys to server nodes...
|
||||||
# TODO If we try to use direct piping here, bash doesn't execute all of the commands.
|
# 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.
|
# 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
|
bash /tmp/reset-network.sh
|
||||||
|
|
||||||
echo Uploading bootstrap node network key
|
echo Uploading bootstrap node network key
|
||||||
|
|
|
@ -3,7 +3,7 @@ NETWORK_TYPE=libp2p_daemon
|
||||||
SHARD_COUNT=16
|
SHARD_COUNT=16
|
||||||
SLOTS_PER_EPOCH=16
|
SLOTS_PER_EPOCH=16
|
||||||
SECONDS_PER_SLOT=30
|
SECONDS_PER_SLOT=30
|
||||||
QUICKSTART_VALIDATORS=192
|
QUICKSTART_VALIDATORS=32
|
||||||
RANDOM_VALIDATORS=0
|
RANDOM_VALIDATORS=160
|
||||||
BOOTSTRAP_PORT=9000
|
BOOTSTRAP_PORT=9000
|
||||||
WEB3_URL=wss://goerli.infura.io/ws/v3/809a18497dd74102b5f37d25aae3c85a
|
WEB3_URL=wss://goerli.infura.io/ws/v3/809a18497dd74102b5f37d25aae3c85a
|
||||||
|
|
Loading…
Reference in New Issue