2022-05-31 10:45:37 +00:00
# beacon_chain
2023-01-20 14:14:37 +00:00
# Copyright (c) 2022-2023 Status Research & Development GmbH
2022-05-31 10:45:37 +00:00
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
2023-01-20 14:14:37 +00:00
{. push raises : [ ] . }
2022-05-31 10:45:37 +00:00
import
json_serialization / std / net ,
. / conf
export net , conf
type LightClientConf * = object
# Config
configFile * {.
desc : " Loads the configuration from a TOML file "
2022-06-15 18:04:07 +00:00
name : " config-file " . } : Option [ InputFile ]
2022-05-31 10:45:37 +00:00
# Logging
logLevel * {.
desc : " Sets the log level "
defaultValue : " INFO "
2022-06-15 18:04:07 +00:00
name : " log-level " . } : string
2022-05-31 10:45:37 +00:00
logStdout * {.
hidden
desc : " Specifies what kind of logs should be written to stdout (auto, colors, nocolors, json) "
defaultValueDesc : " auto "
defaultValue : StdoutLogKind . Auto
2022-06-15 18:04:07 +00:00
name : " log-format " . } : StdoutLogKind
2022-05-31 10:45:37 +00:00
logFile * {.
desc : " Specifies a path for the written Json log file (deprecated) "
2022-06-15 18:04:07 +00:00
name : " log-file " . } : Option [ OutFile ]
2022-05-31 10:45:37 +00:00
2022-07-14 04:07:40 +00:00
# Storage
dataDir * {.
desc : " The directory where nimbus will store all blockchain data "
defaultValue : config . defaultDataDir ( )
defaultValueDesc : " "
abbr : " d "
name : " data-dir " . } : OutDir
2022-05-31 10:45:37 +00:00
# Network
eth2Network * {.
desc : " The Eth2 network to join "
defaultValueDesc : " mainnet "
2022-06-15 18:04:07 +00:00
name : " network " . } : Option [ string ]
2022-05-31 10:45:37 +00:00
# Libp2p
bootstrapNodes * {.
desc : " Specifies one or more bootstrap nodes to use when connecting to the network "
abbr : " b "
2022-06-15 18:04:07 +00:00
name : " bootstrap-node " . } : seq [ string ]
2022-05-31 10:45:37 +00:00
bootstrapNodesFile * {.
desc : " Specifies a line-delimited file of bootstrap Ethereum network addresses "
defaultValue : " "
2022-06-15 18:04:07 +00:00
name : " bootstrap-file " . } : InputFile
2022-05-31 10:45:37 +00:00
listenAddress * {.
desc : " Listening address for the Ethereum LibP2P and Discovery v5 traffic "
defaultValue : defaultListenAddress
2022-07-20 18:17:21 +00:00
defaultValueDesc : $ defaultListenAddressDesc
2022-06-15 18:04:07 +00:00
name : " listen-address " . } : ValidIpAddress
2022-05-31 10:45:37 +00:00
tcpPort * {.
desc : " Listening TCP port for Ethereum LibP2P traffic "
defaultValue : defaultEth2TcpPort
2022-07-20 18:17:21 +00:00
defaultValueDesc : $ defaultEth2TcpPortDesc
2022-06-15 18:04:07 +00:00
name : " tcp-port " . } : Port
2022-05-31 10:45:37 +00:00
udpPort * {.
desc : " Listening UDP port for node discovery "
defaultValue : defaultEth2TcpPort
2022-07-20 18:17:21 +00:00
defaultValueDesc : $ defaultEth2TcpPortDesc
2022-06-15 18:04:07 +00:00
name : " udp-port " . } : Port
2022-05-31 10:45:37 +00:00
maxPeers * {.
desc : " The target number of peers to connect to "
defaultValue : 160 # 5 (fanout) * 64 (subnets) / 2 (subs) for a heathy mesh
2022-06-15 18:04:07 +00:00
name : " max-peers " . } : int
2022-05-31 10:45:37 +00:00
hardMaxPeers * {.
desc : " The maximum number of peers to connect to. Defaults to maxPeers * 1.5 "
2022-06-15 18:04:07 +00:00
name : " hard-max-peers " . } : Option [ int ]
2022-05-31 10:45:37 +00:00
nat * {.
desc : " Specify method to use for determining public address. " &
" Must be one of: any, none, upnp, pmp, extip:<IP> "
defaultValue : NatConfig ( hasExtIp : false , nat : NatAny )
defaultValueDesc : " any "
name : " nat " . } : NatConfig
enrAutoUpdate * {.
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 "
defaultValue : false
name : " enr-auto-update " . } : bool
2023-06-23 07:16:30 +00:00
enableYamux * {.
hidden
desc : " Enable the Yamux multiplexer "
defaultValue : false
name : " enable-yamux " . } : bool
2022-05-31 10:45:37 +00:00
agentString * {.
defaultValue : " nimbus " ,
desc : " Node agent string which is used as identifier in network "
2022-06-15 18:04:07 +00:00
name : " agent-string " . } : string
2022-05-31 10:45:37 +00:00
discv5Enabled * {.
desc : " Enable Discovery v5 "
defaultValue : true
2022-06-15 18:04:07 +00:00
name : " discv5 " . } : bool
2022-05-31 10:45:37 +00:00
directPeers * {.
desc : " The list of priviledged, secure and known peers to connect and maintain the connection to, this requires a not random netkey-file. In the complete multiaddress format like: /ip4/<address>/tcp/<port>/p2p/<peerId-public-key>. Peering agreements are established out of band and must be reciprocal. "
name : " direct-peer " . } : seq [ string ]
# Light client
trustedBlockRoot * {.
desc : " Recent trusted finalized block root to initialize light client from "
2022-06-15 18:04:07 +00:00
name : " trusted-block-root " . } : Eth2Digest
2022-05-31 10:45:37 +00:00
2022-07-14 04:07:40 +00:00
# Execution layer
web3Urls * {.
2023-03-05 01:40:21 +00:00
desc : " One or more execution layer Engine API URLs "
name : " web3-url " . } : seq [ EngineApiUrlConfigValue ]
elUrls * {.
desc : " One or more execution layer Engine API URLs "
name : " el " . } : seq [ EngineApiUrlConfigValue ]
noEl * {.
defaultValue : false
desc : " Don ' t use an EL. The node will remain optimistically synced and won ' t be able to perform validator duties "
name : " no-el " . } : bool
2022-07-14 04:07:40 +00:00
jwtSecret * {.
2022-08-02 12:23:03 +00:00
desc : " A file containing the hex-encoded 256 bit secret key to be used for verifying/generating JWT tokens "
2023-03-05 01:40:21 +00:00
name : " jwt-secret " . } : Option [ InputFile ]
2022-07-14 04:07:40 +00:00
2023-08-24 14:04:19 +00:00
bandwidthEstimate * {.
hidden
desc : " Bandwidth estimate for the node (bits per second) "
name : " debug-bandwidth-estimate " . } : Option [ Natural ]
2022-05-31 10:45:37 +00:00
# Testing
stopAtEpoch * {.
hidden
desc : " The wall-time epoch at which to exit the program. (for testing purposes) "
defaultValue : 0
2022-06-15 18:04:07 +00:00
name : " stop-at-epoch " . } : uint64
2022-07-14 04:07:40 +00:00
2022-11-30 03:45:03 +00:00
template databaseDir * ( config : LightClientConf ) : string =
config . dataDir . databaseDir
2022-07-14 04:07:40 +00:00
template loadJwtSecret * (
rng : var HmacDrbgContext ,
config : LightClientConf ,
allowCreate : bool ) : Option [ seq [ byte ] ] =
rng . loadJwtSecret ( string ( config . dataDir ) , config . jwtSecret , allowCreate )
2023-03-05 01:40:21 +00:00
proc engineApiUrls * ( config : LightClientConf ) : seq [ EngineApiUrl ] =
let elUrls = if config . noEl :
return newSeq [ EngineApiUrl ] ( )
elif config . elUrls . len = = 0 and config . web3Urls . len = = 0 :
@ [ defaultEngineApiUrl ]
else :
config . elUrls
( elUrls & config . web3Urls ) . toFinalEngineApiUrls ( config . jwtSecret )