nimbus-eth2/beacon_chain/conf.nim

344 lines
11 KiB
Nim
Raw Normal View History

{.push raises: [Defect].}
import
os, options,
chronicles, confutils, json_serialization,
confutils/defs, confutils/std/net,
chronicles/options as chroniclesOptions,
spec/[crypto, keystore]
export
defs, enabledLogLevel, parseCmdArg, completeCmdArg
type
ValidatorKeyPath* = TypedInputFile[ValidatorPrivKey, Txt, "privkey"]
BNStartUpCmd* = enum
noCommand
importValidator
createTestnet
makeDeposits
VCStartUpCmd* = enum
VCNoCommand
Eth1Network* = enum
custom
mainnet
rinkeby
goerli
2018-11-29 01:08:34 +00:00
BeaconNodeConf* = object
logLevel* {.
defaultValue: "DEBUG"
2019-11-11 14:43:12 +00:00
desc: "Sets the log level."
name: "log-level" }: string
eth1Network* {.
defaultValue: goerli
2019-11-11 14:43:12 +00:00
desc: "The Eth1 network tracked by the beacon node."
name: "eth1-network" }: Eth1Network
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
web3Url* {.
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
nonInteractive* {.
desc: "Do not display interative prompts. Quit on missing configuration."
name: "non-interactive" }: bool
case cmd* {.
command
defaultValue: noCommand }: BNStartUpCmd
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
libp2pAddress* {.
defaultValue: defaultListenAddress(config)
desc: "Listening address for the Ethereum LibP2P traffic."
2020-06-05 15:08:50 +00:00
name: "listen-address" }: ValidIpAddress
tcpPort* {.
defaultValue: defaultEth2TcpPort
desc: "Listening TCP port for Ethereum LibP2P traffic."
name: "tcp-port" }: Port
udpPort* {.
defaultValue: defaultEth2TcpPort
desc: "Listening UDP port for node discovery."
name: "udp-port" }: Port
maxPeers* {.
2020-06-05 20:25:01 +00:00
defaultValue: 79 # The Wall gets released
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]
validatorsDir* {.
desc: "A directory containing validator keystores."
name: "validators-dir" }: Option[InputDir]
secretsDir* {.
desc: "A directory containing validator keystore passwords."
name: "secrets-dir" }: Option[InputDir]
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
2020-02-17 21:22:50 +00:00
stopAtEpoch* {.
defaultValue: 0
2020-02-17 21:22:50 +00:00
desc: "A positive epoch selects the epoch at which to stop."
name: "stop-at-epoch" }: uint64
metricsEnabled* {.
defaultValue: false
2019-11-11 14:43:12 +00:00
desc: "Enable the metrics server."
name: "metrics" }: bool
metricsAddress* {.
defaultValue: defaultAdminListenAddress(config)
2019-11-11 14:43:12 +00:00
desc: "Listening address of the metrics server."
2020-06-05 15:08:50 +00:00
name: "metrics-address" }: ValidIpAddress
metricsPort* {.
defaultValue: 8008
2019-11-11 14:43:12 +00:00
desc: "Listening HTTP port of the metrics server."
name: "metrics-port" }: Port
statusBarEnabled* {.
defaultValue: true
desc: "Display a status bar at the bottom of the terminal screen."
name: "status-bar" }: bool
statusBarContents* {.
defaultValue: "peers: $connected_peers;" &
"finalized: $finalized_root:$finalized_epoch;" &
"head: $head_root:$head_epoch:$head_epoch_slot;" &
"time: $epoch:$epoch_slot ($slot)|" &
"ETH: $attached_validators_balance"
desc: "Textual template for the contents of the status bar."
name: "status-bar-contents" }: string
rpcEnabled* {.
defaultValue: false
desc: "Enable the JSON-RPC server"
name: "rpc" }: bool
rpcPort* {.
defaultValue: defaultEth2RpcPort
desc: "HTTP port for the JSON-RPC service."
name: "rpc-port" }: Port
rpcAddress* {.
defaultValue: defaultAdminListenAddress(config)
desc: "Listening address of the RPC server"
2020-06-05 15:08:50 +00:00
name: "rpc-address" }: ValidIpAddress
dumpEnabled* {.
defaultValue: false
desc: "Write SSZ dumps of blocks, attestations and states to data dir"
name: "dump" }: bool
of createTestnet:
testnetDepositsDir* {.
desc: "Directory containing validator keystores."
2019-11-11 14:43:12 +00:00
name: "validators-dir" }: InputDir
totalValidators* {.
desc: "The number of validator deposits 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* {.
2020-06-05 15:08:50 +00:00
defaultValue: ValidIpAddress.init("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."
2020-06-05 15:08:50 +00:00
name: "bootstrap-address" }: ValidIpAddress
bootstrapPort* {.
defaultValue: defaultEth2TcpPort
2019-11-11 14:43:12 +00:00
desc: "The TCP/UDP port that will be used by the bootstrap node."
name: "bootstrap-port" }: Port
genesisOffset* {.
defaultValue: 5
2019-11-11 14:43:12 +00:00
desc: "Seconds from now to add to genesis time."
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:
totalDeposits* {.
defaultValue: 1
desc: "Number of deposits to generate."
name: "count" }: int
outValidatorsDir* {.
defaultValue: "validators"
desc: "Output folder for validator keystores and deposits."
name: "out-validators-dir" }: string
outSecretsDir* {.
defaultValue: "secrets"
desc: "Output folder for randomly generated keystore passphrases."
name: "out-secrets-dir" }: string
2019-11-05 18:16:10 +00:00
depositPrivateKey* {.
defaultValue: ""
desc: "Private key of the controlling (sending) account.",
2019-11-11 14:43:12 +00:00
name: "deposit-private-key" }: string
2019-11-05 18:16:10 +00:00
minDelay* {.
defaultValue: 0.0
desc: "Minimum possible delay between making two deposits (in seconds)."
name: "min-delay" }: float
maxDelay* {.
defaultValue: 0.0
desc: "Maximum possible delay between making two deposits (in seconds)."
name: "max-delay" }: float
ValidatorClientConf* = object
logLevel* {.
defaultValue: "DEBUG"
desc: "Sets the log level."
name: "log-level" }: string
dataDir* {.
defaultValue: config.defaultDataDir()
desc: "The directory where nimbus will store all blockchain data."
abbr: "d"
name: "data-dir" }: OutDir
nonInteractive* {.
desc: "Do not display interative prompts. Quit on missing configuration."
name: "non-interactive" }: bool
case cmd* {.
command
defaultValue: VCNoCommand }: VCStartUpCmd
of VCNoCommand:
rpcPort* {.
defaultValue: defaultEth2RpcPort
desc: "HTTP port of the server to connect to for RPC."
name: "rpc-port" }: Port
rpcAddress* {.
defaultValue: defaultAdminListenAddress(config)
desc: "Address of the server to connect to for RPC."
2020-06-05 15:08:50 +00:00
name: "rpc-address" }: ValidIpAddress
validators* {.
required
desc: "Path to a validator key store, as generated by makeDeposits."
abbr: "v"
name: "validator" }: seq[ValidatorKeyPath]
validatorsDir* {.
desc: "A directory containing validator keystores."
name: "validators-dir" }: Option[InputDir]
secretsDir* {.
desc: "A directory containing validator keystore passwords."
name: "secrets-dir" }: Option[InputDir]
proc defaultDataDir*(conf: BeaconNodeConf|ValidatorClientConf): 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
func dumpDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
conf.dataDir / "dump"
func localValidatorsDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
string conf.validatorsDir.get(InputDir(conf.dataDir / "validators"))
func databaseDir*(conf: BeaconNodeConf|ValidatorClientConf): string =
conf.dataDir / "db"
2020-06-05 15:08:50 +00:00
func defaultListenAddress*(conf: BeaconNodeConf|ValidatorClientConf): ValidIpAddress =
# TODO: How should we select between IPv4 and IPv6
# Maybe there should be a config option for this.
2020-06-05 15:08:50 +00:00
(static ValidIpAddress.init("0.0.0.0"))
2020-06-05 15:08:50 +00:00
func defaultAdminListenAddress*(conf: BeaconNodeConf|ValidatorClientConf): ValidIpAddress =
(static ValidIpAddress.init("127.0.0.1"))
template writeValue*(writer: var JsonWriter,
value: TypedInputFile|InputFile|InputDir|OutPath|OutDir|OutFile) =
writer.writeValue(string value)