2018-11-23 23:58:49 +00:00
|
|
|
import
|
2019-12-10 14:20:40 +00:00
|
|
|
os, options, strformat, strutils,
|
|
|
|
chronicles, confutils,
|
2019-01-16 23:01:15 +00:00
|
|
|
confutils/defs, chronicles/options as chroniclesOptions,
|
2019-10-25 10:59:56 +00:00
|
|
|
spec/[crypto]
|
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
|
|
|
|
2019-11-01 09:53:06 +00:00
|
|
|
StartUpCmd* = enum
|
2018-12-19 12:58:53 +00:00
|
|
|
noCommand
|
2019-03-25 23:26:11 +00:00
|
|
|
importValidator
|
2019-03-26 10:01:13 +00:00
|
|
|
createTestnet
|
2019-09-01 15:02:49 +00:00
|
|
|
makeDeposits
|
2019-11-01 09:53:06 +00:00
|
|
|
query
|
|
|
|
|
|
|
|
QueryCmd* = enum
|
|
|
|
nimQuery
|
|
|
|
get
|
2019-03-18 03:54:08 +00:00
|
|
|
|
2019-10-28 23:04:52 +00:00
|
|
|
Eth1Network* = enum
|
|
|
|
custom
|
|
|
|
mainnet
|
|
|
|
rinkeby
|
|
|
|
goerli
|
|
|
|
|
2018-11-29 01:08:34 +00:00
|
|
|
BeaconNodeConf* = object
|
2019-01-16 23:01:15 +00:00
|
|
|
logLevel* {.
|
2019-11-14 13:12:57 +00:00
|
|
|
defaultValue: LogLevel.DEBUG
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Sets the log level."
|
|
|
|
name: "log-level" }: LogLevel
|
2019-03-18 03:54:08 +00:00
|
|
|
|
2019-10-28 23:04:52 +00:00
|
|
|
eth1Network* {.
|
|
|
|
defaultValue: goerli
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "The Eth1 network tracked by the beacon node."
|
|
|
|
name: "eth1-network" }: Eth1Network
|
2019-03-19 17:22:17 +00:00
|
|
|
|
2019-09-09 20:34:50 +00:00
|
|
|
quickStart* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: false
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Run in quickstart mode"
|
|
|
|
name: "quick-start" }: bool
|
2019-09-09 20:34:50 +00:00
|
|
|
|
2019-03-19 17:22:17 +00:00
|
|
|
dataDir* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: config.defaultDataDir()
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "The directory where nimbus will store all blockchain data."
|
|
|
|
abbr: "d"
|
|
|
|
name: "data-dir" }: OutDir
|
2019-01-16 23:01:15 +00:00
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
depositWeb3Url* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: ""
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "URL of the Web3 server to observe Eth1."
|
|
|
|
name: "web3-url" }: string
|
2019-09-01 15:02:49 +00:00
|
|
|
|
|
|
|
depositContractAddress* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: ""
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Address of the deposit contract."
|
|
|
|
name: "deposit-contract" }: string
|
2019-10-03 01:51:44 +00:00
|
|
|
|
2019-10-28 23:04:52 +00:00
|
|
|
statusBarEnabled* {.
|
|
|
|
defaultValue: true
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Display a status bar at the bottom of the terminal screen."
|
|
|
|
name: "status-bar" }: bool
|
2019-10-03 01:51:44 +00:00
|
|
|
|
2019-10-28 23:04:52 +00:00
|
|
|
statusBarContents* {.
|
2019-10-07 08:29:39 +00:00
|
|
|
defaultValue: "peers: $connected_peers; " &
|
2019-10-29 19:48:32 +00:00
|
|
|
"epoch: $epoch, slot: $epoch_slot/$slots_per_epoch ($slot); " &
|
2019-10-07 08:29:39 +00:00
|
|
|
"finalized epoch: $last_finalized_epoch |" &
|
2019-10-28 23:04:52 +00:00
|
|
|
"ETH: $attached_validators_balance"
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Textual template for the contents of the status bar."
|
|
|
|
name: "status-bar-contents" }: string
|
2019-11-08 17:35:57 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
case cmd* {.
|
|
|
|
command
|
2019-11-01 09:53:06 +00:00
|
|
|
defaultValue: noCommand }: StartUpCmd
|
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."
|
2019-11-11 14:43:12 +00:00
|
|
|
abbr: "b"
|
|
|
|
name: "bootstrap-node" }: seq[string]
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
bootstrapNodesFile* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: ""
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Specifies a line-delimited file of bootsrap Ethereum network addresses."
|
|
|
|
name: "bootstrap-file" }: InputFile
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-12-13 17:30:39 +00:00
|
|
|
enrBootstrapNodesFile* {.
|
|
|
|
defaultValue: ""
|
|
|
|
desc: "Specifies a line-delimited file of bootstrap ENR records"
|
|
|
|
name: "enr-bootstrap-file" }: InputFile
|
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
tcpPort* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: defaultPort(config)
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "TCP listening port."
|
|
|
|
name: "tcp-port" }: int
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
udpPort* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: defaultPort(config)
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "UDP listening port."
|
|
|
|
name: "udp-port" }: int
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-12-18 01:11:20 +00:00
|
|
|
maxPeers* {.
|
|
|
|
defaultValue: 10
|
|
|
|
desc: "The maximum number of peers to connect to"
|
|
|
|
name: "max-peers" }: int
|
|
|
|
|
2019-03-19 03:57:19 +00:00
|
|
|
nat* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
desc: "Specify method to use for determining public address. " &
|
|
|
|
"Must be one of: any, none, upnp, pmp, extip:<IP>."
|
|
|
|
defaultValue: "any" }: string
|
2019-03-19 03:57:19 +00:00
|
|
|
|
2018-12-19 12:58:53 +00:00
|
|
|
validators* {.
|
|
|
|
required
|
2019-10-28 23:04:52 +00:00
|
|
|
desc: "Path to a validator private key, as generated by makeDeposits."
|
2019-11-11 14:43:12 +00:00
|
|
|
abbr: "v"
|
|
|
|
name: "validator" }: seq[ValidatorKeyPath]
|
2018-12-19 12:58:53 +00:00
|
|
|
|
|
|
|
stateSnapshot* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
desc: "Json file specifying a recent state snapshot."
|
2019-11-11 14:43:12 +00:00
|
|
|
abbr: "s"
|
|
|
|
name: "state-snapshot" }: Option[InputFile]
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-10-28 23:04:52 +00:00
|
|
|
nodeName* {.
|
2019-11-11 14:43:12 +00:00
|
|
|
defaultValue: ""
|
2019-03-22 14:35:20 +00:00
|
|
|
desc: "A name for this node that will appear in the logs. " &
|
2019-10-28 23:04:52 +00:00
|
|
|
"If you set this to 'auto', a persistent automatically generated ID will be seleceted for each --dataDir folder."
|
2019-11-11 14:43:12 +00:00
|
|
|
name: "node-name" }: string
|
2019-03-22 14:35:20 +00:00
|
|
|
|
2019-09-07 17:48:05 +00:00
|
|
|
metricsServer* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: false
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Enable the metrics server."
|
|
|
|
name: "metrics-server" }: bool
|
2019-09-07 17:48:05 +00:00
|
|
|
|
|
|
|
metricsServerAddress* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: "0.0.0.0"
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Listening address of the metrics server."
|
|
|
|
name: "metrics-server-address" }: string # TODO: use a validated type here
|
2019-09-07 17:48:05 +00:00
|
|
|
|
|
|
|
metricsServerPort* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: 8008
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Listening HTTP port of the metrics server."
|
|
|
|
name: "metrics-server-port" }: uint16
|
2019-09-07 17:48:05 +00:00
|
|
|
|
2019-12-03 11:32:27 +00:00
|
|
|
dump* {.
|
|
|
|
defaultValue: false
|
|
|
|
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
|
|
|
|
.}: bool
|
|
|
|
|
2019-03-19 17:22:17 +00:00
|
|
|
of createTestnet:
|
2019-03-07 13:59:28 +00:00
|
|
|
validatorsDir* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
desc: "Directory containing validator descriptors named 'vXXXXXXX.deposit.json'."
|
2019-11-11 14:43:12 +00:00
|
|
|
abbr: "d"
|
|
|
|
name: "validators-dir" }: InputDir
|
2019-03-07 13:59:28 +00:00
|
|
|
|
2019-03-27 12:06:06 +00:00
|
|
|
totalValidators* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
desc: "The number of validators in the newly created chain."
|
2019-11-11 14:43:12 +00:00
|
|
|
name: "total-validators" }: uint64
|
2019-03-07 13:59:28 +00:00
|
|
|
|
|
|
|
firstValidator* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: 0
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Index of first validator to add to validator list."
|
|
|
|
name: "first-validator" }: uint64
|
2019-03-19 17:22:17 +00:00
|
|
|
|
2019-03-27 12:06:06 +00:00
|
|
|
lastUserValidator* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: config.totalValidators - 1,
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "The last validator index that will free for taking from a testnet participant."
|
|
|
|
name: "last-user-validator" }: uint64
|
2019-03-19 17:22:17 +00:00
|
|
|
|
|
|
|
bootstrapAddress* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: "127.0.0.1"
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "The public IP address that will be advertised as a bootstrap node for the testnet."
|
|
|
|
name: "bootstrap-address" }: string
|
2019-03-19 17:22:17 +00:00
|
|
|
|
|
|
|
bootstrapPort* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: defaultPort(config)
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "The TCP/UDP port that will be used by the bootstrap node."
|
|
|
|
name: "bootstrap-port" }: int
|
2018-12-19 12:58:53 +00:00
|
|
|
|
2019-02-15 16:33:32 +00:00
|
|
|
genesisOffset* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: 5
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Seconds from now to add to genesis time."
|
|
|
|
abbr: "g"
|
|
|
|
name: "genesis-offset" }: int
|
2019-02-15 16:33:32 +00:00
|
|
|
|
2019-03-19 17:22:17 +00:00
|
|
|
outputGenesis* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
desc: "Output file where to write the initial state snapshot."
|
2019-11-11 14:43:12 +00:00
|
|
|
name: "output-genesis" }: OutFile
|
2019-03-18 03:54:08 +00:00
|
|
|
|
2019-09-10 21:55:58 +00:00
|
|
|
withGenesisRoot* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: false
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Include a genesis root in 'network.json'."
|
|
|
|
name: "with-genesis-root" }: bool
|
2019-09-10 21:55:58 +00:00
|
|
|
|
2019-10-28 23:04:52 +00:00
|
|
|
outputBootstrapFile* {.
|
|
|
|
desc: "Output file with list of bootstrap nodes for the network."
|
2019-11-11 14:43:12 +00:00
|
|
|
name: "output-bootstrap-file" }: OutFile
|
2019-09-10 22:13:27 +00:00
|
|
|
|
2019-03-25 23:26:11 +00:00
|
|
|
of importValidator:
|
2019-03-19 19:50:22 +00:00
|
|
|
keyFiles* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
desc: "File with validator key to be imported (in hex form)."
|
2019-11-11 14:43:12 +00:00
|
|
|
name: "keyfile" }: seq[ValidatorKeyPath]
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-09-01 15:02:49 +00:00
|
|
|
of makeDeposits:
|
2019-10-29 02:43:23 +00:00
|
|
|
totalQuickstartDeposits* {.
|
|
|
|
defaultValue: 0
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Number of quick-start deposits to generate."
|
|
|
|
name: "quickstart-deposits" }: int
|
2019-10-29 02:43:23 +00:00
|
|
|
|
|
|
|
totalRandomDeposits* {.
|
|
|
|
defaultValue: 0
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Number of secure random deposits to generate."
|
|
|
|
name: "random-deposits" }: int
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2019-09-10 22:13:27 +00:00
|
|
|
depositsDir* {.
|
2019-10-28 23:04:52 +00:00
|
|
|
defaultValue: "validators"
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Folder to write deposits to."
|
|
|
|
name: "deposits-dir" }: string
|
2019-09-01 15:02:49 +00:00
|
|
|
|
2019-11-05 18:16:10 +00:00
|
|
|
depositPrivateKey* {.
|
|
|
|
defaultValue: ""
|
2019-11-11 14:43:12 +00:00
|
|
|
desc: "Private key of the controlling (sending) account",
|
|
|
|
name: "deposit-private-key" }: string
|
2019-11-05 18:16:10 +00:00
|
|
|
|
2019-11-01 09:53:06 +00:00
|
|
|
of query:
|
|
|
|
case queryCmd* {.
|
|
|
|
defaultValue: nimQuery
|
2019-11-11 14:43:12 +00:00
|
|
|
command
|
2019-11-01 09:53:06 +00:00
|
|
|
desc: "Query the beacon node database and print the result" }: QueryCmd
|
|
|
|
|
|
|
|
of nimQuery:
|
|
|
|
nimQueryExpression* {.
|
|
|
|
argument
|
|
|
|
desc: "Nim expression to evaluate (using limited syntax)" }: string
|
|
|
|
|
|
|
|
of get:
|
|
|
|
getQueryPath* {.
|
|
|
|
argument
|
|
|
|
desc: "REST API path to evaluate" }: string
|
|
|
|
|
2019-03-29 16:44:19 +00:00
|
|
|
proc defaultPort*(config: BeaconNodeConf): int =
|
2019-10-28 23:04:52 +00:00
|
|
|
9000
|
2019-03-29 16:44:19 +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-10-28 23:04:52 +00:00
|
|
|
getHomeDir() / dataDir / "BeaconNode"
|
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}"
|
2019-12-03 11:32:27 +00:00
|
|
|
|
|
|
|
func dumpDir*(conf: BeaconNodeConf): string =
|
|
|
|
conf.dataDir / "dump"
|
2019-12-10 14:20:40 +00:00
|
|
|
|
|
|
|
func localValidatorsDir*(conf: BeaconNodeConf): string =
|
|
|
|
conf.dataDir / "validators"
|
|
|
|
|
|
|
|
func databaseDir*(conf: BeaconNodeConf): string =
|
|
|
|
conf.dataDir / "db"
|
|
|
|
|
|
|
|
iterator validatorKeys*(conf: BeaconNodeConf): ValidatorPrivKey =
|
|
|
|
for validatorKeyFile in conf.validators:
|
|
|
|
try:
|
|
|
|
yield validatorKeyFile.load
|
|
|
|
except CatchableError as err:
|
|
|
|
warn "Failed to load validator private key",
|
|
|
|
file = validatorKeyFile.string, err = err.msg
|
|
|
|
|
|
|
|
for kind, file in walkDir(conf.localValidatorsDir):
|
|
|
|
if kind in {pcFile, pcLinkToFile} and
|
|
|
|
cmpIgnoreCase(".privkey", splitFile(file).ext) == 0:
|
|
|
|
try:
|
|
|
|
yield ValidatorPrivKey.init(readFile(file).string)
|
|
|
|
except CatchableError as err:
|
|
|
|
warn "Failed to load a validator private key", file, err = err.msg
|