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 defaultValue: 0
name: "user-validators" }: int name: "user-validators" }: int
Node = object
id: int
server: string
container: string
var conf = load CliConfig var conf = load CliConfig
var var
serverCount = 10 serverCount = 10
instancesCount = 2 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 = proc findOrDefault[K, V](tupleList: openarray[(K, V)], key: K, default: V): V =
for t in tupleList: for t in tupleList:
@ -51,25 +47,47 @@ proc findOrDefault[K, V](tupleList: openarray[(K, V)], key: K, default: V): V =
return default return default
let defaultValidatorAssignment = proc (nodeIdx: int): int = iterator nodes: Node =
(systemValidators div serverCount) div instancesCount
iterator nodes: tuple[server, container: string, firstValidator, lastValidator: int] =
var nextValidatorIdx = conf.totalUserValidators
for i in 0 ..< serverCount: for i in 0 ..< serverCount:
let let
nodeName = if i == 0: "master-01" else: &"node-0{i}" serverShortName = if i == 0: "master-01" else: &"node-0{i}"
server = &"{nodeName}.do-ams3.nimbus.test.statusim.net" server = &"{serverShortName}.do-ams3.nimbus.test.statusim.net"
for j in 0 ..< instancesCount: for j in 0 ..< instancesCount:
yield Node(id: i*instancesCount + j,
server: server,
container: &"beacon-node-{conf.network}-{j+1}")
iterator validatorAssignments: tuple[node: Node; firstValidator, lastValidator: int] =
let
systemValidators = conf.totalValidators - conf.totalUserValidators
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 let
globalNodeIdx = i*instancesCount + j
validatorAssignmentFn = customValidatorAssignments.findOrDefault( validatorAssignmentFn = customValidatorAssignments.findOrDefault(
conf.network, defaultValidatorAssignment) conf.network, defaultValidatorAssignment)
nodeValidatorCount = validatorAssignmentFn(globalNodeIdx) nodeValidatorCount = validatorAssignmentFn(node.id)
yield (server, yield (node,
&"beacon-node-{conf.network}-{j+1}",
nextValidatorIdx, nextValidatorIdx,
nextValidatorIdx + nodeValidatorCount) nextValidatorIdx + nodeValidatorCount)
@ -81,18 +99,18 @@ of restart_nodes:
echo &"ssh {n.server} docker restart {n.container}" echo &"ssh {n.server} docker restart {n.container}"
of reset_network: of reset_network:
for n in nodes(): for n, firstValidator, lastValidator in validatorAssignments():
var var
keysList = "" keysList = ""
networkDataFiles = conf.networkDataDir & "/{genesis.ssz,bootstrap_nodes.txt}" 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" let validatorKey = fmt"v{i:07}.privkey"
keysList.add " " keysList.add " "
keysList.add conf.depositsDir / validatorKey keysList.add conf.depositsDir / validatorKey
let dockerPath = &"/docker/{n.container}/data/BeaconNode" 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 &" ssh {n.server} 'sudo rm -rf /tmp/nimbus && mkdir -p /tmp/nimbus/' && \\"
echo &" rsync {networkDataFiles} {n.server}:/tmp/nimbus/net-data/ && \\" echo &" rsync {networkDataFiles} {n.server}:/tmp/nimbus/net-data/ && \\"
if keysList.len > 0: echo &" rsync {keysList} {n.server}:/tmp/nimbus/keys/ && \\" 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 commit -m "Reset of Nimbus $NETWORK_NAME"
git push git push
popd 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 fi

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