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-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-29 16:44:19 +00:00
|
|
|
defaultValue: DEFAULT_NETWORK .}: string
|
2019-03-19 17:22:17 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
depositWeb3Url* {.
|
|
|
|
desc: "URL of the Web3 server to observe Eth1",
|
|
|
|
defaultValue: ""}: string
|
|
|
|
|
|
|
|
depositContractAddress* {.
|
|
|
|
desc: "Address of the deposit contract",
|
|
|
|
defaultValue: ""}: string
|
|
|
|
|
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-29 16:44:19 +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-03-29 16:44:19 +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-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* {.
|
2019-05-22 07:13:15 +00:00
|
|
|
desc: "An unique numeric identifier for the network".}: uint8
|
2019-03-19 17:22:17 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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-09-01 15:02:49 +00:00
|
|
|
of makeDeposits:
|
|
|
|
totalDeposits* {.
|
|
|
|
desc: "Total number of deposits and keys to generate".}: int
|
|
|
|
|
|
|
|
depositDir* {.
|
|
|
|
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}"
|