2018-11-23 23:58:49 +00:00
|
|
|
import
|
2019-03-18 03:54:08 +00:00
|
|
|
os, options, strformat,
|
2019-01-16 23:01:15 +00:00
|
|
|
confutils/defs, chronicles/options as chroniclesOptions,
|
2019-03-18 03:54:08 +00:00
|
|
|
spec/[crypto, datatypes], time, version
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
export
|
2019-03-18 03:54:08 +00:00
|
|
|
defs
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-03-26 19:44:51 +00:00
|
|
|
const
|
2019-03-26 20:35:01 +00:00
|
|
|
defaultPort* = 9000
|
2019-03-26 19:44:51 +00:00
|
|
|
|
2018-11-23 23:58:49 +00:00
|
|
|
type
|
2019-03-18 03:54:08 +00:00
|
|
|
ValidatorKeyPath* = TypedInputFile[ValidatorPrivKey, Txt, "privkey"]
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
StartUpCommand* = enum
|
|
|
|
noCommand
|
2019-03-25 23:26:11 +00:00
|
|
|
importValidator
|
2019-03-26 10:01:13 +00:00
|
|
|
createTestnet
|
2019-03-18 03:54:08 +00:00
|
|
|
updateTestnet
|
|
|
|
|
2018-11-29 01:08:34 +00:00
|
|
|
BeaconNodeConf* = object
|
2019-01-16 23:01:15 +00:00
|
|
|
logLevel* {.
|
|
|
|
desc: "Sets the log level",
|
2019-03-18 03:54:08 +00:00
|
|
|
defaultValue: enabledLogLevel.}: LogLevel
|
|
|
|
|
|
|
|
network* {.
|
2019-03-19 17:22:17 +00:00
|
|
|
desc: "The network Nimbus should connect to. " &
|
|
|
|
"Possible values: testnet0, testnet1, mainnet, custom-network.json"
|
2019-03-18 03:54:08 +00:00
|
|
|
longform: "network"
|
|
|
|
shortform: "n"
|
2019-03-19 17:22:17 +00:00
|
|
|
defaultValue: "testnet0".}: string
|
|
|
|
|
|
|
|
dataDir* {.
|
|
|
|
desc: "The directory where nimbus will store all blockchain data."
|
|
|
|
shortform: "d"
|
|
|
|
defaultValue: config.defaultDataDir().}: OutDir
|
2019-01-16 23:01:15 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
case cmd* {.
|
|
|
|
command
|
|
|
|
defaultValue: noCommand.}: StartUpCommand
|
|
|
|
|
|
|
|
of noCommand:
|
|
|
|
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"
|
2019-03-18 03:54:08 +00:00
|
|
|
defaultValue: "".}: InputFile
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
tcpPort* {.
|
2019-03-18 03:54:08 +00:00
|
|
|
desc: "TCP listening port"
|
2019-03-26 19:44:51 +00:00
|
|
|
defaultValue: defaultPort .}: int
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
udpPort* {.
|
2019-03-18 03:54:08 +00:00
|
|
|
desc: "UDP listening port",
|
2019-03-26 19:44:51 +00:00
|
|
|
defaultValue: defaultPort .}: int
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-03-19 03:57:19 +00:00
|
|
|
nat* {.
|
|
|
|
desc: "Specify method to use for determining public address. Must be one of: any, extip:<IP>"
|
|
|
|
defaultValue: "any" .}: string
|
|
|
|
|
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-18 03:54:08 +00:00
|
|
|
shortform: "v".}: seq[ValidatorKeyPath]
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
stateSnapshot* {.
|
|
|
|
desc: "Json file specifying a recent state snapshot"
|
2019-03-18 03:54:08 +00:00
|
|
|
shortform: "s".}: Option[TypedInputFile[BeaconState, Json, "json"]]
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-03-22 14:35:20 +00:00
|
|
|
nodename* {.
|
|
|
|
desc: "A name for this node that will appear in the logs. " &
|
|
|
|
"If you set this to 'auto', a persistent automatically generated ID will be seleceted for each --dataDir folder"
|
|
|
|
defaultValue: ""}: string
|
|
|
|
|
2019-03-19 17:22:17 +00:00
|
|
|
of createTestnet:
|
|
|
|
networkId* {.
|
|
|
|
desc: "An unique numeric identifier for the network".}: uint64
|
|
|
|
|
2019-03-07 13:59:28 +00:00
|
|
|
validatorsDir* {.
|
|
|
|
desc: "Directory containing validator descriptors named vXXXXXXX.deposit.json"
|
2019-03-18 03:54:08 +00:00
|
|
|
shortform: "d".}: InputDir
|
2019-03-07 13:59:28 +00:00
|
|
|
|
2019-03-27 12:06:06 +00:00
|
|
|
totalValidators* {.
|
2019-03-19 17:22:17 +00:00
|
|
|
desc: "The number of validators in the newly created chain".}: uint64
|
2019-03-07 13:59:28 +00:00
|
|
|
|
|
|
|
firstValidator* {.
|
2019-03-19 17:22:17 +00:00
|
|
|
desc: "Index of first validator to add to validator list"
|
|
|
|
defaultValue: 0 .}: uint64
|
|
|
|
|
2019-03-27 12:06:06 +00:00
|
|
|
lastUserValidator* {.
|
|
|
|
desc: "The last validator index that will free for taking from a testnet participant"
|
2019-03-19 17:22:17 +00:00
|
|
|
defaultValue: 0 .}: uint64
|
|
|
|
|
|
|
|
bootstrapAddress* {.
|
|
|
|
desc: "The public IP address that will be advertised as a bootstrap node for the testnet"
|
|
|
|
defaultValue: "127.0.0.1".}: string
|
|
|
|
|
|
|
|
bootstrapPort* {.
|
|
|
|
desc: "The TCP/UDP port that will be used by the bootstrap node"
|
2019-03-26 19:44:51 +00:00
|
|
|
defaultValue: defaultPort .}: 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
|
|
|
|
2019-03-19 17:22:17 +00:00
|
|
|
outputGenesis* {.
|
|
|
|
desc: "Output file where to write the initial state snapshot".}: OutFile
|
|
|
|
|
|
|
|
outputNetwork* {.
|
|
|
|
desc: "Output file where to write the initial state snapshot".}: OutFile
|
2019-03-18 03:54:08 +00:00
|
|
|
|
2019-03-25 23:26:11 +00:00
|
|
|
of importValidator:
|
2019-03-19 19:50:22 +00:00
|
|
|
keyFiles* {.
|
|
|
|
longform: "keyfile"
|
|
|
|
desc: "File with validator key to be imported (in hex form)".}: seq[ValidatorKeyPath]
|
2019-03-18 03:54:08 +00:00
|
|
|
|
|
|
|
of updateTestnet:
|
|
|
|
discard
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-03-18 03:54:08 +00:00
|
|
|
proc defaultDataDir*(conf: BeaconNodeConf): string =
|
2019-03-19 17:22:17 +00:00
|
|
|
let dataDir = when defined(windows):
|
|
|
|
"AppData" / "Roaming" / "Nimbus"
|
|
|
|
elif defined(macosx):
|
|
|
|
"Library" / "Application Support" / "Nimbus"
|
|
|
|
else:
|
|
|
|
".cache" / "nimbus"
|
2018-12-09 08:25:02 +00:00
|
|
|
|
2019-03-20 11:52:30 +00:00
|
|
|
let networkDir = if conf.network in ["testnet0", "testnet1", "mainnet"]:
|
2019-03-19 17:22:17 +00:00
|
|
|
conf.network
|
2019-03-18 03:54:08 +00:00
|
|
|
else:
|
2019-03-19 17:22:17 +00:00
|
|
|
# TODO: This seems silly. Perhaps we should error out here and ask
|
|
|
|
# the user to specify dataDir as well.
|
|
|
|
"tempnet"
|
2018-12-05 13:58:41 +00:00
|
|
|
|
2019-03-20 11:52:30 +00:00
|
|
|
getHomeDir() / dataDir / "BeaconNode" / networkDir
|
2018-11-29 01:08:34 +00:00
|
|
|
|
2019-03-18 03:54:08 +00:00
|
|
|
proc validatorFileBaseName*(validatorIdx: int): string =
|
|
|
|
# there can apparently be tops 4M validators so we use 7 digits..
|
|
|
|
fmt"v{validatorIdx:07}"
|
2018-12-19 12:58:53 +00:00
|
|
|
|