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,
|
2018-12-19 12:58:53 +00:00
|
|
|
spec/[crypto, datatypes], randao, time
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
ChainStartupData* = object
|
|
|
|
validatorDeposits*: seq[Deposit]
|
|
|
|
genesisTime*: Timestamp
|
|
|
|
|
|
|
|
PrivateValidatorData* = object
|
|
|
|
privKey*: ValidatorPrivKey
|
|
|
|
randao*: Randao
|
|
|
|
|
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
|
|
|
|
desc: "A path to a pair of public and private keys for a validator. " &
|
|
|
|
"Nimbus will automatically add the extensions .privkey and .pubkey."
|
|
|
|
longform: "validator"
|
|
|
|
shortform: "v".}: seq[PrivateValidatorData]
|
|
|
|
|
|
|
|
stateSnapshot* {.
|
|
|
|
desc: "Json file specifying a recent state snapshot"
|
|
|
|
shortform: "s".}: Option[BeaconState]
|
|
|
|
|
|
|
|
of createChain:
|
|
|
|
chainStartupData* {.
|
|
|
|
desc: ""
|
|
|
|
shortform: "c".}: ChainStartupData
|
|
|
|
|
|
|
|
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-08 14:17:47 +00:00
|
|
|
proc loadRandao*(p: ValidatorKeyPath): Randao =
|
2018-12-09 08:25:02 +00:00
|
|
|
initRandao(readFileBytes(string(p) & ".randao"))
|
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)
|
|
|
|
discard loadRandao(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
|
|
|
|
handledAsJsonFilename ChainStartupData
|
|
|
|
handledAsJsonFilename PrivateValidatorData
|
|
|
|
|