Finalizing setup for testnet1; Auto-restart of the docker containers after testnet resets

This commit is contained in:
Zahary Karadjov 2019-11-12 12:14:55 +00:00 committed by Dustin Brody
parent 7fe18732d5
commit 5a6a8e9520
3 changed files with 54 additions and 30 deletions

View File

@ -29,20 +29,16 @@ type
defaultValue: 0
name: "user-validators" }: int
Node = object
id: int
server: string
container: string
var conf = load CliConfig
var
serverCount = 10
instancesCount = 2
systemValidators = conf.totalValidators - conf.totalUserValidators
let customValidatorAssignments = {
"testnet0": proc (nodeIdx: int): int =
if nodeidx < 4:
systemValidators div 4
else:
0
}
proc findOrDefault[K, V](tupleList: openarray[(K, V)], key: K, default: V): V =
for t in tupleList:
@ -51,29 +47,51 @@ proc findOrDefault[K, V](tupleList: openarray[(K, V)], key: K, default: V): V =
return default
let defaultValidatorAssignment = proc (nodeIdx: int): int =
(systemValidators div serverCount) div instancesCount
iterator nodes: tuple[server, container: string, firstValidator, lastValidator: int] =
var nextValidatorIdx = conf.totalUserValidators
iterator nodes: Node =
for i in 0 ..< serverCount:
let
nodeName = if i == 0: "master-01" else: &"node-0{i}"
server = &"{nodeName}.do-ams3.nimbus.test.statusim.net"
serverShortName = if i == 0: "master-01" else: &"node-0{i}"
server = &"{serverShortName}.do-ams3.nimbus.test.statusim.net"
for j in 0 ..< instancesCount:
let
globalNodeIdx = i*instancesCount + j
validatorAssignmentFn = customValidatorAssignments.findOrDefault(
conf.network, defaultValidatorAssignment)
nodeValidatorCount = validatorAssignmentFn(globalNodeIdx)
yield Node(id: i*instancesCount + j,
server: server,
container: &"beacon-node-{conf.network}-{j+1}")
yield (server,
&"beacon-node-{conf.network}-{j+1}",
nextValidatorIdx,
nextValidatorIdx + nodeValidatorCount)
iterator validatorAssignments: tuple[node: Node; firstValidator, lastValidator: int] =
let
systemValidators = conf.totalValidators - conf.totalUserValidators
inc nextValidatorIdx, nodeValidatorCount
defaultValidatorAssignment = proc (nodeIdx: int): int =
(systemValidators div serverCount) div instancesCount
customValidatorAssignments = {
# This is used just to force the correct type of the table
"default": defaultValidatorAssignment
,
"testnet0": proc (nodeIdx: int): int =
if nodeidx < 4:
systemValidators div 4
else:
0
,
"testnet1": proc (nodeIdx: int): int =
if nodeIdx == 0: systemValidators
else: 0
}
var nextValidatorIdx = conf.totalUserValidators
for node in nodes():
let
validatorAssignmentFn = customValidatorAssignments.findOrDefault(
conf.network, defaultValidatorAssignment)
nodeValidatorCount = validatorAssignmentFn(node.id)
yield (node,
nextValidatorIdx,
nextValidatorIdx + nodeValidatorCount)
inc nextValidatorIdx, nodeValidatorCount
case conf.cmd
of restart_nodes:
@ -81,18 +99,18 @@ of restart_nodes:
echo &"ssh {n.server} docker restart {n.container}"
of reset_network:
for n in nodes():
for n, firstValidator, lastValidator in validatorAssignments():
var
keysList = ""
networkDataFiles = conf.networkDataDir & "/{genesis.ssz,bootstrap_nodes.txt}"
for i in n.firstValidator ..< n.lastValidator:
for i in firstValidator ..< lastValidator:
let validatorKey = fmt"v{i:07}.privkey"
keysList.add " "
keysList.add conf.depositsDir / validatorKey
let dockerPath = &"/docker/{n.container}/data/BeaconNode"
echo &"echo Syncing {n.lastValidator - n.firstValidator} keys starting from {n.firstValidator} to container {n.container}@{n.server} ... && \\"
echo &"echo Syncing {lastValidator - firstValidator} keys starting from {firstValidator} 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/ && \\"
if keysList.len > 0: echo &" rsync {keysList} {n.server}:/tmp/nimbus/keys/ && \\"

View File

@ -122,4 +122,10 @@ if [[ $PUBLISH_TESTNET_RESETS != "0" ]]; then
git commit -m "Reset of Nimbus $NETWORK_NAME"
git push
popd
../env.sh nim --verbosity:0 manage_testnet_hosts.nims restart_nodes \
--network=$NETWORK_NAME \
> /tmp/restart-nodes.sh
bash /tmp/restart-nodes.sh
fi

@ -1 +1 @@
Subproject commit 4e487bedf1e3b4f03087bc608a8747f0d7361389
Subproject commit 7a607bfd3d83be86f153517636370b76f3d7cf25