2018-11-24 01:58:49 +02:00
|
|
|
import
|
2019-03-18 05:54:08 +02:00
|
|
|
os, options, strformat,
|
2019-01-17 01:01:15 +02:00
|
|
|
confutils/defs, chronicles/options as chroniclesOptions,
|
2019-03-18 05:54:08 +02:00
|
|
|
spec/[crypto, datatypes], time, version
|
2018-12-19 14:58:53 +02:00
|
|
|
|
|
|
|
export
|
2019-03-18 05:54:08 +02:00
|
|
|
defs
|
2018-11-24 01:58:49 +02:00
|
|
|
|
2019-03-26 21:44:51 +02:00
|
|
|
const
|
2019-03-26 22:35:01 +02:00
|
|
|
defaultPort* = 9000
|
2019-03-26 21:44:51 +02:00
|
|
|
|
2018-11-24 01:58:49 +02:00
|
|
|
type
|
2019-03-18 05:54:08 +02:00
|
|
|
ValidatorKeyPath* = TypedInputFile[ValidatorPrivKey, Txt, "privkey"]
|
2018-11-24 01:58:49 +02:00
|
|
|
|
2018-12-19 14:58:53 +02:00
|
|
|
StartUpCommand* = enum
|
|
|
|
noCommand
|
2019-03-26 01:26:11 +02:00
|
|
|
importValidator
|
2019-03-26 12:01:13 +02:00
|
|
|
createTestnet
|
2019-03-18 05:54:08 +02:00
|
|
|
updateTestnet
|
|
|
|
|
2018-11-29 03:08:34 +02:00
|
|
|
BeaconNodeConf* = object
|
2019-01-17 01:01:15 +02:00
|
|
|
logLevel* {.
|
|
|
|
desc: "Sets the log level",
|
2019-03-18 05:54:08 +02:00
|
|
|
defaultValue: enabledLogLevel.}: LogLevel
|
|
|
|
|
|
|
|
network* {.
|
2019-03-19 19:22:17 +02:00
|
|
|
desc: "The network Nimbus should connect to. " &
|
|
|
|
"Possible values: testnet0, testnet1, mainnet, custom-network.json"
|
2019-03-18 05:54:08 +02:00
|
|
|
longform: "network"
|
|
|
|
shortform: "n"
|
2019-03-19 19:22:17 +02:00
|
|
|
defaultValue: "testnet0".}: string
|
|
|
|
|
|
|
|
dataDir* {.
|
|
|
|
desc: "The directory where nimbus will store all blockchain data."
|
|
|
|
shortform: "d"
|
|
|
|
defaultValue: config.defaultDataDir().}: OutDir
|
2019-01-17 01:01:15 +02:00
|
|
|
|
2018-12-19 14:58:53 +02: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-24 01:58:49 +02:00
|
|
|
|
2018-12-19 14:58:53 +02:00
|
|
|
bootstrapNodesFile* {.
|
|
|
|
desc: "Specifies a line-delimited file of bootsrap Ethereum network addresses"
|
|
|
|
shortform: "f"
|
2019-03-18 05:54:08 +02:00
|
|
|
defaultValue: "".}: InputFile
|
2018-11-24 01:58:49 +02:00
|
|
|
|
2018-12-19 14:58:53 +02:00
|
|
|
tcpPort* {.
|
2019-03-18 05:54:08 +02:00
|
|
|
desc: "TCP listening port"
|
2019-03-26 21:44:51 +02:00
|
|
|
defaultValue: defaultPort .}: int
|
2018-11-24 01:58:49 +02:00
|
|
|
|
2018-12-19 14:58:53 +02:00
|
|
|
udpPort* {.
|
2019-03-18 05:54:08 +02:00
|
|
|
desc: "UDP listening port",
|
2019-03-26 21:44:51 +02:00
|
|
|
defaultValue: defaultPort .}: int
|
2018-11-24 01:58:49 +02:00
|
|
|
|
2019-03-18 21:57:19 -06:00
|
|
|
nat* {.
|
|
|
|
desc: "Specify method to use for determining public address. Must be one of: any, extip:<IP>"
|
|
|
|
defaultValue: "any" .}: string
|
|
|
|
|
2018-12-19 14:58:53 +02:00
|
|
|
validators* {.
|
|
|
|
required
|
2019-03-07 07:59:28 -06:00
|
|
|
desc: "Path to a validator private key, as generated by validator_keygen"
|
2018-12-19 14:58:53 +02:00
|
|
|
longform: "validator"
|
2019-03-18 05:54:08 +02:00
|
|
|
shortform: "v".}: seq[ValidatorKeyPath]
|
2018-12-19 14:58:53 +02:00
|
|
|
|
|
|
|
stateSnapshot* {.
|
|
|
|
desc: "Json file specifying a recent state snapshot"
|
2019-03-18 05:54:08 +02:00
|
|
|
shortform: "s".}: Option[TypedInputFile[BeaconState, Json, "json"]]
|
2018-12-19 14:58:53 +02:00
|
|
|
|
2019-03-22 16:35:20 +02: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 19:22:17 +02:00
|
|
|
of createTestnet:
|
|
|
|
networkId* {.
|
|
|
|
desc: "An unique numeric identifier for the network".}: uint64
|
|
|
|
|
2019-03-07 07:59:28 -06:00
|
|
|
validatorsDir* {.
|
|
|
|
desc: "Directory containing validator descriptors named vXXXXXXX.deposit.json"
|
2019-03-18 05:54:08 +02:00
|
|
|
shortform: "d".}: InputDir
|
2019-03-07 07:59:28 -06:00
|
|
|
|
2019-03-27 14:06:06 +02:00
|
|
|
totalValidators* {.
|
2019-03-19 19:22:17 +02:00
|
|
|
desc: "The number of validators in the newly created chain".}: uint64
|
2019-03-07 07:59:28 -06:00
|
|
|
|
|
|
|
firstValidator* {.
|
2019-03-19 19:22:17 +02:00
|
|
|
desc: "Index of first validator to add to validator list"
|
|
|
|
defaultValue: 0 .}: uint64
|
|
|
|
|
2019-03-27 14:06:06 +02:00
|
|
|
lastUserValidator* {.
|
|
|
|
desc: "The last validator index that will free for taking from a testnet participant"
|
2019-03-29 15:38:59 +02:00
|
|
|
defaultValue: config.totalValidators - 1 .}: uint64
|
2019-03-19 19:22:17 +02:00
|
|
|
|
|
|
|
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 21:44:51 +02:00
|
|
|
defaultValue: defaultPort .}: int
|
2018-12-19 14:58:53 +02:00
|
|
|
|
2019-02-15 10:33:32 -06:00
|
|
|
genesisOffset* {.
|
|
|
|
desc: "Seconds from now to add to genesis time"
|
|
|
|
shortForm: "g"
|
2019-03-07 07:59:28 -06:00
|
|
|
defaultValue: 5 .}: int
|
2019-02-15 10:33:32 -06:00
|
|
|
|
2019-03-19 19:22:17 +02: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 05:54:08 +02:00
|
|
|
|
2019-03-26 01:26:11 +02:00
|
|
|
of importValidator:
|
2019-03-19 21:50:22 +02:00
|
|
|
keyFiles* {.
|
|
|
|
longform: "keyfile"
|
|
|
|
desc: "File with validator key to be imported (in hex form)".}: seq[ValidatorKeyPath]
|
2019-03-18 05:54:08 +02:00
|
|
|
|
|
|
|
of updateTestnet:
|
|
|
|
discard
|
2018-11-24 01:58:49 +02:00
|
|
|
|
2019-03-18 05:54:08 +02:00
|
|
|
proc defaultDataDir*(conf: BeaconNodeConf): string =
|
2019-03-19 19:22:17 +02:00
|
|
|
let dataDir = when defined(windows):
|
|
|
|
"AppData" / "Roaming" / "Nimbus"
|
|
|
|
elif defined(macosx):
|
|
|
|
"Library" / "Application Support" / "Nimbus"
|
|
|
|
else:
|
|
|
|
".cache" / "nimbus"
|
2018-12-09 10:25:02 +02:00
|
|
|
|
2019-03-20 13:52:30 +02:00
|
|
|
let networkDir = if conf.network in ["testnet0", "testnet1", "mainnet"]:
|
2019-03-19 19:22:17 +02:00
|
|
|
conf.network
|
2019-03-18 05:54:08 +02:00
|
|
|
else:
|
2019-03-19 19:22:17 +02:00
|
|
|
# TODO: This seems silly. Perhaps we should error out here and ask
|
|
|
|
# the user to specify dataDir as well.
|
|
|
|
"tempnet"
|
2018-12-05 15:58:41 +02:00
|
|
|
|
2019-03-20 13:52:30 +02:00
|
|
|
getHomeDir() / dataDir / "BeaconNode" / networkDir
|
2018-11-29 03:08:34 +02:00
|
|
|
|
2019-03-18 05:54:08 +02: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 14:58:53 +02:00
|
|
|
|