2020-04-22 07:53:02 +02:00
{. push raises : [ Defect ] . }
2018-11-24 01:58:49 +02:00
import
2020-11-27 21:48:33 +02:00
strutils , os , options , unicode , uri ,
2020-07-02 18:14:11 +03:00
chronicles , chronicles / options as chroniclesOptions ,
2020-10-01 22:08:59 +03:00
confutils , confutils / defs , confutils / std / net , stew / shims / net as stewNet ,
2020-09-22 23:42:42 +03:00
stew / io2 , unicodedb / properties , normalize ,
2020-11-12 21:01:26 +02:00
eth / common / eth_types as commonEthTypes ,
2020-11-25 00:23:28 +01:00
eth / p2p / discoveryv5 / enr ,
2020-07-17 23:59:50 +03:00
json_serialization , web3 / [ ethtypes , confutils_defs ] ,
2020-10-06 18:32:17 +03:00
spec / [ crypto , keystore , digest , datatypes , network ] ,
2020-10-27 13:04:17 +02:00
network_metadata , filepath
2018-12-19 14:58:53 +02:00
export
2020-11-27 21:48:33 +02:00
uri ,
2020-10-01 22:08:59 +03:00
defaultEth2TcpPort , enabledLogLevel , ValidIpAddress ,
defs , parseCmdArg , completeCmdArg , network_metadata
2019-03-26 21:44:51 +02:00
2018-11-24 01:58:49 +02:00
type
2020-05-22 20:04:52 +03:00
BNStartUpCmd * = enum
2018-12-19 14:58:53 +02:00
noCommand
2019-03-26 12:01:13 +02:00
createTestnet
2020-06-16 01:20:31 +03:00
deposits
2020-06-23 22:11:07 +03:00
wallets
2020-11-25 00:23:28 +01:00
record
2020-12-04 18:28:42 +02:00
web3
2020-06-16 01:20:31 +03:00
2020-06-23 22:11:07 +03:00
WalletsCmd * {. pure . } = enum
create = " Creates a new EIP-2386 wallet "
restore = " Restores a wallet from cold storage "
list = " Lists details about all wallets "
2020-06-16 01:20:31 +03:00
2020-06-23 22:11:07 +03:00
DepositsCmd * {. pure . } = enum
2020-11-27 21:48:33 +02:00
# create = "Creates validator keystores and deposits"
2020-08-02 20:26:57 +03:00
` import ` = " Imports password-protected keystores interactively "
2020-11-27 21:48:33 +02:00
# status = "Displays status information about all deposits"
exit = " Submits a validator voluntary exit "
2019-11-01 11:53:06 +02:00
2020-05-22 20:04:52 +03:00
VCStartUpCmd * = enum
VCNoCommand
2020-11-25 00:23:28 +01:00
RecordCmd * {. pure . } = enum
create = " Create a new ENR "
print = " Print the content of a given ENR "
2020-12-04 18:28:42 +02:00
Web3Cmd * {. pure . } = enum
test = " Test a web3 provider "
Web3Mode * {. pure . } = enum
2021-01-29 23:21:44 +02:00
auto # Enabled only when validators are attached
enabled # Always enabled
disabled # Always disabled
2020-12-04 18:28:42 +02:00
2018-11-29 03:08:34 +02:00
BeaconNodeConf * = object
2019-01-17 01:01:15 +02:00
logLevel * {.
2020-11-09 10:12:48 +02:00
defaultValue : " INFO "
2020-11-12 11:46:02 +01:00
desc : " Sets the log level for process and topics (e.g. \" DEBUG; TRACE:discv5,libp2p; REQUIRED:none; DISABLED:none \" ) "
2020-04-28 01:39:04 +03:00
name : " log-level " } : string
2019-03-18 05:54:08 +02:00
2020-07-15 16:15:55 +03:00
logFile * {.
desc : " Specifies a path for the written Json log file "
name : " log-file " } : Option [ OutFile ]
2020-07-02 18:14:11 +03:00
eth2Network * {.
desc : " The Eth2 network to join "
name : " network " } : Option [ string ]
2019-03-19 19:22:17 +02:00
dataDir * {.
2019-10-29 01:04:52 +02:00
defaultValue : config . defaultDataDir ( )
2020-06-23 22:11:07 +03:00
desc : " The directory where nimbus will store all blockchain data "
2019-11-11 14:43:12 +00:00
abbr : " d "
name : " data-dir " } : OutDir
2019-01-17 01:01:15 +02:00
2020-08-01 21:32:41 +03:00
validatorsDirFlag * {.
desc : " A directory containing validator keystores "
name : " validators-dir " } : Option [ InputDir ]
2020-08-02 20:26:57 +03:00
secretsDirFlag * {.
desc : " A directory containing validator keystore passwords "
name : " secrets-dir " } : Option [ InputDir ]
2020-07-17 23:59:50 +03:00
walletsDirFlag * {.
desc : " A directory containing wallet files "
name : " wallets-dir " } : Option [ InputDir ]
2020-03-24 13:13:07 +02:00
web3Url * {.
2019-10-29 01:04:52 +02:00
defaultValue : " "
2020-06-23 22:11:07 +03:00
desc : " URL of the Web3 server to observe Eth1 "
2019-11-11 14:43:12 +00:00
name : " web3-url " } : string
2019-09-01 17:02:49 +02:00
2020-12-04 18:28:42 +02:00
web3Mode * {.
hidden
defaultValue : Web3Mode . auto
desc : " URL of the Web3 server to observe Eth1 "
name : " web3-mode " } : Web3Mode
2020-06-19 20:42:28 +03:00
2020-06-01 22:48:20 +03:00
nonInteractive * {.
2020-06-23 22:11:07 +03:00
desc : " Do not display interative prompts. Quit on missing configuration "
2020-06-01 22:48:20 +03:00
name : " non-interactive " } : bool
2020-08-25 15:49:05 +03:00
netKeyFile * {.
defaultValue : " random " ,
desc : " Source of network (secp256k1) private key file " &
" (random|<path>) (default: random) "
name : " netkey-file " } : string
netKeyInsecurePassword * {.
defaultValue : false ,
desc : " Use pre-generated INSECURE password for network private key " &
" file (default: false) "
name : " insecure-netkey-password " } : bool
2020-11-28 09:00:36 +02:00
agentString * {.
defaultValue : " nimbus " ,
desc : " Node agent string which is used as identifier in network "
name : " agent-string " } : string
2021-01-12 13:43:15 +01:00
subscribeAllSubnets * {.
defaultValue : false ,
desc : " Subscribe to all attestation subnet topics when gossiping "
name : " subscribe-all-subnets " } : bool
2021-02-19 16:18:17 +01:00
# Can we use a set[enum]?
testDualSlashingProtectionDBs * {.
hidden
defaultValue : false
desc : " Use the the 2 slashing protection implementation at the same time to ensure no regression. "
name : " slashing-test-dual-db " } : bool
2018-12-19 14:58:53 +02:00
case cmd * {.
command
2020-05-22 20:04:52 +03:00
defaultValue : noCommand } : BNStartUpCmd
2018-12-19 14:58:53 +02:00
of noCommand :
bootstrapNodes * {.
2020-06-23 22:11:07 +03:00
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-24 01:58:49 +02:00
2018-12-19 14:58:53 +02:00
bootstrapNodesFile * {.
2019-10-29 01:04:52 +02:00
defaultValue : " "
2020-06-23 22:11:07 +03:00
desc : " Specifies a line-delimited file of bootstrap Ethereum network addresses "
2019-11-11 14:43:12 +00:00
name : " bootstrap-file " } : InputFile
2018-11-24 01:58:49 +02:00
2020-09-27 22:00:24 +02:00
listenAddress * {.
2020-03-18 21:36:22 +02:00
defaultValue : defaultListenAddress ( config )
2020-09-27 22:00:24 +02:00
desc : " Listening address for the Ethereum LibP2P and Discovery v5 traffic "
2020-06-05 18:08:50 +03:00
name : " listen-address " } : ValidIpAddress
2020-03-18 21:36:22 +02:00
2018-12-19 14:58:53 +02:00
tcpPort * {.
2020-03-17 00:28:54 +02:00
defaultValue : defaultEth2TcpPort
2020-06-23 22:11:07 +03:00
desc : " Listening TCP port for Ethereum LibP2P traffic "
2020-03-17 00:28:54 +02:00
name : " tcp-port " } : Port
2018-11-24 01:58:49 +02:00
2018-12-19 14:58:53 +02:00
udpPort * {.
2020-03-17 00:28:54 +02:00
defaultValue : defaultEth2TcpPort
2020-06-23 22:11:07 +03:00
desc : " Listening UDP port for node discovery "
2020-03-17 00:28:54 +02:00
name : " udp-port " } : Port
2018-11-24 01:58:49 +02:00
2019-12-18 03:11:20 +02:00
maxPeers * {.
2020-11-29 14:43:41 +01:00
defaultValue : 160 # 5 (fanout) * 64 (subnets) / 2 (subs) for a heathy mesh
2019-12-18 03:11:20 +02:00
desc : " The maximum number of peers to connect to "
name : " max-peers " } : int
2019-03-18 21:57:19 -06:00
nat * {.
2019-10-29 01:04:52 +02:00
desc : " Specify method to use for determining public address. " &
2020-06-23 22:11:07 +03:00
" Must be one of: any, none, upnp, pmp, extip:<IP> "
2019-10-29 01:04:52 +02:00
defaultValue : " any " } : string
2019-03-18 21:57:19 -06:00
2021-02-02 09:07:21 +01:00
enrAutoUpdate * {.
defaultValue : false
desc : " Discovery can automatically update its ENR with the IP address " &
" and UDP port as seen by other nodes it communicates with. " &
" This option allows to enable/disable this functionality "
name : " enr-auto-update " . } : bool
2020-09-22 23:42:42 +03:00
weakSubjectivityCheckpoint * {.
desc : " Weak subjectivity checkpoint in the format block_root:epoch_number "
2020-10-06 18:32:17 +03:00
name : " weak-subjectivity-checkpoint " } : Option [ Checkpoint ]
2018-12-19 14:58:53 +02:00
2020-09-22 23:42:42 +03:00
finalizedCheckpointState * {.
desc : " SSZ file specifying a recent finalized state "
name : " finalized-checkpoint-state " } : Option [ InputFile ]
finalizedCheckpointBlock * {.
desc : " SSZ file specifying a recent finalized block "
name : " finalized-checkpoint-block " } : Option [ InputFile ]
2020-07-02 18:52:48 +03:00
2019-10-29 01:04:52 +02:00
nodeName * {.
2019-11-11 14:43:12 +00:00
defaultValue : " "
2019-03-22 16:35:20 +02:00
desc : " A name for this node that will appear in the logs. " &
2020-06-23 22:11:07 +03:00
" If you set this to ' auto ' , a persistent automatically generated ID will be selected for each --data-dir folder "
2019-11-11 14:43:12 +00:00
name : " node-name " } : string
2019-03-22 16:35:20 +02:00
2020-06-29 20:30:19 +03:00
graffiti * {.
desc : " The graffiti value that will appear in proposed blocks. " &
2020-11-09 10:12:48 +02:00
" You can use a 0x-prefixed hex encoded string to specify raw bytes "
2020-06-29 20:30:19 +03:00
name : " graffiti " } : Option [ GraffitiBytes ]
2020-02-17 19:24:14 +01:00
verifyFinalization * {.
defaultValue : false
2020-06-23 22:11:07 +03:00
desc : " Specify whether to verify finalization occurs on schedule, for testing "
2020-02-17 19:24:14 +01:00
name : " verify-finalization " } : bool
2020-02-17 22:22:50 +01:00
stopAtEpoch * {.
2020-02-17 19:24:14 +01:00
defaultValue : 0
2020-06-23 22:11:07 +03:00
desc : " A positive epoch selects the epoch at which to stop "
2020-02-17 22:22:50 +01:00
name : " stop-at-epoch " } : uint64
2020-02-17 19:24:14 +01:00
2020-03-17 00:28:54 +02:00
metricsEnabled * {.
2019-10-29 01:04:52 +02:00
defaultValue : false
2020-06-23 22:11:07 +03:00
desc : " Enable the metrics server "
2020-03-17 00:28:54 +02:00
name : " metrics " } : bool
2019-09-07 13:48:05 -04:00
2020-03-17 00:28:54 +02:00
metricsAddress * {.
2020-03-18 21:36:22 +02:00
defaultValue : defaultAdminListenAddress ( config )
2020-06-23 22:11:07 +03:00
desc : " Listening address of the metrics server "
2020-06-05 18:08:50 +03:00
name : " metrics-address " } : ValidIpAddress
2019-09-07 13:48:05 -04:00
2020-03-17 00:28:54 +02:00
metricsPort * {.
2019-10-29 01:04:52 +02:00
defaultValue : 8008
2020-06-23 22:11:07 +03:00
desc : " Listening HTTP port of the metrics server "
2020-03-17 00:28:54 +02:00
name : " metrics-port " } : Port
2019-09-07 13:48:05 -04:00
2020-03-18 21:36:22 +02:00
statusBarEnabled * {.
defaultValue : true
2020-06-23 22:11:07 +03:00
desc : " Display a status bar at the bottom of the terminal screen "
2020-03-18 21:36:22 +02:00
name : " status-bar " } : bool
statusBarContents * {.
2020-06-08 18:04:11 +02:00
defaultValue : " peers: $connected_peers ; " &
" finalized: $finalized_root : $finalized_epoch ; " &
" head: $head_root : $head_epoch : $head_epoch_slot ; " &
2020-09-11 15:46:01 +03:00
" time: $epoch : $epoch_slot ( $slot ); " &
2020-11-28 20:53:51 +02:00
" sync: $sync_status | " &
" ETH: $attached_validators_balance "
2020-06-23 22:11:07 +03:00
desc : " Textual template for the contents of the status bar "
2020-03-18 21:36:22 +02:00
name : " status-bar-contents " } : string
rpcEnabled * {.
defaultValue : false
desc : " Enable the JSON-RPC server "
name : " rpc " } : bool
rpcPort * {.
defaultValue : defaultEth2RpcPort
2020-06-23 22:11:07 +03:00
desc : " HTTP port for the JSON-RPC service "
2020-03-18 21:36:22 +02:00
name : " rpc-port " } : Port
rpcAddress * {.
defaultValue : defaultAdminListenAddress ( config )
desc : " Listening address of the RPC server "
2020-06-05 18:08:50 +03:00
name : " rpc-address " } : ValidIpAddress
2020-03-18 21:36:22 +02:00
2020-09-01 16:44:40 +03:00
inProcessValidators * {.
2020-11-07 20:00:31 +02:00
defaultValue : true # the use of the nimbus_signing_process binary by default will be delayed until async I/O over stdin/stdout is developed for the child process.
2020-09-01 16:44:40 +03:00
desc : " Disable the push model (the beacon node tells a signing process with the private keys of the validators what to sign and when) and load the validators in the beacon node itself "
name : " in-process-validators " } : bool
2020-08-24 13:52:06 +02:00
discv5Enabled * {.
defaultValue : true
desc : " Enable Discovery v5 "
name : " discv5 " } : bool
2020-03-18 21:36:22 +02:00
dumpEnabled * {.
2019-12-03 12:32:27 +01:00
defaultValue : false
desc : " Write SSZ dumps of blocks, attestations and states to data dir "
2020-03-18 21:36:22 +02:00
name : " dump " } : bool
2019-12-03 12:32:27 +01:00
2021-02-01 12:18:16 +01:00
doppelgangerDetection * {.
2021-02-03 18:11:42 +01:00
defaultValue : true
desc : " Whether to detect whether another validator is be running the same validator keys (default true) "
2021-02-01 12:18:16 +01:00
name : " doppelganger-detection "
2021-02-03 18:11:42 +01:00
} : bool
2020-10-27 18:21:35 +01:00
2019-03-19 19:22:17 +02:00
of createTestnet :
2020-07-17 23:59:50 +03:00
testnetDepositsFile * {.
desc : " A LaunchPad deposits file for the genesis state validators "
name : " deposits-file " } : InputFile
2019-03-07 07:59:28 -06:00
2019-03-27 14:06:06 +02:00
totalValidators * {.
2020-06-23 22:11:07 +03:00
desc : " The number of validator deposits in the newly created chain "
2019-11-11 14:43:12 +00:00
name : " total-validators " } : uint64
2019-03-07 07:59:28 -06:00
firstValidator * {.
2019-10-29 01:04:52 +02:00
defaultValue : 0
2020-06-23 22:11:07 +03:00
desc : " Index of first validator to add to validator list "
2019-11-11 14:43:12 +00:00
name : " first-validator " } : uint64
2019-03-19 19:22:17 +02:00
2019-03-27 14:06:06 +02:00
lastUserValidator * {.
2019-10-29 01:04:52 +02:00
defaultValue : config . totalValidators - 1 ,
2020-07-23 17:58:54 +02:00
desc : " The last validator index that will be free for taking from a testnet participant "
2019-11-11 14:43:12 +00:00
name : " last-user-validator " } : uint64
2019-03-19 19:22:17 +02:00
bootstrapAddress * {.
2020-10-01 22:08:59 +03:00
defaultValue : init ( ValidIpAddress , " 127.0.0.1 " )
2020-06-23 22:11:07 +03:00
desc : " The public IP address that will be advertised as a bootstrap node for the testnet "
2020-06-05 18:08:50 +03:00
name : " bootstrap-address " } : ValidIpAddress
2019-03-19 19:22:17 +02:00
bootstrapPort * {.
2020-03-17 00:28:54 +02:00
defaultValue : defaultEth2TcpPort
2020-06-23 22:11:07 +03:00
desc : " The TCP/UDP port that will be used by the bootstrap node "
2020-03-17 00:28:54 +02:00
name : " bootstrap-port " } : Port
2018-12-19 14:58:53 +02:00
2019-02-15 10:33:32 -06:00
genesisOffset * {.
2019-10-29 01:04:52 +02:00
defaultValue : 5
2020-06-23 22:11:07 +03:00
desc : " Seconds from now to add to genesis time "
2019-11-11 14:43:12 +00:00
name : " genesis-offset " } : int
2019-02-15 10:33:32 -06:00
2019-03-19 19:22:17 +02:00
outputGenesis * {.
2020-06-23 22:11:07 +03: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 05:54:08 +02:00
2019-09-10 17:55:58 -04:00
withGenesisRoot * {.
2019-10-29 01:04:52 +02:00
defaultValue : false
2020-06-23 22:11:07 +03:00
desc : " Include a genesis root in ' network.json ' "
2019-11-11 14:43:12 +00:00
name : " with-genesis-root " } : bool
2019-09-10 17:55:58 -04:00
2019-10-29 01:04:52 +02:00
outputBootstrapFile * {.
2020-06-23 22:11:07 +03:00
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 18:13:27 -04:00
2020-06-23 22:11:07 +03:00
of wallets :
case walletsCmd * {. command . } : WalletsCmd
of WalletsCmd . create :
nextAccount * {.
desc : " Initial value for the ' nextaccount ' property of the wallet "
name : " next-account " } : Option [ Natural ]
2020-07-17 23:59:50 +03:00
createdWalletNameFlag * {.
desc : " An easy-to-remember name for the wallet of your choice "
name : " name " } : Option [ WalletName ]
2020-07-14 22:00:35 +03:00
2020-07-17 23:59:50 +03:00
createdWalletFileFlag * {.
2020-06-23 22:11:07 +03:00
desc : " Output wallet file "
name : " out " } : Option [ OutFile ]
of WalletsCmd . restore :
2020-07-17 23:59:50 +03:00
restoredWalletNameFlag * {.
2020-06-23 22:11:07 +03:00
desc : " An easy-to-remember name for the wallet of your choice "
name : " name " } : Option [ WalletName ]
2020-07-17 23:59:50 +03:00
restoredWalletFileFlag * {.
desc : " Output wallet file "
name : " out " } : Option [ OutFile ]
2020-06-23 22:11:07 +03:00
restoredDepositsCount * {.
desc : " Expected number of deposits to recover. If not specified, " &
" Nimbus will try to guess the number by inspecting the latest " &
" beacon state "
name : " deposits " . } : Option [ Natural ]
of WalletsCmd . list :
discard
2018-11-24 01:58:49 +02:00
2020-06-16 01:20:31 +03:00
of deposits :
2020-06-16 21:38:51 +03:00
case depositsCmd * {. command . } : DepositsCmd
2020-11-27 21:48:33 +02:00
#[
2020-06-23 22:11:07 +03:00
of DepositsCmd . create :
2020-06-16 01:20:31 +03:00
totalDeposits * {.
defaultValue : 1
2020-06-23 22:11:07 +03:00
desc : " Number of deposits to generate "
2020-06-16 01:20:31 +03:00
name : " count " } : int
2020-06-23 22:11:07 +03:00
existingWalletId * {.
desc : " An existing wallet ID. If not specified, a new wallet will be created "
name : " wallet " } : Option [ WalletName ]
2020-06-16 01:20:31 +03:00
outValidatorsDir * {.
defaultValue : " validators "
2020-08-01 21:32:41 +03:00
desc : " Output folder for validator keystores "
name : " out-validators-dir " } : string
2020-06-16 01:20:31 +03:00
outSecretsDir * {.
defaultValue : " secrets "
2020-06-23 22:11:07 +03:00
desc : " Output folder for randomly generated keystore passphrases "
2020-06-16 01:20:31 +03:00
name : " out-secrets-dir " } : string
2020-07-17 23:59:50 +03:00
outDepositsFile * {.
desc : " The name of generated deposits file "
name : " out-deposits-file " } : Option [ OutFile ]
newWalletNameFlag * {.
desc : " An easy-to-remember name for the wallet of your choice "
2020-08-02 20:26:57 +03:00
name : " new-wallet-name " } : Option [ WalletName ]
2020-07-17 23:59:50 +03:00
newWalletFileFlag * {.
desc : " Output wallet file "
name : " new-wallet-file " } : Option [ OutFile ]
2020-06-16 21:38:51 +03:00
2020-11-27 21:48:33 +02:00
of DepositsCmd . status :
discard
#]#
2020-08-02 20:26:57 +03:00
of DepositsCmd . ` import ` :
importedDepositsDir * {.
argument
2020-11-28 20:50:09 +02:00
desc : " A directory with keystores to import " } : Option [ InputDir ]
2020-08-02 20:26:57 +03:00
2020-11-27 21:48:33 +02:00
of DepositsCmd . exit :
exitedValidator * {.
name : " validator "
desc : " Validator index or a public key of the exited validator " } : string
rpcUrlForExit * {.
name : " rpc-url "
2021-01-15 19:39:45 +02:00
defaultValue : parseUri ( " http://localhost: " & $ defaultEth2RpcPort )
2020-11-27 21:48:33 +02:00
desc : " URL of the beacon node JSON-RPC service " } : Uri
exitAtEpoch * {.
name : " epoch "
desc : " The desired exit epoch " } : Option [ uint64 ]
2020-06-23 22:11:07 +03:00
2020-11-25 00:23:28 +01:00
of record :
case recordCmd * {. command . } : RecordCmd
of RecordCmd . create :
ipExt * {.
desc : " External IP address "
name : " ip " . } : ValidIpAddress
tcpPortExt * {.
desc : " External TCP port "
name : " tcp-port " . } : Port
udpPortExt * {.
desc : " External UDP port "
name : " udp-port " . } : Port
seqNumber * {.
defaultValue : 1 ,
desc : " Record sequence number "
name : " seq-number " . } : uint
fields * {.
desc : " Additional record key pairs, provide as <string>:<bytes in hex> "
name : " field " . } : seq [ ( string ) ]
of RecordCmd . print :
recordPrint * {.
argument
desc : " ENR URI of the record to print "
name : " enr " . } : Record
2020-12-04 18:28:42 +02:00
of web3 :
case web3Cmd * {. command . } : Web3Cmd
of Web3Cmd . test :
web3TestUrl * {.
argument
desc : " The web3 provider URL to test "
name : " url " } : Uri
2020-05-22 20:04:52 +03:00
ValidatorClientConf * = object
logLevel * {.
2020-11-09 10:12:48 +02:00
defaultValue : " INFO "
desc : " Sets the log level "
2020-05-22 20:04:52 +03:00
name : " log-level " } : string
2020-07-15 16:15:55 +03:00
logFile * {.
desc : " Specifies a path for the written Json log file "
name : " log-file " } : Option [ OutFile ]
2020-05-22 20:04:52 +03:00
dataDir * {.
defaultValue : config . defaultDataDir ( )
2020-06-23 22:11:07 +03:00
desc : " The directory where nimbus will store all blockchain data "
2020-05-22 20:04:52 +03:00
abbr : " d "
name : " data-dir " } : OutDir
2020-06-01 22:48:20 +03:00
nonInteractive * {.
2020-06-23 22:11:07 +03:00
desc : " Do not display interative prompts. Quit on missing configuration "
2020-06-01 22:48:20 +03:00
name : " non-interactive " } : bool
2020-09-01 16:44:40 +03:00
validatorsDirFlag * {.
desc : " A directory containing validator keystores "
name : " validators-dir " } : Option [ InputDir ]
secretsDirFlag * {.
desc : " A directory containing validator keystore passwords "
name : " secrets-dir " } : Option [ InputDir ]
2020-05-22 20:04:52 +03:00
case cmd * {.
command
defaultValue : VCNoCommand } : VCStartUpCmd
2020-10-27 13:04:17 +02:00
2020-05-22 20:04:52 +03:00
of VCNoCommand :
2020-06-29 20:30:19 +03:00
graffiti * {.
desc : " The graffiti value that will appear in proposed blocks. " &
2020-11-09 10:12:48 +02:00
" You can use a 0x-prefixed hex encoded string to specify raw bytes "
2020-06-29 20:30:19 +03:00
name : " graffiti " } : Option [ GraffitiBytes ]
2020-09-01 16:38:34 +03:00
stopAtEpoch * {.
defaultValue : 0
desc : " A positive epoch selects the epoch at which to stop "
name : " stop-at-epoch " } : uint64
2020-05-22 20:04:52 +03:00
rpcPort * {.
defaultValue : defaultEth2RpcPort
2020-09-01 16:44:40 +03:00
desc : " HTTP port of the server to connect to for RPC - for the validator duties in the pull model "
2020-05-22 20:04:52 +03:00
name : " rpc-port " } : Port
rpcAddress * {.
defaultValue : defaultAdminListenAddress ( config )
2020-09-01 16:44:40 +03:00
desc : " Address of the server to connect to for RPC - for the validator duties in the pull model "
2020-06-05 18:08:50 +03:00
name : " rpc-address " } : ValidIpAddress
2020-10-27 13:04:17 +02:00
2020-09-01 16:44:40 +03:00
retryDelay * {.
defaultValue : 10
desc : " Delay in seconds between retries after unsuccessful attempts to connect to a beacon node "
name : " retry-delay " } : int
2020-06-01 22:48:20 +03:00
2020-05-22 20:04:52 +03:00
proc defaultDataDir * ( conf : BeaconNodeConf | ValidatorClientConf ) : string =
2019-03-19 19:22:17 +02:00
let dataDir = when defined ( windows ) :
" AppData " / " Roaming " / " Nimbus "
elif defined ( macosx ) :
" Library " / " Application Support " / " Nimbus "
else :
" .cache " / " nimbus "
2018-12-09 10:25:02 +02:00
2019-10-29 01:04:52 +02:00
getHomeDir ( ) / dataDir / " BeaconNode "
2018-11-29 03:08:34 +02:00
2020-05-22 20:04:52 +03:00
func dumpDir * ( conf : BeaconNodeConf | ValidatorClientConf ) : string =
2019-12-03 12:32:27 +01:00
conf . dataDir / " dump "
2019-12-10 15:20:40 +01:00
2020-06-16 10:49:32 +02:00
func dumpDirInvalid * ( conf : BeaconNodeConf | ValidatorClientConf ) : string =
conf . dumpDir / " invalid " # things that failed validation
func dumpDirIncoming * ( conf : BeaconNodeConf | ValidatorClientConf ) : string =
conf . dumpDir / " incoming " # things that couldn't be validated (missingparent etc)
func dumpDirOutgoing * ( conf : BeaconNodeConf | ValidatorClientConf ) : string =
conf . dumpDir / " outgoing " # things we produced
proc createDumpDirs * ( conf : BeaconNodeConf ) =
if conf . dumpEnabled :
2020-10-27 13:04:17 +02:00
let resInv = secureCreatePath ( conf . dumpDirInvalid )
2020-08-27 21:23:41 +03:00
if resInv . isErr ( ) :
warn " Could not create dump directory " , path = conf . dumpDirInvalid
2020-10-27 13:04:17 +02:00
let resInc = secureCreatePath ( conf . dumpDirIncoming )
2020-08-27 21:23:41 +03:00
if resInc . isErr ( ) :
warn " Could not create dump directory " , path = conf . dumpDirIncoming
2020-10-27 13:04:17 +02:00
let resOut = secureCreatePath ( conf . dumpDirOutgoing )
2020-08-27 21:23:41 +03:00
if resOut . isErr ( ) :
warn " Could not create dump directory " , path = conf . dumpDirOutgoing
2020-06-16 10:49:32 +02:00
2020-06-29 20:30:19 +03:00
func parseCmdArg * ( T : type GraffitiBytes , input : TaintedString ) : T
{. raises : [ ValueError , Defect ] . } =
GraffitiBytes . init ( string input )
func completeCmdArg * ( T : type GraffitiBytes , input : TaintedString ) : seq [ string ] =
return @ [ ]
2020-11-12 21:01:26 +02:00
func parseCmdArg * ( T : type BlockHashOrNumber , input : TaintedString ) : T
{. raises : [ ValueError , Defect ] . } =
init ( BlockHashOrNumber , string input )
func completeCmdArg * ( T : type BlockHashOrNumber , input : TaintedString ) : seq [ string ] =
return @ [ ]
2020-11-27 21:48:33 +02:00
func parseCmdArg * ( T : type Uri , input : TaintedString ) : T
{. raises : [ ValueError , Defect ] . } =
parseUri ( input . string )
func completeCmdArg * ( T : type Uri , input : TaintedString ) : seq [ string ] =
return @ [ ]
2020-10-06 18:32:17 +03:00
func parseCmdArg * ( T : type Checkpoint , input : TaintedString ) : T
2020-09-22 23:42:42 +03:00
{. raises : [ ValueError , Defect ] . } =
2020-10-06 18:32:17 +03:00
let sepIdx = find ( input . string , ' : ' )
if sepIdx = = - 1 :
raise newException ( ValueError ,
" The weak subjectivity checkpoint must be provided in the `block_root:epoch_number` format " )
T ( root : Eth2Digest . fromHex ( input [ 0 .. < sepIdx ] ) ,
epoch : parseBiggestUInt ( input [ sepIdx .. ^ 1 ] ) . Epoch )
func completeCmdArg * ( T : type Checkpoint , input : TaintedString ) : seq [ string ] =
2020-09-22 23:42:42 +03:00
return @ [ ]
2020-10-02 17:48:27 +03:00
proc isPrintable ( rune : Rune ) : bool =
# This can be eventually replaced by the `unicodeplus` package, but a single
# proc does not justify the extra dependencies at the moment:
# https://github.com/nitely/nim-unicodeplus
# https://github.com/nitely/nim-segmentation
rune = = Rune ( 0x20 ) or unicodeCategory ( rune ) notin ctgC + ctgZ
2020-06-23 22:11:07 +03:00
func parseCmdArg * ( T : type WalletName , input : TaintedString ) : T
{. raises : [ ValueError , Defect ] . } =
if input . len = = 0 :
raise newException ( ValueError , " The wallet name should not be empty " )
if input [ 0 ] = = ' _ ' :
raise newException ( ValueError , " The wallet name should not start with an underscore " )
2020-10-02 17:48:27 +03:00
for rune in runes ( input . string ) :
if not rune . isPrintable :
raise newException ( ValueError , " The wallet name should consist only of printable characters " )
# From the Unicode Normalization FAQ (https://unicode.org/faq/normalization.html):
# NFKC is the preferred form for identifiers, especially where there are security concerns
# (see UTR #36 http://www.unicode.org/reports/tr36/)
return T ( toNFKC ( input ) )
2020-06-23 22:11:07 +03:00
func completeCmdArg * ( T : type WalletName , input : TaintedString ) : seq [ string ] =
return @ [ ]
2020-11-25 00:23:28 +01:00
proc parseCmdArg * ( T : type enr . Record , p : TaintedString ) : T
{. raises : [ ConfigurationError , Defect ] . } =
if not fromURI ( result , p ) :
raise newException ( ConfigurationError , " Invalid ENR " )
proc completeCmdArg * ( T : type enr . Record , val : TaintedString ) : seq [ string ] =
return @ [ ]
2020-06-23 22:11:07 +03:00
2020-06-03 14:52:36 +03:00
func validatorsDir * ( conf : BeaconNodeConf | ValidatorClientConf ) : string =
string conf . validatorsDirFlag . get ( InputDir ( conf . dataDir / " validators " ) )
func secretsDir * ( conf : BeaconNodeConf | ValidatorClientConf ) : string =
string conf . secretsDirFlag . get ( InputDir ( conf . dataDir / " secrets " ) )
2019-12-10 15:20:40 +01:00
2020-09-01 16:44:40 +03:00
func walletsDir * ( conf : BeaconNodeConf ) : string =
2020-07-17 23:59:50 +03:00
if conf . walletsDirFlag . isSome :
conf . walletsDirFlag . get . string
else :
conf . dataDir / " wallets "
func outWalletName * ( conf : BeaconNodeConf ) : Option [ WalletName ] =
proc fail {. noReturn . } =
raiseAssert " outWalletName should be used only in the right context "
2020-07-14 22:00:35 +03:00
case conf . cmd
of wallets :
2020-07-17 23:59:50 +03:00
case conf . walletsCmd
of WalletsCmd . create : conf . createdWalletNameFlag
of WalletsCmd . restore : conf . restoredWalletNameFlag
of WalletsCmd . list : fail ( )
of deposits :
2020-11-27 21:48:33 +02:00
# TODO: Uncomment when the deposits create command is restored
#case conf.depositsCmd
#of DepositsCmd.create: conf.newWalletNameFlag
#else: fail()
fail ( )
2020-07-14 22:00:35 +03:00
else :
2020-07-17 23:59:50 +03:00
fail ( )
2020-07-14 22:00:35 +03:00
2020-07-17 23:59:50 +03:00
func outWalletFile * ( conf : BeaconNodeConf ) : Option [ OutFile ] =
proc fail {. noReturn . } =
raiseAssert " outWalletName should be used only in the right context "
case conf . cmd
of wallets :
case conf . walletsCmd
of WalletsCmd . create : conf . createdWalletFileFlag
of WalletsCmd . restore : conf . restoredWalletFileFlag
of WalletsCmd . list : fail ( )
of deposits :
2020-11-27 21:48:33 +02:00
# TODO: Uncomment when the deposits create command is restored
#case conf.depositsCmd
#of DepositsCmd.create: conf.newWalletFileFlag
#else: fail()
fail ( )
2020-07-17 23:59:50 +03:00
else :
fail ( )
2020-06-23 22:11:07 +03:00
2020-05-22 20:04:52 +03:00
func databaseDir * ( conf : BeaconNodeConf | ValidatorClientConf ) : string =
2019-12-10 15:20:40 +01:00
conf . dataDir / " db "
2020-06-05 18:08:50 +03:00
func defaultListenAddress * ( conf : BeaconNodeConf | ValidatorClientConf ) : ValidIpAddress =
2020-03-17 00:28:54 +02:00
# TODO: How should we select between IPv4 and IPv6
# Maybe there should be a config option for this.
2020-06-05 18:08:50 +03:00
( static ValidIpAddress . init ( " 0.0.0.0 " ) )
2020-03-17 00:28:54 +02:00
2020-06-05 18:08:50 +03:00
func defaultAdminListenAddress * ( conf : BeaconNodeConf | ValidatorClientConf ) : ValidIpAddress =
( static ValidIpAddress . init ( " 127.0.0.1 " ) )
2020-03-18 21:36:22 +02:00
2020-02-11 19:35:42 +02:00
template writeValue * ( writer : var JsonWriter ,
value : TypedInputFile | InputFile | InputDir | OutPath | OutDir | OutFile ) =
writer . writeValue ( string value )