nimbus-eth2/beacon_chain/conf.nim

297 lines
8.9 KiB
Nim
Raw Normal View History

import
os, options, strformat, strutils,
chronicles, confutils,
confutils/defs, chronicles/options as chroniclesOptions,
spec/[crypto]
export
defs, enabledLogLevel
const
DEFAULT_NETWORK* {.strdefine.} = "testnet0"
type
ValidatorKeyPath* = TypedInputFile[ValidatorPrivKey, Txt, "privkey"]
StartUpCmd* = enum
noCommand
importValidator
createTestnet
makeDeposits
query
QueryCmd* = enum
nimQuery
get
Eth1Network* = enum
custom
mainnet
rinkeby
goerli
2018-11-29 01:08:34 +00:00
BeaconNodeConf* = object
logLevel* {.
defaultValue: LogLevel.DEBUG
2019-11-11 14:43:12 +00:00
desc: "Sets the log level."
name: "log-level" }: LogLevel
eth1Network* {.
defaultValue: goerli
2019-11-11 14:43:12 +00:00
desc: "The Eth1 network tracked by the beacon node."
name: "eth1-network" }: Eth1Network
quickStart* {.
defaultValue: false
2019-11-11 14:43:12 +00:00
desc: "Run in quickstart mode"
name: "quick-start" }: bool
dataDir* {.
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
depositWeb3Url* {.
defaultValue: ""
2019-11-11 14:43:12 +00:00
desc: "URL of the Web3 server to observe Eth1."
name: "web3-url" }: string
depositContractAddress* {.
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
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
statusBarContents* {.
defaultValue: "peers: $connected_peers; " &
"epoch: $epoch, slot: $epoch_slot/$slots_per_epoch ($slot); " &
"finalized epoch: $last_finalized_epoch |" &
"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
case cmd* {.
command
defaultValue: noCommand }: StartUpCmd
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]
bootstrapNodesFile* {.
defaultValue: ""
2019-11-11 14:43:12 +00:00
desc: "Specifies a line-delimited file of bootsrap Ethereum network addresses."
name: "bootstrap-file" }: InputFile
enrBootstrapNodesFile* {.
defaultValue: ""
desc: "Specifies a line-delimited file of bootstrap ENR records"
name: "enr-bootstrap-file" }: InputFile
tcpPort* {.
defaultValue: defaultPort(config)
2019-11-11 14:43:12 +00:00
desc: "TCP listening port."
name: "tcp-port" }: int
udpPort* {.
defaultValue: defaultPort(config)
2019-11-11 14:43:12 +00:00
desc: "UDP listening port."
name: "udp-port" }: int
maxPeers* {.
defaultValue: 10
desc: "The maximum number of peers to connect to"
name: "max-peers" }: int
nat* {.
desc: "Specify method to use for determining public address. " &
"Must be one of: any, none, upnp, pmp, extip:<IP>."
defaultValue: "any" }: string
validators* {.
required
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]
stateSnapshot* {.
desc: "Json file specifying a recent state snapshot."
2019-11-11 14:43:12 +00:00
abbr: "s"
name: "state-snapshot" }: Option[InputFile]
nodeName* {.
2019-11-11 14:43:12 +00:00
defaultValue: ""
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."
2019-11-11 14:43:12 +00:00
name: "node-name" }: string
verifyFinalization* {.
defaultValue: false
desc: "Specify whether to verify finalization occurs on schedule, for testing."
name: "verify-finalization" }: bool
checkEpochs* {.
defaultValue: 0
desc: "A positive checkEpochs selects how many epochs to run."
name: "check-epochs" }: uint64
metricsServer* {.
defaultValue: false
2019-11-11 14:43:12 +00:00
desc: "Enable the metrics server."
name: "metrics-server" }: bool
metricsServerAddress* {.
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
metricsServerPort* {.
defaultValue: 8008
2019-11-11 14:43:12 +00:00
desc: "Listening HTTP port of the metrics server."
name: "metrics-server-port" }: uint16
dump* {.
defaultValue: false
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
.}: bool
of createTestnet:
validatorsDir* {.
desc: "Directory containing validator descriptors named 'vXXXXXXX.deposit.json'."
2019-11-11 14:43:12 +00:00
abbr: "d"
name: "validators-dir" }: InputDir
totalValidators* {.
desc: "The number of validators in the newly created chain."
2019-11-11 14:43:12 +00:00
name: "total-validators" }: uint64
firstValidator* {.
defaultValue: 0
2019-11-11 14:43:12 +00:00
desc: "Index of first validator to add to validator list."
name: "first-validator" }: uint64
lastUserValidator* {.
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
bootstrapAddress* {.
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
bootstrapPort* {.
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
genesisOffset* {.
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
outputGenesis* {.
desc: "Output file where to write the initial state snapshot."
2019-11-11 14:43:12 +00:00
name: "output-genesis" }: OutFile
withGenesisRoot* {.
defaultValue: false
2019-11-11 14:43:12 +00:00
desc: "Include a genesis root in 'network.json'."
name: "with-genesis-root" }: bool
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
of importValidator:
keyFiles* {.
desc: "File with validator key to be imported (in hex form)."
2019-11-11 14:43:12 +00:00
name: "keyfile" }: seq[ValidatorKeyPath]
of makeDeposits:
totalQuickstartDeposits* {.
defaultValue: 0
2019-11-11 14:43:12 +00:00
desc: "Number of quick-start deposits to generate."
name: "quickstart-deposits" }: int
totalRandomDeposits* {.
defaultValue: 0
2019-11-11 14:43:12 +00:00
desc: "Number of secure random deposits to generate."
name: "random-deposits" }: int
depositsDir* {.
defaultValue: "validators"
2019-11-11 14:43:12 +00:00
desc: "Folder to write deposits to."
name: "deposits-dir" }: string
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
of query:
case queryCmd* {.
defaultValue: nimQuery
2019-11-11 14:43:12 +00:00
command
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
proc defaultPort*(config: BeaconNodeConf): int =
9000
proc defaultDataDir*(conf: BeaconNodeConf): string =
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
getHomeDir() / dataDir / "BeaconNode"
2018-11-29 01:08:34 +00:00
proc validatorFileBaseName*(validatorIdx: int): string =
# there can apparently be tops 4M validators so we use 7 digits..
fmt"v{validatorIdx:07}"
func dumpDir*(conf: BeaconNodeConf): string =
conf.dataDir / "dump"
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