2018-11-23 23:58:49 +00:00
|
|
|
import
|
2018-12-19 12:58:53 +00:00
|
|
|
os, options,
|
2019-01-16 23:01:15 +00:00
|
|
|
confutils/defs, chronicles/options as chroniclesOptions,
|
2019-02-05 16:13:29 +00:00
|
|
|
json_serialization,
|
2019-02-14 21:41:04 +00:00
|
|
|
spec/[crypto, datatypes], time
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
export
|
|
|
|
json_serialization
|
2018-11-23 23:58:49 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
ValidatorKeyPath* = distinct string
|
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
StartUpCommand* = enum
|
|
|
|
noCommand
|
|
|
|
createChain
|
|
|
|
|
2018-11-29 01:08:34 +00:00
|
|
|
BeaconNodeConf* = object
|
2019-01-16 23:01:15 +00:00
|
|
|
logLevel* {.
|
|
|
|
desc: "Sets the log level",
|
|
|
|
defaultValue: enabledLogLevel
|
|
|
|
.}: LogLevel
|
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
case cmd* {.
|
|
|
|
command
|
|
|
|
defaultValue: noCommand.}: StartUpCommand
|
|
|
|
|
|
|
|
of noCommand:
|
|
|
|
dataDir* {.
|
|
|
|
desc: "The directory where nimbus will store all blockchain data."
|
|
|
|
shortform: "d"
|
|
|
|
defaultValue: getConfigDir() / "nimbus".}: DirPath
|
|
|
|
|
|
|
|
bootstrapNodes* {.
|
|
|
|
desc: "Specifies one or more bootstrap nodes to use when connecting to the network."
|
|
|
|
longform: "bootstrapNode"
|
|
|
|
shortform: "b".}: seq[string]
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
bootstrapNodesFile* {.
|
|
|
|
desc: "Specifies a line-delimited file of bootsrap Ethereum network addresses"
|
|
|
|
shortform: "f"
|
|
|
|
defaultValue: "".}: FilePath
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
tcpPort* {.
|
|
|
|
desc: "TCP listening port".}: int
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
udpPort* {.
|
|
|
|
desc: "UDP listening port".}: int
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
validators* {.
|
|
|
|
required
|
2019-03-07 13:59:28 +00:00
|
|
|
desc: "Path to a validator private key, as generated by validator_keygen"
|
2018-12-19 12:58:53 +00:00
|
|
|
longform: "validator"
|
2019-03-07 13:59:28 +00:00
|
|
|
shortform: "v".}: seq[ValidatorPrivKey]
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
stateSnapshot* {.
|
|
|
|
desc: "Json file specifying a recent state snapshot"
|
|
|
|
shortform: "s".}: Option[BeaconState]
|
|
|
|
|
|
|
|
of createChain:
|
2019-03-07 13:59:28 +00:00
|
|
|
validatorsDir* {.
|
|
|
|
desc: "Directory containing validator descriptors named vXXXXXXX.deposit.json"
|
|
|
|
shortform: "d".}: DirPath
|
|
|
|
|
|
|
|
numValidators* {.
|
2018-12-19 12:58:53 +00:00
|
|
|
desc: ""
|
2019-03-07 13:59:28 +00:00
|
|
|
shortform: "n".}: int
|
|
|
|
|
|
|
|
firstValidator* {.
|
|
|
|
desc: "index of first validator to add to validator list"
|
|
|
|
shortform: "o"
|
|
|
|
defaultValue: 0.}: int
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-02-15 16:33:32 +00:00
|
|
|
genesisOffset* {.
|
|
|
|
desc: "Seconds from now to add to genesis time"
|
|
|
|
shortForm: "g"
|
2019-03-07 13:59:28 +00:00
|
|
|
defaultValue: 5 .}: int
|
2019-02-15 16:33:32 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
outputStateFile* {.
|
|
|
|
desc: "Output file where to write the initial state snapshot"
|
|
|
|
longform: "out"
|
|
|
|
shortform: "o".}: OutFilePath
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-09 08:25:02 +00:00
|
|
|
proc readFileBytes(path: string): seq[byte] =
|
|
|
|
cast[seq[byte]](readFile(path))
|
|
|
|
|
2018-12-05 13:58:41 +00:00
|
|
|
proc loadPrivKey*(p: ValidatorKeyPath): ValidatorPrivKey =
|
2019-02-05 16:13:29 +00:00
|
|
|
ValidatorPrivKey.init(readFileBytes(string(p) & ".privkey"))
|
2018-12-05 13:58:41 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
proc parseCmdArg*(T: type ValidatorKeyPath, input: TaintedString): T =
|
2018-12-08 14:17:47 +00:00
|
|
|
result = T(input)
|
|
|
|
discard loadPrivKey(result)
|
2018-11-29 01:08:34 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
template mustBeFilePath(input: TaintedString) =
|
|
|
|
if not fileExists(string input):
|
|
|
|
raise newException(ValueError, "")
|
|
|
|
|
|
|
|
template handledAsJsonFilename(T: untyped) {.dirty.} =
|
|
|
|
proc parseCmdArg*(_: type T, input: TaintedString): T =
|
|
|
|
input.mustBeFilePath
|
2018-12-28 16:51:40 +00:00
|
|
|
return Json.loadFile(string(input), T)
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
handledAsJsonFilename BeaconState
|
2019-03-07 13:59:28 +00:00
|
|
|
handledAsJsonFilename Deposit
|
|
|
|
handledAsJsonFilename ValidatorPrivKey
|