2019-09-10 22:13:27 +00:00
|
|
|
import
|
2019-11-25 14:36:25 +00:00
|
|
|
strformat, os, confutils
|
2019-10-29 13:41:10 +00:00
|
|
|
|
|
|
|
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-11-11 14:43:12 +00:00
|
|
|
name: "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-11-11 14:43:12 +00:00
|
|
|
name: "network-data-dir" }: string
|
2019-11-05 13:00:11 +00:00
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
totalValidators {.
|
2019-11-11 14:43:12 +00:00
|
|
|
name: "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-11-11 14:43:12 +00:00
|
|
|
name: "user-validators" }: int
|
2019-10-29 13:41:10 +00:00
|
|
|
|
2019-11-12 12:14:55 +00:00
|
|
|
Node = object
|
|
|
|
id: int
|
|
|
|
server: string
|
|
|
|
container: string
|
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
var conf = load CliConfig
|
2019-09-10 22:13:27 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
serverCount = 10
|
|
|
|
instancesCount = 2
|
2019-11-05 13:00:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-11-12 12:14:55 +00:00
|
|
|
iterator nodes: Node =
|
2019-09-10 22:13:27 +00:00
|
|
|
for i in 0 ..< serverCount:
|
|
|
|
let
|
2019-11-12 12:14:55 +00:00
|
|
|
serverShortName = if i == 0: "master-01" else: &"node-0{i}"
|
2020-01-28 20:28:52 +00:00
|
|
|
server = &"{serverShortName}.aws-eu-central-1a.nimbus.test.statusim.net"
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-10-29 13:41:10 +00:00
|
|
|
for j in 0 ..< instancesCount:
|
2019-11-12 12:14:55 +00:00
|
|
|
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 =
|
2019-11-14 14:10:14 +00:00
|
|
|
if nodeidx < 4:
|
|
|
|
systemValidators div 4
|
|
|
|
else:
|
|
|
|
0
|
2019-11-12 12:14:55 +00:00
|
|
|
}
|
2019-11-05 13:00:11 +00:00
|
|
|
|
2019-11-12 12:14:55 +00:00
|
|
|
var nextValidatorIdx = conf.totalUserValidators
|
|
|
|
for node in nodes():
|
|
|
|
let
|
|
|
|
validatorAssignmentFn = customValidatorAssignments.findOrDefault(
|
|
|
|
conf.network, defaultValidatorAssignment)
|
|
|
|
nodeValidatorCount = validatorAssignmentFn(node.id)
|
2019-11-05 13:00:11 +00:00
|
|
|
|
2019-11-12 12:14:55 +00:00
|
|
|
yield (node,
|
|
|
|
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():
|
2020-02-11 16:45:52 +00:00
|
|
|
if n.id mod 2 == 0:
|
2020-06-03 00:18:25 +00:00
|
|
|
echo &"echo Pulling container image on {n.server} ..."
|
2020-02-11 16:45:52 +00:00
|
|
|
# This will only print one line: "docker.io/statusteam/nimbus_beacon_node:testnet1".
|
|
|
|
echo &"ssh {n.server} docker pull -q statusteam/nimbus_beacon_node:{conf.network}"
|
2020-06-03 00:18:25 +00:00
|
|
|
echo &"echo Starting container {n.container}@{n.server} ..."
|
2020-02-11 16:45:52 +00:00
|
|
|
# docker-compose will rebuild the container if it detects a newer image.
|
|
|
|
# Prints: "Recreating beacon-node-testnet1-1 ... done".
|
2020-03-26 18:07:19 +00:00
|
|
|
echo &"ssh {n.server} 'cd /docker/{n.container} && docker-compose --compatibility up -d'"
|
2019-10-29 03:58:31 +00:00
|
|
|
|
2019-11-05 13:00:11 +00:00
|
|
|
of reset_network:
|
2019-11-12 12:14:55 +00:00
|
|
|
for n, firstValidator, lastValidator in validatorAssignments():
|
2019-10-29 13:41:10 +00:00
|
|
|
var
|
|
|
|
keysList = ""
|
|
|
|
networkDataFiles = conf.networkDataDir & "/{genesis.ssz,bootstrap_nodes.txt}"
|
|
|
|
|
2019-11-12 12:14:55 +00:00
|
|
|
for i in firstValidator ..< 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-12 12:14:55 +00:00
|
|
|
echo &"echo Syncing {lastValidator - firstValidator} keys starting from {firstValidator} to container {n.container}@{n.server} ... && \\"
|
2019-11-05 00:41:12 +00:00
|
|
|
echo &" ssh {n.server} 'sudo rm -rf /tmp/nimbus && mkdir -p /tmp/nimbus/' && \\"
|
2020-02-11 16:45:52 +00:00
|
|
|
echo &" rsync -a -zz {networkDataFiles} {n.server}:/tmp/nimbus/net-data/ && \\"
|
|
|
|
if keysList.len > 0:
|
|
|
|
echo &" rsync -a -zz {keysList} {n.server}:/tmp/nimbus/keys/ && \\"
|
2019-11-05 13:00:11 +00:00
|
|
|
|
2020-02-26 16:59:31 +00:00
|
|
|
echo &" ssh {n.server} 'sudo docker container stop {n.container}; " &
|
2019-11-05 13:00:11 +00:00
|
|
|
&"sudo mkdir -p {dockerPath}/validators && " &
|
2019-11-05 15:33:06 +00:00
|
|
|
&"sudo rm -rf {dockerPath}/validators/* && " &
|
|
|
|
&"sudo rm -rf {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
|
|
|
|