2018-12-19 12:58:53 +00:00
|
|
|
import
|
|
|
|
os, ospaths, strutils, strformat,
|
2019-02-06 17:56:04 +00:00
|
|
|
chronos, nimcrypto, json_serialization, confutils,
|
2019-02-14 22:03:45 +00:00
|
|
|
spec/[datatypes, digest, crypto], conf, time, ssz,
|
2018-12-19 12:58:53 +00:00
|
|
|
../tests/testutil
|
|
|
|
|
|
|
|
proc writeFile(filename: string, value: auto) =
|
|
|
|
Json.saveFile(filename, value, pretty = true)
|
2018-12-28 16:51:40 +00:00
|
|
|
echo "Wrote ", filename
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
proc genSingleValidator(path: string): (ValidatorPubKey,
|
2019-02-14 22:03:45 +00:00
|
|
|
ValidatorPrivKey) =
|
2018-12-19 12:58:53 +00:00
|
|
|
var v: PrivateValidatorData
|
2019-02-06 19:58:18 +00:00
|
|
|
v.privKey = newPrivKey()
|
2019-02-15 16:33:32 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
writeFile(path, v)
|
|
|
|
|
2019-02-06 19:58:18 +00:00
|
|
|
assert v.privKey != ValidatorPrivKey(), "Private key shouldn't be zero"
|
2019-02-14 22:03:45 +00:00
|
|
|
return (v.privKey.pubKey(), v.privKey)
|
2018-12-08 14:17:47 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
# TODO: Make these more comprehensive and find them a new home
|
|
|
|
type
|
|
|
|
Ether* = distinct int64
|
|
|
|
GWei* = distinct int64
|
|
|
|
|
|
|
|
template eth*(x: SomeInteger): Ether = Ether(x)
|
|
|
|
template gwei*(x: Ether): Gwei = Gwei(int(x) * 1000000000)
|
2018-12-08 14:17:47 +00:00
|
|
|
|
2019-01-23 18:45:15 +00:00
|
|
|
cli do (validators: int,
|
|
|
|
outputDir: string,
|
|
|
|
startupDelay = 0):
|
2018-12-08 14:17:47 +00:00
|
|
|
|
2019-01-23 18:45:15 +00:00
|
|
|
if validators < 64:
|
2018-12-19 12:58:53 +00:00
|
|
|
echo "The number of validators must be higher than ", EPOCH_LENGTH, " (EPOCH_LENGTH)"
|
|
|
|
echo "There must be at least one validator assigned per slot."
|
|
|
|
quit 1
|
|
|
|
|
|
|
|
var startupData: ChainStartupData
|
|
|
|
|
2019-01-23 18:45:15 +00:00
|
|
|
for i in 1 .. validators:
|
2019-02-14 22:03:45 +00:00
|
|
|
let (pubKey, privKey) =
|
2019-01-23 18:45:15 +00:00
|
|
|
genSingleValidator(outputDir / &"validator-{i:02}.json")
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2018-12-28 16:51:40 +00:00
|
|
|
let
|
|
|
|
withdrawalCredentials = makeFakeHash(i)
|
|
|
|
|
|
|
|
proofOfPossessionData = DepositInput(
|
|
|
|
pubkey: pubKey,
|
2019-02-07 20:13:10 +00:00
|
|
|
withdrawal_credentials: withdrawalCredentials)
|
2018-12-28 16:51:40 +00:00
|
|
|
|
2019-02-05 16:13:29 +00:00
|
|
|
proofOfPossession = bls_sign(
|
|
|
|
privkey, hash_tree_root_final(proofOfPossessionData).data,
|
|
|
|
0 # TODO - domain
|
|
|
|
)
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
startupData.validatorDeposits.add Deposit(
|
|
|
|
deposit_data: DepositData(
|
2019-01-21 18:26:58 +00:00
|
|
|
amount: MAX_DEPOSIT_AMOUNT,
|
2018-12-19 12:58:53 +00:00
|
|
|
timestamp: now(),
|
2018-12-27 20:14:37 +00:00
|
|
|
deposit_input: DepositInput(
|
2018-12-19 12:58:53 +00:00
|
|
|
pubkey: pubKey,
|
|
|
|
proof_of_possession: proofOfPossession,
|
2019-02-07 20:13:10 +00:00
|
|
|
withdrawal_credentials: withdrawalCredentials)))
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-01-23 18:45:15 +00:00
|
|
|
writeFile(outputDir / "startup.json", startupData)
|
2018-12-08 14:17:47 +00:00
|
|
|
|