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-06-10 23:20:18 +00:00
|
|
|
defs, enabledLogLevel
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-03-26 19:44:51 +00:00
|
|
|
const
|
2019-03-29 16:44:19 +00:00
|
|
|
DEFAULT_NETWORK* {.strdefine.} = "testnet0"
|
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
|
2019-09-01 15:02:49 +00:00
|
|
|
makeDeposits
|
2019-03-18 03:54:08 +00:00
|
|
|
|
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-10-03 01:51:44 +00:00
|
|
|
defaultValue: enabledLogLevel }: LogLevel
|
2019-03-18 03:54:08 +00:00
|
|
|
|
|
|
|
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-10-03 01:51:44 +00:00
|
|
|
defaultValue: DEFAULT_NETWORK }: string
|
2019-03-19 17:22:17 +00:00
|
|
|
|
2019-09-09 20:34:50 +00:00
|
|
|
quickStart* {.
|
|
|
|
desc: "Run in quickstart mode",
|
2019-10-03 01:51:44 +00:00
|
|
|
defaultValue: false }: bool
|
2019-09-09 20:34:50 +00:00
|
|
|
|
2019-03-19 17:22:17 +00:00
|
|
|
dataDir* {.
|
|
|
|
desc: "The directory where nimbus will store all blockchain data."
|
|
|
|
shortform: "d"
|
2019-10-03 01:51:44 +00:00
|
|
|
defaultValue: config.defaultDataDir() }: OutDir
|
2019-01-16 23:01:15 +00:00
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
depositWeb3Url* {.
|
|
|
|
desc: "URL of the Web3 server to observe Eth1",
|
2019-10-03 01:51:44 +00:00
|
|
|
defaultValue: "" }: string
|
2019-09-01 15:02:49 +00:00
|
|
|
|
|
|
|
depositContractAddress* {.
|
|
|
|
desc: "Address of the deposit contract",
|
2019-10-03 01:51:44 +00:00
|
|
|
defaultValue: "" }: string
|
|
|
|
|
|
|
|
statusbar* {.
|
|
|
|
desc: "Display a status bar at the bottom of the terminal screen"
|
|
|
|
defaultValue: true }: bool
|
|
|
|
|
|
|
|
statusbarContents* {.
|
|
|
|
desc: ""
|
2019-10-07 08:29:39 +00:00
|
|
|
defaultValue: "peers: $connected_peers; " &
|
|
|
|
"epoch: $epoch, slot: $epoch_slot/$slots_per_epoch (..$slot_trailing_digits); " &
|
|
|
|
"finalized epoch: $last_finalized_epoch |" &
|
2019-10-03 01:51:44 +00:00
|
|
|
"ETH: $attached_validators_balance" }: string
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
case cmd* {.
|
|
|
|
command
|
2019-10-03 01:51:44 +00:00
|
|
|
defaultValue: noCommand }: StartUpCommand
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
of noCommand:
|
|
|
|
bootstrapNodes* {.
|
|
|
|
desc: "Specifies one or more bootstrap nodes to use when connecting to the network."
|
|
|
|
longform: "bootstrapNode"
|
2019-10-03 01:51:44 +00:00
|
|
|
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-10-03 01:51:44 +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-10-03 01:51:44 +00:00
|
|
|
defaultValue: defaultPort(config) }: 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-10-03 01:51:44 +00:00
|
|
|
defaultValue: defaultPort(config) }: int
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-03-19 03:57:19 +00:00
|
|
|
nat* {.
|
2019-04-18 00:02:14 +00:00
|
|
|
desc: "Specify method to use for determining public address. Must be one of: any, none, upnp, pmp, extip:<IP>"
|
2019-03-19 03:57:19 +00:00
|
|
|
defaultValue: "any" .}: string
|
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
validators* {.
|
|
|
|
required
|
2019-09-01 15:02:49 +00:00
|
|
|
desc: "Path to a validator private key, as generated by makeDeposits"
|
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-09-09 18:10:19 +00:00
|
|
|
shortform: "s".}: Option[InputFile]
|
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-09-07 17:48:05 +00:00
|
|
|
metricsServer* {.
|
|
|
|
desc: "Enable the metrics server"
|
|
|
|
defaultValue: false.}: bool
|
|
|
|
|
|
|
|
metricsServerAddress* {.
|
|
|
|
desc: "Listening address of the metrics server"
|
|
|
|
defaultValue: "0.0.0.0".}: string # TODO: use a validated type here
|
|
|
|
|
|
|
|
metricsServerPort* {.
|
|
|
|
desc: "Listening HTTP port of the metrics server"
|
|
|
|
defaultValue: 8008 .}: uint16
|
|
|
|
|
2019-03-19 17:22:17 +00:00
|
|
|
of createTestnet:
|
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-29 13:38:59 +00:00
|
|
|
defaultValue: config.totalValidators - 1 .}: uint64
|
2019-03-19 17:22:17 +00: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-29 16:44:19 +00:00
|
|
|
defaultValue: defaultPort(config) .}: 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
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
outputNetworkMetadata* {.
|
2019-03-19 17:22:17 +00:00
|
|
|
desc: "Output file where to write the initial state snapshot".}: OutFile
|
2019-03-18 03:54:08 +00:00
|
|
|
|
2019-09-10 21:55:58 +00:00
|
|
|
withGenesisRoot* {.
|
|
|
|
desc: "Include a genesis root in network.json", defaultValue: false.}: bool
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
outputBootstrapNodes* {.
|
|
|
|
desc: "Output file with list of bootstrap nodes for the network".}: OutFile
|
|
|
|
|
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-09-01 15:02:49 +00:00
|
|
|
of makeDeposits:
|
|
|
|
totalDeposits* {.
|
|
|
|
desc: "Total number of deposits and keys to generate".}: int
|
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
depositsDir* {.
|
2019-09-01 15:02:49 +00:00
|
|
|
desc: "Folder to write deposits to", defaultValue: "validators".}: string
|
|
|
|
|
|
|
|
randomKeys* {.
|
|
|
|
desc: "Use random keys (instead of interop keys)", defaultValue: false.}: bool
|
|
|
|
|
2019-03-29 16:44:19 +00:00
|
|
|
proc defaultPort*(config: BeaconNodeConf): int =
|
|
|
|
if config.network == "testnet1": 9100
|
|
|
|
else: 9000
|
|
|
|
|
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}"
|