2019-09-10 22:13:27 +00:00
|
|
|
import
|
2019-10-29 13:41:10 +00:00
|
|
|
strformat, ospaths, confutils
|
|
|
|
|
|
|
|
type
|
|
|
|
Command = enum
|
|
|
|
restart_nodes
|
2019-11-05 13:00:11 +00:00
|
|
|
reset_network
|
2019-10-29 13:41:10 +00:00
|
|
|
|
|
|
|
CliConfig = object
|
|
|
|
network: string
|
|
|
|
|
|
|
|
case cmd {.command.}: Command
|
|
|
|
of restart_nodes:
|
|
|
|
discard
|
|
|
|
|
2019-11-05 13:00:11 +00:00
|
|
|
of reset_network:
|
2019-10-29 13:41:10 +00:00
|
|
|
depositsDir {.
|
2019-11-05 13:00:11 +00:00
|
|
|
defaultValue: "deposits"
|
2019-10-29 13:41:10 +00:00
|
|
|
longform: "deposits-dir" }: string
|
2019-11-05 13:00:11 +00:00
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
networkDataDir {.
|
2019-11-05 13:00:11 +00:00
|
|
|
defaultValue: "data"
|
2019-10-29 13:41:10 +00:00
|
|
|
longform: "network-data-dir"}: string
|
2019-11-05 13:00:11 +00:00
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
totalValidators {.
|
|
|
|
longform: "total-validators" }: int
|
2019-11-05 13:00:11 +00:00
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
totalUserValidators {.
|
2019-11-05 13:00:11 +00:00
|
|
|
defaultValue: 0
|
2019-10-29 13:41:10 +00:00
|
|
|
longform: "user-validators" }: int
|
|
|
|
|
|
|
|
var conf = load CliConfig
|
2019-09-10 22:13:27 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
serverCount = 10
|
|
|
|
instancesCount = 2
|
2019-10-29 13:41:10 +00:00
|
|
|
systemValidators = conf.totalValidators - conf.totalUserValidators
|
2019-11-05 13:00:11 +00:00
|
|
|
|
|
|
|
let customValidatorAssignments = {
|
|
|
|
"testnet0": proc (nodeIdx: int): int =
|
|
|
|
if nodeidx < 2:
|
|
|
|
systemValidators div 2
|
|
|
|
else:
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
proc findOrDefault[K, V](tupleList: openarray[(K, V)], key: K, default: V): V =
|
|
|
|
for t in tupleList:
|
|
|
|
if t[0] == key:
|
|
|
|
return t[1]
|
|
|
|
|
|
|
|
return default
|
|
|
|
|
|
|
|
let defaultValidatorAssignment = proc (nodeIdx: int): int =
|
|
|
|
(systemValidators div serverCount) div instancesCount
|
2019-09-10 22:13:27 +00:00
|
|
|
|
|
|
|
iterator nodes: tuple[server, container: string, firstValidator, lastValidator: int] =
|
2019-11-05 13:00:11 +00:00
|
|
|
var nextValidatorIdx = conf.totalUserValidators
|
2019-09-10 22:13:27 +00:00
|
|
|
for i in 0 ..< serverCount:
|
|
|
|
let
|
|
|
|
nodeName = if i == 0: "master-01" else: &"node-0{i}"
|
|
|
|
server = &"{nodeName}.do-ams3.nimbus.test.statusim.net"
|
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
for j in 0 ..< instancesCount:
|
2019-11-05 13:00:11 +00:00
|
|
|
let
|
|
|
|
globalNodeIdx = i*instancesCount + j
|
|
|
|
validatorAssignmentFn = customValidatorAssignments.findOrDefault(
|
|
|
|
conf.network, defaultValidatorAssignment)
|
|
|
|
nodeValidatorCount = validatorAssignmentFn(globalNodeIdx)
|
|
|
|
|
|
|
|
yield (server,
|
|
|
|
&"beacon-node-{conf.network}-{j+1}",
|
|
|
|
nextValidatorIdx,
|
|
|
|
nextValidatorIdx + nodeValidatorCount)
|
|
|
|
|
|
|
|
inc nextValidatorIdx, nodeValidatorCount
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
case conf.cmd
|
|
|
|
of restart_nodes:
|
2019-09-10 22:13:27 +00:00
|
|
|
for n in nodes():
|
|
|
|
echo &"ssh {n.server} docker restart {n.container}"
|
2019-10-29 03:58:31 +00:00
|
|
|
|
2019-11-05 13:00:11 +00:00
|
|
|
of reset_network:
|
2019-09-10 22:13:27 +00:00
|
|
|
for n in nodes():
|
2019-10-29 13:41:10 +00:00
|
|
|
var
|
|
|
|
keysList = ""
|
|
|
|
networkDataFiles = conf.networkDataDir & "/{genesis.ssz,bootstrap_nodes.txt}"
|
|
|
|
|
2019-11-05 00:41:12 +00:00
|
|
|
for i in n.firstValidator ..< n.lastValidator:
|
2019-10-29 03:58:31 +00:00
|
|
|
let validatorKey = fmt"v{i:07}.privkey"
|
|
|
|
keysList.add " "
|
2019-10-29 13:41:10 +00:00
|
|
|
keysList.add conf.depositsDir / validatorKey
|
2019-10-29 03:58:31 +00:00
|
|
|
|
2019-10-29 16:35:21 +00:00
|
|
|
let dockerPath = &"/docker/{n.container}/data/BeaconNode"
|
2019-11-05 00:41:12 +00:00
|
|
|
echo &"echo Syncing {n.lastValidator - n.firstValidator} keys starting from {n.firstValidator} to container {n.container}@{n.server} ... && \\"
|
|
|
|
echo &" ssh {n.server} 'sudo rm -rf /tmp/nimbus && mkdir -p /tmp/nimbus/' && \\"
|
2019-10-29 13:41:10 +00:00
|
|
|
echo &" rsync {networkDataFiles} {n.server}:/tmp/nimbus/net-data/ && \\"
|
2019-11-05 00:41:12 +00:00
|
|
|
if keysList.len > 0: echo &" rsync {keysList} {n.server}:/tmp/nimbus/keys/ && \\"
|
2019-11-05 13:00:11 +00:00
|
|
|
|
|
|
|
echo &" ssh {n.server} 'sudo docker container stop {n.container} && " &
|
|
|
|
&"sudo mkdir -p {dockerPath}/validators && " &
|
|
|
|
&"sudo rm -f {dockerPath}/validators/* && " &
|
|
|
|
&"sudo rm -f {dockerPath}/db" &
|
2019-11-05 00:41:12 +00:00
|
|
|
(if keysList.len > 0: &"sudo mv /tmp/nimbus/keys/* {dockerPath}/validators/ && " else: "") &
|
2019-10-29 13:41:10 +00:00
|
|
|
&"sudo mv /tmp/nimbus/net-data/* {dockerPath}/ && " &
|
2019-09-10 22:13:27 +00:00
|
|
|
&"sudo chown dockremap:docker -R {dockerPath}'"
|
2019-10-29 13:41:10 +00:00
|
|
|
|