2018-04-27 08:53:53 +00:00
|
|
|
# Nimbus
|
2019-01-06 22:06:26 +00:00
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
2018-04-27 08:53:53 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
2018-10-16 00:10:01 +00:00
|
|
|
import
|
2020-07-23 07:54:32 +00:00
|
|
|
parseopt, strutils, macros, os, times, json, tables, stew/[byteutils],
|
2019-04-17 01:56:28 +00:00
|
|
|
chronos, eth/[keys, common, p2p, net/nat], chronicles, nimcrypto/hash,
|
2021-06-01 10:54:13 +00:00
|
|
|
eth/p2p/bootnodes, ./db/select_backend, eth/keys, ./chain_config, ./forks
|
2018-04-27 08:53:53 +00:00
|
|
|
|
2019-01-15 15:25:14 +00:00
|
|
|
const
|
2018-04-27 08:53:53 +00:00
|
|
|
NimbusName* = "Nimbus"
|
|
|
|
## project name string
|
2018-05-02 15:01:10 +00:00
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
NimbusMajor*: int = 0
|
|
|
|
## is the major number of Nimbus' version.
|
|
|
|
|
|
|
|
NimbusMinor*: int = 0
|
|
|
|
## is the minor number of Nimbus' version.
|
|
|
|
|
|
|
|
NimbusPatch*: int = 1
|
|
|
|
## is the patch number of Nimbus' version.
|
|
|
|
|
|
|
|
NimbusVersion* = $NimbusMajor & "." & $NimbusMinor & "." & $NimbusPatch
|
|
|
|
## is the version of Nimbus as a string.
|
|
|
|
|
2019-01-15 15:25:14 +00:00
|
|
|
NimbusIdent* = "$1/$2 ($3/$4)" % [NimbusName, NimbusVersion, hostCPU, hostOS]
|
|
|
|
## project ident name for networking services
|
|
|
|
|
2020-07-22 11:40:12 +00:00
|
|
|
GitRevision = staticExec("git rev-parse --short HEAD").replace("\n") # remove CR
|
2020-04-15 22:21:58 +00:00
|
|
|
|
|
|
|
NimVersion = staticExec("nim --version")
|
2019-01-15 15:25:14 +00:00
|
|
|
|
2019-11-10 17:44:40 +00:00
|
|
|
let
|
|
|
|
NimbusCopyright* = "Copyright (c) 2018-" & $(now().utc.year) & " Status Research & Development GmbH"
|
2020-04-15 22:21:58 +00:00
|
|
|
NimbusHeader* = "$# Version $# [$#: $#, $#, $#]\p$#\p\p$#\p" %
|
|
|
|
[NimbusName, NimbusVersion, hostOS, hostCPU, nimbus_db_backend, GitRevision, NimbusCopyright, NimVersion]
|
2018-06-20 17:27:32 +00:00
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
type
|
|
|
|
ConfigStatus* = enum
|
|
|
|
## Configuration status flags
|
2018-06-20 17:27:32 +00:00
|
|
|
Success, ## Success
|
|
|
|
EmptyOption, ## No options in category
|
|
|
|
ErrorUnknownOption, ## Unknown option in command line found
|
|
|
|
ErrorParseOption, ## Error in parsing command line option
|
|
|
|
ErrorIncorrectOption, ## Option has incorrect value
|
|
|
|
Error ## Unspecified error
|
2018-04-27 08:53:53 +00:00
|
|
|
|
|
|
|
RpcFlags* {.pure.} = enum
|
|
|
|
## RPC flags
|
2018-06-20 17:27:32 +00:00
|
|
|
Enabled ## RPC enabled
|
2018-11-22 06:40:09 +00:00
|
|
|
Eth ## enable eth_ set of RPC API
|
|
|
|
Debug ## enable debug_ set of RPC API
|
2018-04-27 08:53:53 +00:00
|
|
|
|
2019-04-23 13:49:49 +00:00
|
|
|
ProtocolFlags* {.pure.} = enum
|
|
|
|
## Protocol flags
|
|
|
|
Eth ## enable eth subprotocol
|
|
|
|
Les ## enable les subprotocol
|
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
RpcConfiguration* = object
|
|
|
|
## JSON-RPC configuration object
|
2018-06-20 17:27:32 +00:00
|
|
|
flags*: set[RpcFlags] ## RPC flags
|
|
|
|
binds*: seq[TransportAddress] ## RPC bind address
|
2018-04-27 08:53:53 +00:00
|
|
|
|
2021-04-24 03:58:05 +00:00
|
|
|
GraphqlConfiguration* = object
|
|
|
|
enabled*: bool
|
|
|
|
address*: TransportAddress
|
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
NetworkFlags* = enum
|
|
|
|
## Ethereum network flags
|
2021-05-20 06:01:57 +00:00
|
|
|
NoDiscover ## Peer discovery disabled
|
|
|
|
V5Discover ## Dicovery V5 enabled
|
|
|
|
NetworkIdSet ## prevent CustomNetwork replacement
|
2018-04-27 08:53:53 +00:00
|
|
|
|
|
|
|
DebugFlags* {.pure.} = enum
|
|
|
|
## Debug selection flags
|
2018-06-20 17:27:32 +00:00
|
|
|
Enabled, ## Debugging enabled
|
|
|
|
Test1, ## Test1 enabled
|
|
|
|
Test2, ## Test2 enabled
|
|
|
|
Test3 ## Test3 enabled
|
2018-04-27 08:53:53 +00:00
|
|
|
|
|
|
|
NetConfiguration* = object
|
|
|
|
## Network configuration object
|
2018-06-20 17:27:32 +00:00
|
|
|
flags*: set[NetworkFlags] ## Network flags
|
|
|
|
bootNodes*: seq[ENode] ## List of bootnodes
|
2019-04-23 13:49:49 +00:00
|
|
|
staticNodes*: seq[ENode] ## List of static nodes to connect to
|
2021-05-20 06:37:24 +00:00
|
|
|
customBootNodes*: seq[ENode]
|
2018-06-20 17:27:32 +00:00
|
|
|
bindPort*: uint16 ## Main TCP bind port
|
|
|
|
discPort*: uint16 ## Discovery UDP bind port
|
2021-02-13 09:32:48 +00:00
|
|
|
metricsServer*: bool ## Enable metrics server
|
2019-07-16 10:43:05 +00:00
|
|
|
metricsServerPort*: uint16 ## metrics HTTP server port
|
2018-06-20 17:27:32 +00:00
|
|
|
maxPeers*: int ## Maximum allowed number of peers
|
|
|
|
maxPendingPeers*: int ## Maximum allowed pending peers
|
2021-02-13 09:32:48 +00:00
|
|
|
networkId*: NetworkId ## Network ID as integer
|
2018-06-20 17:27:32 +00:00
|
|
|
ident*: string ## Server ident name string
|
|
|
|
nodeKey*: PrivateKey ## Server private key
|
2019-04-17 01:56:28 +00:00
|
|
|
nat*: NatStrategy ## NAT strategy
|
|
|
|
externalIP*: string ## user-provided external IP
|
2019-04-23 13:49:49 +00:00
|
|
|
protocols*: set[ProtocolFlags]## Enabled subprotocols
|
2018-04-27 08:53:53 +00:00
|
|
|
|
|
|
|
DebugConfiguration* = object
|
|
|
|
## Debug configuration object
|
2018-06-20 17:27:32 +00:00
|
|
|
flags*: set[DebugFlags] ## Debug flags
|
2019-03-20 13:41:25 +00:00
|
|
|
logLevel*: LogLevel ## Log level
|
|
|
|
logFile*: string ## Log file
|
2019-07-16 10:43:05 +00:00
|
|
|
logMetrics*: bool ## Enable metrics logging
|
|
|
|
logMetricsInterval*: int ## Metrics logging interval
|
2018-04-27 08:53:53 +00:00
|
|
|
|
2018-11-30 03:03:30 +00:00
|
|
|
PruneMode* {.pure.} = enum
|
|
|
|
Full
|
|
|
|
Archive
|
|
|
|
|
2020-07-23 07:54:32 +00:00
|
|
|
NimbusAccount* = object
|
|
|
|
privateKey*: PrivateKey
|
|
|
|
keystore*: JsonNode
|
|
|
|
unlocked*: bool
|
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
NimbusConfiguration* = ref object
|
|
|
|
## Main Nimbus configuration object
|
2018-09-24 22:25:17 +00:00
|
|
|
dataDir*: string
|
2020-07-23 07:54:32 +00:00
|
|
|
keyStore*: string
|
2018-11-30 03:03:30 +00:00
|
|
|
prune*: PruneMode
|
2021-04-24 03:58:05 +00:00
|
|
|
graphql*: GraphqlConfiguration
|
2018-06-20 17:27:32 +00:00
|
|
|
rpc*: RpcConfiguration ## JSON-RPC configuration
|
2021-07-31 12:27:13 +00:00
|
|
|
ws*: RpcConfiguration ## Websocket JSON-RPC configuration
|
2018-06-20 17:27:32 +00:00
|
|
|
net*: NetConfiguration ## Network configuration
|
|
|
|
debug*: DebugConfiguration ## Debug configuration
|
2021-05-13 09:01:58 +00:00
|
|
|
customGenesis*: CustomGenesis ## Custom Genesis Configuration
|
2020-07-20 17:16:59 +00:00
|
|
|
# You should only create one instance of the RNG per application / library
|
|
|
|
# Ref is used so that it can be shared between components
|
|
|
|
rng*: ref BrHmacDrbgContext
|
2020-07-23 07:54:32 +00:00
|
|
|
accounts*: Table[EthAddress, NimbusAccount]
|
2021-03-18 15:05:15 +00:00
|
|
|
importFile*: string
|
2021-07-30 14:06:51 +00:00
|
|
|
verifyFromOk*: bool ## activate `verifyFrom` setting
|
|
|
|
verifyFrom*: uint64 ## verification start block, 0 for disable
|
2021-07-31 12:16:30 +00:00
|
|
|
cliquePeriod*: int ## Enables clique support, 0 for disable
|
|
|
|
engineSigner*: EthAddress ## Miner account
|
2020-01-13 18:35:40 +00:00
|
|
|
|
2021-05-20 06:01:57 +00:00
|
|
|
const
|
|
|
|
# these are public network id
|
|
|
|
CustomNet* = 0.NetworkId
|
|
|
|
MainNet* = 1.NetworkId
|
|
|
|
# No longer used: MordenNet = 2
|
|
|
|
RopstenNet* = 3.NetworkId
|
|
|
|
RinkebyNet* = 4.NetworkId
|
|
|
|
GoerliNet* = 5.NetworkId
|
|
|
|
KovanNet* = 42.NetworkId
|
|
|
|
|
2018-11-22 06:40:09 +00:00
|
|
|
const
|
2021-06-01 13:15:19 +00:00
|
|
|
defaultRpcApi = {RpcFlags.Eth}
|
|
|
|
defaultProtocols = {ProtocolFlags.Eth}
|
2019-03-20 13:41:25 +00:00
|
|
|
defaultLogLevel = LogLevel.WARN
|
2019-07-30 09:00:55 +00:00
|
|
|
defaultNetwork = MainNet
|
2018-11-22 06:40:09 +00:00
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
var nimbusConfig {.threadvar.}: NimbusConfiguration
|
|
|
|
|
2018-06-20 17:27:32 +00:00
|
|
|
proc getConfiguration*(): NimbusConfiguration {.gcsafe.}
|
2018-04-27 08:53:53 +00:00
|
|
|
|
2021-03-18 15:05:15 +00:00
|
|
|
proc `$`*(c: ChainId): string =
|
|
|
|
$(c.int)
|
|
|
|
|
2020-04-12 10:07:09 +00:00
|
|
|
proc toFork*(c: ChainConfig, number: BlockNumber): Fork =
|
2021-06-28 02:01:18 +00:00
|
|
|
if number >= c.londonBlock: FkLondon
|
|
|
|
elif number >= c.berlinBlock: FkBerlin
|
2020-11-19 04:59:53 +00:00
|
|
|
elif number >= c.istanbulBlock: FkIstanbul
|
2020-04-12 10:07:09 +00:00
|
|
|
elif number >= c.petersburgBlock: FkPetersburg
|
|
|
|
elif number >= c.constantinopleBlock: FkConstantinople
|
|
|
|
elif number >= c.byzantiumBlock: FkByzantium
|
|
|
|
elif number >= c.eip158Block: FkSpurious
|
|
|
|
elif number >= c.eip150Block: FkTangerine
|
|
|
|
elif number >= c.homesteadBlock: FkHomestead
|
|
|
|
else: FkFrontier
|
2020-04-11 09:59:46 +00:00
|
|
|
|
2021-05-20 06:01:57 +00:00
|
|
|
proc chainConfig*(id: NetworkId): ChainConfig =
|
2021-02-13 09:32:48 +00:00
|
|
|
# For some public networks, NetworkId and ChainId value are identical
|
|
|
|
# but that is not always the case
|
2021-03-18 15:05:15 +00:00
|
|
|
|
2018-08-01 12:50:44 +00:00
|
|
|
result = case id
|
|
|
|
of MainNet:
|
|
|
|
ChainConfig(
|
2021-05-24 07:35:47 +00:00
|
|
|
poaEngine: false, # TODO: use real engine conf: PoW
|
2021-02-13 09:32:48 +00:00
|
|
|
chainId: MainNet.ChainId,
|
2020-04-11 09:59:46 +00:00
|
|
|
homesteadBlock: 1_150_000.toBlockNumber, # 14/03/2016 20:49:53
|
|
|
|
daoForkBlock: 1_920_000.toBlockNumber,
|
2018-08-01 12:50:44 +00:00
|
|
|
daoForkSupport: true,
|
2020-04-11 09:59:46 +00:00
|
|
|
eip150Block: 2_463_000.toBlockNumber, # 18/10/2016 17:19:31
|
2018-08-01 12:50:44 +00:00
|
|
|
eip150Hash: toDigest("2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
|
2020-04-11 09:59:46 +00:00
|
|
|
eip155Block: 2_675_000.toBlockNumber, # 22/11/2016 18:15:44
|
|
|
|
eip158Block: 2_675_000.toBlockNumber,
|
|
|
|
byzantiumBlock: 4_370_000.toBlockNumber, # 16/10/2017 09:22:11
|
|
|
|
constantinopleBlock: 7_280_000.toBlockNumber, # Never Occured in MainNet
|
|
|
|
petersburgBlock:7_280_000.toBlockNumber, # 28/02/2019 07:52:04
|
|
|
|
istanbulBlock: 9_069_000.toBlockNumber, # 08/12/2019 12:25:09
|
2020-11-19 04:59:53 +00:00
|
|
|
muirGlacierBlock: 9_200_000.toBlockNumber, # 02/01/2020 08:30:49
|
2021-06-28 02:01:18 +00:00
|
|
|
berlinBlock: 12_244_000.toBlockNumber, # 15/04/2021 10:07:03
|
|
|
|
londonBlock: high(BlockNumber)
|
2018-08-01 12:50:44 +00:00
|
|
|
)
|
|
|
|
of RopstenNet:
|
|
|
|
ChainConfig(
|
2021-05-24 07:35:47 +00:00
|
|
|
poaEngine: false, # TODO: use real engine conf: PoW
|
2021-02-13 09:32:48 +00:00
|
|
|
chainId: RopstenNet.ChainId,
|
2019-07-10 07:40:46 +00:00
|
|
|
homesteadBlock: 0.toBlockNumber,
|
2020-04-08 09:53:26 +00:00
|
|
|
daoForkSupport: false,
|
2019-07-10 07:40:46 +00:00
|
|
|
eip150Block: 0.toBlockNumber,
|
2018-08-01 12:50:44 +00:00
|
|
|
eip150Hash: toDigest("41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
|
2019-07-10 07:40:46 +00:00
|
|
|
eip155Block: 10.toBlockNumber,
|
|
|
|
eip158Block: 10.toBlockNumber,
|
2020-04-11 09:59:46 +00:00
|
|
|
byzantiumBlock: 1_700_000.toBlockNumber,
|
|
|
|
constantinopleBlock: 4_230_000.toBlockNumber,
|
|
|
|
petersburgBlock:4_939_394.toBlockNumber,
|
|
|
|
istanbulBlock: 6_485_846.toBlockNumber,
|
2020-11-19 04:59:53 +00:00
|
|
|
muirGlacierBlock: 7_117_117.toBlockNumber,
|
2021-06-28 02:01:18 +00:00
|
|
|
berlinBlock: 9_812_189.toBlockNumber,
|
|
|
|
londonBlock: high(BlockNumber)
|
2018-08-01 12:50:44 +00:00
|
|
|
)
|
|
|
|
of RinkebyNet:
|
|
|
|
ChainConfig(
|
2021-05-24 07:35:47 +00:00
|
|
|
poaEngine: true, # TODO: use real engine conf: PoA
|
2021-02-13 09:32:48 +00:00
|
|
|
chainId: RinkebyNet.ChainId,
|
2019-07-10 07:40:46 +00:00
|
|
|
homesteadBlock: 1.toBlockNumber,
|
2020-04-08 09:53:26 +00:00
|
|
|
daoForkSupport: false,
|
2019-07-10 07:40:46 +00:00
|
|
|
eip150Block: 2.toBlockNumber,
|
2018-08-01 12:50:44 +00:00
|
|
|
eip150Hash: toDigest("9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
|
2019-07-10 07:40:46 +00:00
|
|
|
eip155Block: 3.toBlockNumber,
|
|
|
|
eip158Block: 3.toBlockNumber,
|
2020-04-11 09:59:46 +00:00
|
|
|
byzantiumBlock: 1_035_301.toBlockNumber,
|
|
|
|
constantinopleBlock: 3_660_663.toBlockNumber,
|
|
|
|
petersburgBlock:4_321_234.toBlockNumber,
|
|
|
|
istanbulBlock: 5_435_345.toBlockNumber,
|
2021-05-12 10:24:27 +00:00
|
|
|
muirGlacierBlock: 8_290_928.toBlockNumber, # never occured in rinkeby network
|
2021-06-28 02:01:18 +00:00
|
|
|
berlinBlock: 8_290_928.toBlockNumber,
|
|
|
|
londonBlock: high(BlockNumber)
|
2018-08-01 12:50:44 +00:00
|
|
|
)
|
2020-04-09 10:06:08 +00:00
|
|
|
of GoerliNet:
|
|
|
|
ChainConfig(
|
2021-05-24 07:35:47 +00:00
|
|
|
poaEngine: true, # TODO: use real engine conf: PoA
|
2021-02-13 09:32:48 +00:00
|
|
|
chainId: GoerliNet.ChainId,
|
2020-04-09 10:06:08 +00:00
|
|
|
homesteadBlock: 0.toBlockNumber,
|
|
|
|
daoForkSupport: false,
|
|
|
|
eip150Block: 0.toBlockNumber,
|
|
|
|
eip150Hash: toDigest("0000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
eip155Block: 0.toBlockNumber,
|
|
|
|
eip158Block: 0.toBlockNumber,
|
|
|
|
byzantiumBlock: 0.toBlockNumber,
|
2020-04-11 09:59:46 +00:00
|
|
|
constantinopleBlock: 0.toBlockNumber,
|
|
|
|
petersburgBlock: 0.toBlockNumber,
|
|
|
|
istanbulBlock: 1_561_651.toBlockNumber,
|
2021-05-12 10:24:27 +00:00
|
|
|
muirGlacierBlock: 4_460_644.toBlockNumber, # never occured in goerli network
|
2021-06-28 02:01:18 +00:00
|
|
|
berlinBlock: 4_460_644.toBlockNumber,
|
|
|
|
londonBlock: high(BlockNumber)
|
2020-04-09 10:06:08 +00:00
|
|
|
)
|
2021-05-20 06:01:57 +00:00
|
|
|
else:
|
|
|
|
# everything else will use CustomNet config
|
2021-05-13 09:01:58 +00:00
|
|
|
let conf = getConfiguration()
|
|
|
|
trace "Custom genesis block configuration loaded", conf=conf.customGenesis.config
|
|
|
|
conf.customGenesis.config
|
2018-08-01 12:50:44 +00:00
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
proc processList(v: string, o: var seq[string]) =
|
2018-05-01 00:47:35 +00:00
|
|
|
## Process comma-separated list of strings.
|
2018-04-27 08:53:53 +00:00
|
|
|
if len(v) > 0:
|
|
|
|
for n in v.split({' ', ','}):
|
|
|
|
if len(n) > 0:
|
|
|
|
o.add(n)
|
|
|
|
|
2019-01-08 11:29:56 +00:00
|
|
|
proc processInteger*(v: string, o: var int): ConfigStatus =
|
2018-05-01 00:47:35 +00:00
|
|
|
## Convert string to integer.
|
2018-04-27 08:53:53 +00:00
|
|
|
try:
|
|
|
|
o = parseInt(v)
|
2018-04-30 07:24:51 +00:00
|
|
|
result = Success
|
2019-12-04 12:43:18 +00:00
|
|
|
except ValueError:
|
2018-04-30 07:24:51 +00:00
|
|
|
result = ErrorParseOption
|
|
|
|
|
2021-07-30 14:06:51 +00:00
|
|
|
proc processUInt64*(v: string, o: var uint64): ConfigStatus =
|
|
|
|
## Convert string to integer.
|
|
|
|
try:
|
|
|
|
o = parseBiggestUInt(v).uint64
|
|
|
|
result = Success
|
|
|
|
except ValueError:
|
|
|
|
result = ErrorParseOption
|
|
|
|
|
2019-04-23 13:49:49 +00:00
|
|
|
proc processFloat*(v: string, o: var float): ConfigStatus =
|
|
|
|
## Convert string to float.
|
|
|
|
try:
|
|
|
|
o = parseFloat(v)
|
|
|
|
result = Success
|
2019-12-04 12:43:18 +00:00
|
|
|
except ValueError:
|
2019-04-23 13:49:49 +00:00
|
|
|
result = ErrorParseOption
|
|
|
|
|
2021-04-24 03:58:05 +00:00
|
|
|
proc processAddressPort(addrStr: string, ta: var TransportAddress): ConfigStatus =
|
|
|
|
try:
|
|
|
|
ta = initTAddress(addrStr)
|
|
|
|
return Success
|
|
|
|
except CatchableError:
|
|
|
|
return ErrorParseOption
|
|
|
|
|
2018-06-20 17:27:32 +00:00
|
|
|
proc processAddressPortsList(v: string,
|
|
|
|
o: var seq[TransportAddress]): ConfigStatus =
|
|
|
|
## Convert <hostname:port>;...;<hostname:port> to list of `TransportAddress`.
|
|
|
|
var list = newSeq[string]()
|
2018-05-01 00:47:35 +00:00
|
|
|
processList(v, list)
|
|
|
|
for item in list:
|
2021-04-24 03:58:05 +00:00
|
|
|
var ta: TransportAddress
|
|
|
|
if processAddressPort(item, ta) == Success:
|
|
|
|
o.add ta
|
2018-06-20 17:27:32 +00:00
|
|
|
else:
|
2021-04-24 03:58:05 +00:00
|
|
|
return ErrorParseOption
|
2018-06-20 17:27:32 +00:00
|
|
|
result = Success
|
2018-05-01 00:47:35 +00:00
|
|
|
|
2018-11-22 06:40:09 +00:00
|
|
|
proc processRpcApiList(v: string, flags: var set[RpcFlags]): ConfigStatus =
|
|
|
|
var list = newSeq[string]()
|
|
|
|
processList(v, list)
|
|
|
|
result = Success
|
|
|
|
for item in list:
|
|
|
|
case item.toLowerAscii()
|
|
|
|
of "eth": flags.incl RpcFlags.Eth
|
|
|
|
of "debug": flags.incl RpcFlags.Debug
|
|
|
|
else:
|
|
|
|
warn "unknown rpc api", name = item
|
|
|
|
result = ErrorIncorrectOption
|
|
|
|
|
2019-04-23 13:49:49 +00:00
|
|
|
proc processProtocolList(v: string, flags: var set[ProtocolFlags]): ConfigStatus =
|
|
|
|
var list = newSeq[string]()
|
|
|
|
processList(v, list)
|
|
|
|
result = Success
|
|
|
|
for item in list:
|
|
|
|
case item.toLowerAscii()
|
|
|
|
of "eth": flags.incl ProtocolFlags.Eth
|
|
|
|
of "les": flags.incl ProtocolFlags.Les
|
|
|
|
else:
|
|
|
|
warn "unknown protocol", name = item
|
|
|
|
result = ErrorIncorrectOption
|
|
|
|
|
2018-05-01 00:47:35 +00:00
|
|
|
proc processENode(v: string, o: var ENode): ConfigStatus =
|
|
|
|
## Convert string to ENode.
|
2020-04-07 09:53:50 +00:00
|
|
|
let res = ENode.fromString(v)
|
|
|
|
if res.isOk:
|
|
|
|
o = res[]
|
2018-05-01 00:47:35 +00:00
|
|
|
result = Success
|
|
|
|
else:
|
|
|
|
result = ErrorParseOption
|
|
|
|
|
|
|
|
proc processENodesList(v: string, o: var seq[ENode]): ConfigStatus =
|
|
|
|
## Convert comma-separated list of strings to list of ENode.
|
|
|
|
var
|
|
|
|
node: ENode
|
|
|
|
list = newSeq[string]()
|
|
|
|
processList(v, list)
|
|
|
|
for item in list:
|
|
|
|
result = processENode(item, node)
|
|
|
|
if result == Success:
|
|
|
|
o.add(node)
|
|
|
|
else:
|
|
|
|
break
|
2018-04-30 07:24:51 +00:00
|
|
|
|
2018-05-02 15:01:10 +00:00
|
|
|
proc processPrivateKey(v: string, o: var PrivateKey): ConfigStatus =
|
|
|
|
## Convert hexadecimal string to private key object.
|
2020-04-05 13:12:48 +00:00
|
|
|
let seckey = PrivateKey.fromHex(v)
|
|
|
|
if seckey.isOk():
|
|
|
|
o = seckey[]
|
|
|
|
return Success
|
|
|
|
|
|
|
|
result = ErrorParseOption
|
2018-05-02 15:01:10 +00:00
|
|
|
|
2018-11-30 03:03:30 +00:00
|
|
|
proc processPruneList(v: string, flags: var PruneMode): ConfigStatus =
|
|
|
|
var list = newSeq[string]()
|
|
|
|
processList(v, list)
|
|
|
|
result = Success
|
|
|
|
for item in list:
|
|
|
|
case item.toLowerAscii()
|
|
|
|
of "full": flags = PruneMode.Full
|
|
|
|
of "archive": flags = PruneMode.Archive
|
|
|
|
else:
|
|
|
|
warn "unknown prune flags", name = item
|
|
|
|
result = ErrorIncorrectOption
|
|
|
|
|
2021-07-31 12:16:30 +00:00
|
|
|
proc processEthAddress(value: string, address: var EthAddress): ConfigStatus =
|
|
|
|
try:
|
|
|
|
address = hexToByteArray[20](value)
|
|
|
|
return Success
|
|
|
|
except CatchableError:
|
|
|
|
return ErrorParseOption
|
|
|
|
|
|
|
|
proc importPrivateKey(conf: NimbusConfiguration, fileName: string): ConfigStatus =
|
|
|
|
|
|
|
|
try:
|
|
|
|
let pkhex = readFile(fileName)
|
|
|
|
let res = PrivateKey.fromHex(pkhex)
|
|
|
|
if res.isErr:
|
|
|
|
error "not a valid private key, expect 32 bytes hex"
|
|
|
|
return ErrorParseOption
|
|
|
|
|
|
|
|
let seckey = res.get()
|
|
|
|
let acc = seckey.toPublicKey().toCanonicalAddress()
|
|
|
|
|
|
|
|
conf.accounts[acc] = NimbusAccount(
|
|
|
|
privateKey: seckey,
|
|
|
|
unlocked: true
|
|
|
|
)
|
|
|
|
|
|
|
|
except CatchableError:
|
|
|
|
return ErrorParseOption
|
|
|
|
|
2018-09-24 22:25:17 +00:00
|
|
|
proc processEthArguments(key, value: string): ConfigStatus =
|
|
|
|
result = Success
|
|
|
|
let config = getConfiguration()
|
|
|
|
case key.toLowerAscii()
|
2020-07-23 07:54:32 +00:00
|
|
|
of "keystore":
|
|
|
|
config.keyStore = value
|
2018-12-28 08:24:57 +00:00
|
|
|
of "datadir":
|
2018-09-24 22:25:17 +00:00
|
|
|
config.dataDir = value
|
2018-11-30 03:03:30 +00:00
|
|
|
of "prune":
|
|
|
|
result = processPruneList(value, config.prune)
|
2021-03-18 15:05:15 +00:00
|
|
|
of "import":
|
|
|
|
config.importFile = value
|
2021-07-30 14:06:51 +00:00
|
|
|
of "verifyfrom":
|
|
|
|
var res = 0u64
|
|
|
|
result = processUInt64(value, res)
|
|
|
|
config.verifyFrom = uint64(result)
|
|
|
|
config.verifyFromOk = true
|
2021-07-31 12:16:30 +00:00
|
|
|
of "clique-period":
|
|
|
|
result = processInteger(value, config.cliquePeriod)
|
|
|
|
of "engine-signer":
|
|
|
|
result = processEthAddress(value, config.engineSigner)
|
|
|
|
of "import-key":
|
|
|
|
result = config.importPrivateKey(value)
|
2018-09-24 22:25:17 +00:00
|
|
|
else:
|
|
|
|
result = EmptyOption
|
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
proc processRpcArguments(key, value: string): ConfigStatus =
|
|
|
|
## Processes only `RPC` related command line options
|
|
|
|
result = Success
|
|
|
|
let config = getConfiguration()
|
|
|
|
let skey = key.toLowerAscii()
|
|
|
|
if skey == "rpc":
|
2018-11-22 06:40:09 +00:00
|
|
|
if RpcFlags.Enabled notin config.rpc.flags:
|
|
|
|
config.rpc.flags.incl(RpcFlags.Enabled)
|
|
|
|
config.rpc.flags.incl(defaultRpcApi)
|
2018-04-27 08:53:53 +00:00
|
|
|
elif skey == "rpcbind":
|
2018-06-20 17:27:32 +00:00
|
|
|
config.rpc.binds.setLen(0)
|
|
|
|
result = processAddressPortsList(value, config.rpc.binds)
|
2018-11-22 06:40:09 +00:00
|
|
|
elif skey == "rpcapi":
|
|
|
|
if RpcFlags.Enabled in config.rpc.flags:
|
|
|
|
config.rpc.flags.excl(defaultRpcApi)
|
|
|
|
else:
|
|
|
|
config.rpc.flags.incl(RpcFlags.Enabled)
|
|
|
|
result = processRpcApiList(value, config.rpc.flags)
|
2018-04-27 08:53:53 +00:00
|
|
|
else:
|
|
|
|
result = EmptyOption
|
|
|
|
|
2021-04-24 03:58:05 +00:00
|
|
|
proc processGraphqlArguments(key, value: string): ConfigStatus =
|
|
|
|
## Processes only `Graphql` related command line options
|
|
|
|
result = Success
|
|
|
|
let conf = getConfiguration()
|
|
|
|
case key.toLowerAscii()
|
|
|
|
of "graphql":
|
|
|
|
conf.graphql.enabled = true
|
|
|
|
of "graphqlbind":
|
|
|
|
result = processAddressPort(value, conf.graphql.address)
|
|
|
|
else:
|
|
|
|
result = EmptyOption
|
|
|
|
|
2021-07-31 12:27:13 +00:00
|
|
|
proc processWsArguments(key, value: string): ConfigStatus =
|
|
|
|
## Processes only `Websocket RPC` related command line options
|
|
|
|
result = Success
|
|
|
|
let config = getConfiguration()
|
|
|
|
let skey = key.toLowerAscii()
|
|
|
|
if skey == "ws":
|
|
|
|
if RpcFlags.Enabled notin config.ws.flags:
|
|
|
|
config.ws.flags.incl(RpcFlags.Enabled)
|
|
|
|
config.ws.flags.incl(defaultRpcApi)
|
|
|
|
elif skey == "wsbind":
|
|
|
|
config.ws.binds.setLen(0)
|
|
|
|
result = processAddressPortsList(value, config.ws.binds)
|
|
|
|
elif skey == "wsapi":
|
|
|
|
if RpcFlags.Enabled in config.ws.flags:
|
|
|
|
config.ws.flags.excl(defaultRpcApi)
|
|
|
|
else:
|
|
|
|
config.ws.flags.incl(RpcFlags.Enabled)
|
|
|
|
result = processRpcApiList(value, config.ws.flags)
|
|
|
|
else:
|
|
|
|
result = EmptyOption
|
|
|
|
|
2018-08-01 12:50:44 +00:00
|
|
|
proc setBootnodes(onodes: var seq[ENode], nodeUris: openarray[string]) =
|
2018-06-20 17:27:32 +00:00
|
|
|
var node: ENode
|
2018-08-01 12:50:44 +00:00
|
|
|
onodes = newSeqOfCap[ENode](nodeUris.len)
|
|
|
|
for item in nodeUris:
|
2018-06-20 17:27:32 +00:00
|
|
|
doAssert(processENode(item, node) == Success)
|
2018-08-01 12:50:44 +00:00
|
|
|
onodes.add(node)
|
2018-06-20 17:27:32 +00:00
|
|
|
|
2021-05-20 06:37:24 +00:00
|
|
|
|
2021-05-20 06:01:57 +00:00
|
|
|
proc setNetwork(conf: var NetConfiguration, id: NetworkId) =
|
2018-06-20 17:27:32 +00:00
|
|
|
## Set network id and default network bootnodes
|
2021-05-20 06:01:57 +00:00
|
|
|
conf.networkId = id
|
2018-08-01 12:50:44 +00:00
|
|
|
case id
|
2018-06-20 17:27:32 +00:00
|
|
|
of MainNet:
|
|
|
|
conf.bootNodes.setBootnodes(MainnetBootnodes)
|
|
|
|
of RopstenNet:
|
|
|
|
conf.bootNodes.setBootnodes(RopstenBootnodes)
|
|
|
|
of RinkebyNet:
|
|
|
|
conf.bootNodes.setBootnodes(RinkebyBootnodes)
|
2020-04-09 10:06:08 +00:00
|
|
|
of GoerliNet:
|
|
|
|
conf.bootNodes.setBootnodes(GoerliBootnodes)
|
2018-06-20 17:27:32 +00:00
|
|
|
of KovanNet:
|
|
|
|
conf.bootNodes.setBootnodes(KovanBootnodes)
|
|
|
|
else:
|
2021-05-20 06:01:57 +00:00
|
|
|
# everything else will use bootnodes
|
|
|
|
# from --bootnodes switch
|
|
|
|
discard
|
2018-06-20 17:27:32 +00:00
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
proc processNetArguments(key, value: string): ConfigStatus =
|
|
|
|
## Processes only `Networking` related command line options
|
|
|
|
result = Success
|
|
|
|
let config = getConfiguration()
|
|
|
|
let skey = key.toLowerAscii()
|
|
|
|
if skey == "bootnodes":
|
2021-05-20 06:37:24 +00:00
|
|
|
result = processENodesList(value, config.net.customBootNodes)
|
2018-04-27 08:53:53 +00:00
|
|
|
elif skey == "bootnodesv4":
|
2021-05-20 06:37:24 +00:00
|
|
|
result = processENodesList(value, config.net.customBootNodes)
|
2018-04-27 08:53:53 +00:00
|
|
|
elif skey == "bootnodesv5":
|
2021-05-20 06:37:24 +00:00
|
|
|
result = processENodesList(value, config.net.customBootNodes)
|
2019-04-23 13:49:49 +00:00
|
|
|
elif skey == "staticnodes":
|
|
|
|
result = processENodesList(value, config.net.staticNodes)
|
2018-04-27 08:53:53 +00:00
|
|
|
elif skey == "testnet":
|
2018-06-20 17:27:32 +00:00
|
|
|
config.net.setNetwork(RopstenNet)
|
2018-04-27 08:53:53 +00:00
|
|
|
elif skey == "mainnet":
|
2018-06-20 17:27:32 +00:00
|
|
|
config.net.setNetwork(MainNet)
|
|
|
|
elif skey == "ropsten":
|
|
|
|
config.net.setNetwork(RopstenNet)
|
|
|
|
elif skey == "rinkeby":
|
|
|
|
config.net.setNetwork(RinkebyNet)
|
2020-04-09 10:06:08 +00:00
|
|
|
elif skey == "goerli":
|
|
|
|
config.net.setNetwork(GoerliNet)
|
2018-06-20 17:27:32 +00:00
|
|
|
elif skey == "kovan":
|
|
|
|
config.net.setNetwork(KovanNet)
|
2020-01-13 18:35:40 +00:00
|
|
|
elif skey == "customnetwork":
|
2021-05-13 09:01:58 +00:00
|
|
|
if not loadCustomGenesis(value, config.customGenesis):
|
|
|
|
result = Error
|
2021-05-20 06:01:57 +00:00
|
|
|
if NetworkIdSet notin config.net.flags:
|
|
|
|
# prevent clash with --networkid if it already set
|
|
|
|
# because any --networkid value that is not
|
|
|
|
# in the public network will also translated as
|
|
|
|
# CustomNetwork
|
|
|
|
config.net.networkId = CustomNet
|
2018-06-20 17:27:32 +00:00
|
|
|
elif skey == "networkid":
|
|
|
|
var res = 0
|
|
|
|
result = processInteger(value, res)
|
|
|
|
if result == Success:
|
2021-02-13 09:32:48 +00:00
|
|
|
config.net.setNetwork(NetworkId(result))
|
2021-05-20 06:01:57 +00:00
|
|
|
config.net.flags.incl NetworkIdSet
|
2018-04-27 08:53:53 +00:00
|
|
|
elif skey == "nodiscover":
|
|
|
|
config.net.flags.incl(NoDiscover)
|
|
|
|
elif skey == "v5discover":
|
|
|
|
config.net.flags.incl(V5Discover)
|
2021-05-20 06:37:24 +00:00
|
|
|
config.net.customBootNodes.setBootnodes(DiscoveryV5Bootnodes)
|
2018-04-27 08:53:53 +00:00
|
|
|
elif skey == "port":
|
|
|
|
var res = 0
|
|
|
|
result = processInteger(value, res)
|
|
|
|
if result == Success:
|
|
|
|
config.net.bindPort = uint16(res and 0xFFFF)
|
2018-05-02 15:01:10 +00:00
|
|
|
elif skey == "discport":
|
|
|
|
var res = 0
|
|
|
|
result = processInteger(value, res)
|
|
|
|
if result == Success:
|
|
|
|
config.net.discPort = uint16(res and 0xFFFF)
|
2021-04-27 07:18:26 +00:00
|
|
|
elif skey == "metrics":
|
2019-07-16 10:43:05 +00:00
|
|
|
config.net.metricsServer = true
|
2021-04-27 07:18:26 +00:00
|
|
|
elif skey == "metricsport":
|
2019-07-11 23:38:32 +00:00
|
|
|
var res = 0
|
|
|
|
result = processInteger(value, res)
|
|
|
|
if result == Success:
|
2019-07-16 10:43:05 +00:00
|
|
|
config.net.metricsServerPort = uint16(res and 0xFFFF)
|
2018-04-27 08:53:53 +00:00
|
|
|
elif skey == "maxpeers":
|
|
|
|
var res = 0
|
|
|
|
result = processInteger(value, res)
|
|
|
|
if result == Success:
|
|
|
|
config.net.maxPeers = res
|
|
|
|
elif skey == "maxpendpeers":
|
|
|
|
var res = 0
|
|
|
|
result = processInteger(value, res)
|
|
|
|
if result == Success:
|
|
|
|
config.net.maxPendingPeers = res
|
2018-05-02 15:01:10 +00:00
|
|
|
elif skey == "nodekey":
|
|
|
|
var res: PrivateKey
|
|
|
|
result = processPrivateKey(value, res)
|
|
|
|
if result == Success:
|
|
|
|
config.net.nodeKey = res
|
2018-06-20 17:27:32 +00:00
|
|
|
elif skey == "ident":
|
|
|
|
config.net.ident = value
|
2019-04-17 01:56:28 +00:00
|
|
|
elif skey == "nat":
|
|
|
|
case value.toLowerAscii:
|
|
|
|
of "any":
|
|
|
|
config.net.nat = NatAny
|
|
|
|
of "upnp":
|
|
|
|
config.net.nat = NatUpnp
|
|
|
|
of "pmp":
|
|
|
|
config.net.nat = NatPmp
|
|
|
|
of "none":
|
|
|
|
config.net.nat = NatNone
|
|
|
|
else:
|
|
|
|
if isIpAddress(value):
|
|
|
|
config.net.externalIP = value
|
|
|
|
config.net.nat = NatNone
|
|
|
|
else:
|
|
|
|
error "not a valid NAT mechanism, nor a valid IP address", value
|
|
|
|
result = ErrorParseOption
|
2019-04-23 13:49:49 +00:00
|
|
|
elif skey == "protocols":
|
|
|
|
config.net.protocols = {}
|
|
|
|
result = processProtocolList(value, config.net.protocols)
|
|
|
|
else:
|
|
|
|
result = EmptyOption
|
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
proc processDebugArguments(key, value: string): ConfigStatus =
|
|
|
|
## Processes only `Debug` related command line options
|
|
|
|
let config = getConfiguration()
|
|
|
|
result = Success
|
|
|
|
let skey = key.toLowerAscii()
|
|
|
|
if skey == "debug":
|
|
|
|
config.debug.flags.incl(DebugFlags.Enabled)
|
|
|
|
elif skey == "test":
|
|
|
|
var res = newSeq[string]()
|
|
|
|
processList(value, res)
|
|
|
|
for item in res:
|
|
|
|
if item == "test1":
|
|
|
|
config.debug.flags.incl(DebugFlags.Test1)
|
|
|
|
elif item == "test2":
|
|
|
|
config.debug.flags.incl(DebugFlags.Test2)
|
|
|
|
elif item == "test3":
|
|
|
|
config.debug.flags.incl(DebugFlags.Test3)
|
2019-03-20 13:41:25 +00:00
|
|
|
elif skey == "log-level":
|
|
|
|
try:
|
|
|
|
let logLevel = parseEnum[LogLevel](value)
|
|
|
|
if logLevel >= enabledLogLevel:
|
|
|
|
config.debug.logLevel = logLevel
|
|
|
|
else:
|
|
|
|
result = ErrorIncorrectOption
|
|
|
|
except ValueError:
|
|
|
|
result = ErrorIncorrectOption
|
|
|
|
elif skey == "log-file":
|
|
|
|
if len(value) == 0:
|
|
|
|
result = ErrorIncorrectOption
|
|
|
|
else:
|
|
|
|
config.debug.logFile = value
|
2019-07-16 10:43:05 +00:00
|
|
|
elif skey == "logmetrics":
|
|
|
|
config.debug.logMetrics = true
|
|
|
|
elif skey == "logmetricsinterval":
|
|
|
|
var res = 0
|
|
|
|
result = processInteger(value, res)
|
|
|
|
if result == Success:
|
|
|
|
config.debug.logMetricsInterval = res
|
2019-07-17 22:50:16 +00:00
|
|
|
else:
|
|
|
|
result = EmptyOption
|
2018-04-27 08:53:53 +00:00
|
|
|
|
|
|
|
proc dumpConfiguration*(): string =
|
|
|
|
## Dumps current configuration as string
|
|
|
|
let config = getConfiguration()
|
|
|
|
result = repr config
|
|
|
|
|
2019-03-20 13:41:25 +00:00
|
|
|
template processArgument(processor, key, value, msg: untyped) =
|
2018-06-20 17:27:32 +00:00
|
|
|
## Checks if arguments got processed successfully
|
2019-03-20 13:41:25 +00:00
|
|
|
var res = processor(string(key), string(value))
|
2018-04-27 08:53:53 +00:00
|
|
|
if res == Success:
|
2019-03-20 13:41:25 +00:00
|
|
|
result = res
|
2018-04-27 08:53:53 +00:00
|
|
|
continue
|
|
|
|
elif res == ErrorParseOption:
|
2019-03-20 13:41:25 +00:00
|
|
|
msg = "Error processing option '" & key & "' with value '" & value & "'."
|
2018-04-27 08:53:53 +00:00
|
|
|
result = res
|
|
|
|
break
|
2018-06-20 17:27:32 +00:00
|
|
|
elif res == ErrorIncorrectOption:
|
2019-03-20 13:41:25 +00:00
|
|
|
msg = "Incorrect value for option '" & key & "': '" & value & "'."
|
2018-06-20 17:27:32 +00:00
|
|
|
result = res
|
|
|
|
break
|
|
|
|
|
2019-01-08 11:29:56 +00:00
|
|
|
proc getDefaultDataDir*(): string =
|
|
|
|
when defined(windows):
|
2020-07-23 07:54:32 +00:00
|
|
|
"AppData" / "Roaming" / "Nimbus"
|
2019-01-08 11:29:56 +00:00
|
|
|
elif defined(macosx):
|
2020-07-23 07:54:32 +00:00
|
|
|
"Library" / "Application Support" / "Nimbus"
|
2019-01-08 11:29:56 +00:00
|
|
|
else:
|
2020-07-23 07:54:32 +00:00
|
|
|
".cache" / "nimbus"
|
|
|
|
|
|
|
|
proc getDefaultKeystoreDir*(): string =
|
|
|
|
getDefaultDataDir() / "keystore"
|
2019-01-08 11:29:56 +00:00
|
|
|
|
2018-06-20 17:27:32 +00:00
|
|
|
proc initConfiguration(): NimbusConfiguration =
|
|
|
|
## Allocates and initializes `NimbusConfiguration` with default values
|
|
|
|
result = new NimbusConfiguration
|
2020-07-20 17:16:59 +00:00
|
|
|
result.rng = newRng()
|
2020-07-23 07:54:32 +00:00
|
|
|
result.accounts = initTable[EthAddress, NimbusAccount]()
|
2020-07-20 17:16:59 +00:00
|
|
|
|
2021-04-24 03:58:05 +00:00
|
|
|
## Graphql defaults
|
|
|
|
result.graphql.enabled = false
|
|
|
|
result.graphql.address = initTAddress("127.0.0.1:8547")
|
|
|
|
|
2018-06-20 17:27:32 +00:00
|
|
|
## RPC defaults
|
|
|
|
result.rpc.flags = {}
|
|
|
|
result.rpc.binds = @[initTAddress("127.0.0.1:8545")]
|
|
|
|
|
2021-07-31 12:27:13 +00:00
|
|
|
## Websocket RPC defaults
|
|
|
|
result.ws.flags = {}
|
|
|
|
result.ws.binds = @[initTAddress("127.0.0.1:8546")]
|
|
|
|
|
2018-06-20 17:27:32 +00:00
|
|
|
## Network defaults
|
2021-05-20 06:01:57 +00:00
|
|
|
result.net.setNetwork(defaultNetwork)
|
2018-06-20 17:27:32 +00:00
|
|
|
result.net.maxPeers = 25
|
|
|
|
result.net.maxPendingPeers = 0
|
|
|
|
result.net.bindPort = 30303'u16
|
|
|
|
result.net.discPort = 30303'u16
|
2019-07-16 10:43:05 +00:00
|
|
|
result.net.metricsServer = false
|
|
|
|
result.net.metricsServerPort = 9093'u16
|
2019-01-15 15:25:14 +00:00
|
|
|
result.net.ident = NimbusIdent
|
2019-04-17 01:56:28 +00:00
|
|
|
result.net.nat = NatAny
|
2019-04-23 13:49:49 +00:00
|
|
|
result.net.protocols = defaultProtocols
|
2020-07-20 17:16:59 +00:00
|
|
|
result.net.nodekey = random(PrivateKey, result.rng[])
|
2018-04-27 08:53:53 +00:00
|
|
|
|
2020-07-23 07:54:32 +00:00
|
|
|
const
|
|
|
|
dataDir = getDefaultDataDir()
|
|
|
|
keystore = getDefaultKeystoreDir()
|
2018-09-24 22:25:17 +00:00
|
|
|
|
|
|
|
result.dataDir = getHomeDir() / dataDir
|
2020-07-23 07:54:32 +00:00
|
|
|
result.keystore = getHomeDir() / keystore
|
2018-11-30 03:03:30 +00:00
|
|
|
result.prune = PruneMode.Full
|
2018-09-24 22:25:17 +00:00
|
|
|
|
2018-06-20 17:27:32 +00:00
|
|
|
## Debug defaults
|
|
|
|
result.debug.flags = {}
|
2019-03-20 13:41:25 +00:00
|
|
|
result.debug.logLevel = defaultLogLevel
|
2019-07-16 10:43:05 +00:00
|
|
|
result.debug.logMetrics = false
|
|
|
|
result.debug.logMetricsInterval = 10
|
2018-06-20 17:27:32 +00:00
|
|
|
|
|
|
|
proc getConfiguration*(): NimbusConfiguration =
|
|
|
|
## Retreive current configuration object `NimbusConfiguration`.
|
|
|
|
if isNil(nimbusConfig):
|
|
|
|
nimbusConfig = initConfiguration()
|
|
|
|
result = nimbusConfig
|
2018-04-27 08:53:53 +00:00
|
|
|
|
|
|
|
proc getHelpString*(): string =
|
2019-03-20 13:41:25 +00:00
|
|
|
var logLevels: seq[string]
|
|
|
|
for level in LogLevel:
|
|
|
|
if level < enabledLogLevel:
|
|
|
|
continue
|
|
|
|
logLevels.add($level)
|
|
|
|
|
2018-06-20 17:27:32 +00:00
|
|
|
result = """
|
2018-04-27 08:53:53 +00:00
|
|
|
|
|
|
|
USAGE:
|
|
|
|
nimbus [options]
|
|
|
|
|
2018-05-02 15:01:10 +00:00
|
|
|
ETHEREUM OPTIONS:
|
2018-09-24 22:25:17 +00:00
|
|
|
--datadir:<value> Base directory for all blockchain-related data
|
2021-04-27 07:18:26 +00:00
|
|
|
--keystore:<value> Directory for the keystore (default: inside datadir)
|
|
|
|
--prune:<value> Blockchain prune mode (full or archive, default: full)
|
|
|
|
--import:<path> Import RLP encoded block(s), validate, write to database and quit
|
2021-07-31 12:16:30 +00:00
|
|
|
--clique-period:<value> Enables clique support. value is block time in seconds
|
|
|
|
--engine-signer:<value> Enables mining. value is EthAddress in hex
|
|
|
|
--import-key:<path> Import unencrypted 32 bytes hex private key file
|
2018-05-02 15:01:10 +00:00
|
|
|
|
2018-04-27 08:53:53 +00:00
|
|
|
NETWORKING OPTIONS:
|
|
|
|
--bootnodes:<value> Comma separated enode URLs for P2P discovery bootstrap (set v4+v5 instead for light servers)
|
|
|
|
--bootnodesv4:<value> Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes)
|
2018-09-24 22:25:17 +00:00
|
|
|
--bootnodesv5:<value> Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes)
|
2019-04-23 13:49:49 +00:00
|
|
|
--staticnodes:<value> Comma separated enode URLs to connect with
|
2018-05-02 15:01:10 +00:00
|
|
|
--port:<value> Network listening TCP port (default: 30303)
|
2021-04-09 07:26:06 +00:00
|
|
|
--discport:<value> Network listening UDP port (defaults to --port argument)
|
2018-04-27 08:53:53 +00:00
|
|
|
--maxpeers:<value> Maximum number of network peers (default: 25)
|
|
|
|
--maxpendpeers:<value> Maximum number of pending connection attempts (default: 0)
|
2019-04-17 01:56:28 +00:00
|
|
|
--nat:<value> NAT port mapping mechanism (any|none|upnp|pmp|<external IP>) (default: "any")
|
2018-04-27 08:53:53 +00:00
|
|
|
--nodiscover Disables the peer discovery mechanism (manual peer addition)
|
2021-04-27 07:18:26 +00:00
|
|
|
--v5discover Enables the experimental RLPx V5 (topic discovery) mechanism
|
2018-05-02 15:01:10 +00:00
|
|
|
--nodekey:<value> P2P node private key (as hexadecimal string)
|
2018-06-20 17:27:32 +00:00
|
|
|
--ident:<value> Client identifier (default is '$1')
|
2019-04-23 13:49:49 +00:00
|
|
|
--protocols:<value> Enable specific set of protocols (default: $4)
|
2021-04-27 07:18:26 +00:00
|
|
|
|
|
|
|
ETHEREUM NETWORK OPTIONS:
|
|
|
|
--mainnet Use Ethereum main network (default)
|
|
|
|
--testnet Use Ropsten test network
|
|
|
|
--ropsten Use Ropsten test network (proof-of-work, the one most like Ethereum mainnet)
|
|
|
|
--goerli Use Görli test network (proof-of-authority, works across all clients)
|
|
|
|
--rinkeby Use Rinkeby test network (proof-of-authority, for those running Geth clients)
|
|
|
|
--kovan Use Kovan test network (proof-of-authority, for those running OpenEthereum clients)
|
|
|
|
--networkid:<value> Network id (0=custom, 1=mainnet, 3=ropsten, 4=rinkeby, 5=goerli, 42=kovan, other...)
|
2021-03-18 15:05:15 +00:00
|
|
|
--customnetwork:<path> Use custom genesis block for private Ethereum Network (as /path/to/genesis.json)
|
2019-04-23 13:49:49 +00:00
|
|
|
|
2021-04-27 07:18:26 +00:00
|
|
|
LOCAL SERVICE OPTIONS:
|
|
|
|
--metrics Enable the metrics HTTP server
|
|
|
|
--metricsport:<value> Set port (always on localhost) metrics HTTP server will bind to (default: 9093)
|
2018-04-27 08:53:53 +00:00
|
|
|
--rpc Enable the HTTP-RPC server
|
2021-04-27 07:18:26 +00:00
|
|
|
--rpcbind:<value> Set address:port pair(s) (comma-separated) HTTP-RPC server will bind to (default: localhost:8545)
|
2021-06-01 13:15:19 +00:00
|
|
|
--rpcapi:<value> Enable specific set of RPC API from list (comma-separated) (available: eth, debug)
|
2021-04-27 07:18:26 +00:00
|
|
|
--graphql Enable the HTTP-GraphQL server
|
|
|
|
--graphqlbind:<value> Set address:port pair GraphQL server will bind (default: localhost:8547)
|
2021-07-31 12:27:13 +00:00
|
|
|
--ws Enable the Websocket JSON-RPC server
|
|
|
|
--wsbind:<value> Set address:port pair(s) (comma-separated) Websocket JSON-RPC server will bind to (default: localhost:8546)
|
|
|
|
--wsapi:<value> Enable specific set of Websocket RPC API from list (comma-separated) (available: eth, debug)
|
2018-04-27 08:53:53 +00:00
|
|
|
|
|
|
|
LOGGING AND DEBUGGING OPTIONS:
|
2019-03-20 13:41:25 +00:00
|
|
|
--log-level:<value> One of: $2 (default: $3)
|
|
|
|
--log-file:<value> Optional log file, replacing stdout
|
2021-04-27 07:18:26 +00:00
|
|
|
--logmetrics Enable metrics logging
|
|
|
|
--logmetricsinterval:<value> Interval at which to log metrics, in seconds (default: 10)
|
2018-04-27 08:53:53 +00:00
|
|
|
--debug Enable debug mode
|
|
|
|
--test:<value> Perform specified test
|
2018-06-20 17:27:32 +00:00
|
|
|
""" % [
|
2019-03-20 13:41:25 +00:00
|
|
|
NimbusIdent,
|
|
|
|
join(logLevels, ", "),
|
2019-04-23 13:49:49 +00:00
|
|
|
$defaultLogLevel,
|
|
|
|
strip($defaultProtocols, chars = {'{','}'}),
|
2018-06-20 17:27:32 +00:00
|
|
|
]
|
2018-04-27 08:53:53 +00:00
|
|
|
|
2019-07-31 11:54:48 +00:00
|
|
|
when declared(os.paramCount): # not available with `--app:lib`
|
2021-04-29 05:25:13 +00:00
|
|
|
proc processArguments*(msg: var string, opt: var OptParser): ConfigStatus =
|
2019-07-31 11:54:48 +00:00
|
|
|
## Process command line argument and update `NimbusConfiguration`.
|
|
|
|
let config = getConfiguration()
|
|
|
|
|
2021-05-20 06:37:24 +00:00
|
|
|
# At this point `config.net.discPort` is likely populated with network default
|
|
|
|
# discPort. We want to override those if it is specified on the command line.
|
2019-07-31 11:54:48 +00:00
|
|
|
config.net.discPort = 0
|
|
|
|
|
|
|
|
var length = 0
|
|
|
|
for kind, key, value in opt.getopt():
|
|
|
|
result = Error
|
|
|
|
case kind
|
|
|
|
of cmdArgument:
|
|
|
|
discard
|
|
|
|
of cmdLongOption, cmdShortOption:
|
|
|
|
inc(length)
|
|
|
|
case key.toLowerAscii()
|
|
|
|
of "help", "h":
|
|
|
|
msg = getHelpString()
|
|
|
|
result = Success
|
|
|
|
break
|
|
|
|
of "version", "ver", "v":
|
|
|
|
msg = NimbusVersion
|
|
|
|
result = Success
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
processArgument processEthArguments, key, value, msg
|
|
|
|
processArgument processRpcArguments, key, value, msg
|
|
|
|
processArgument processNetArguments, key, value, msg
|
|
|
|
processArgument processDebugArguments, key, value, msg
|
2021-04-24 03:58:05 +00:00
|
|
|
processArgument processGraphqlArguments, key, value, msg
|
2021-07-31 12:27:13 +00:00
|
|
|
processArgument processWsArguments, key, value, msg
|
2019-07-31 11:54:48 +00:00
|
|
|
if result != Success:
|
|
|
|
msg = "Unknown option: '" & key & "'."
|
|
|
|
break
|
|
|
|
of cmdEnd:
|
|
|
|
doAssert(false) # we're never getting this kind here
|
|
|
|
|
|
|
|
if config.net.discPort == 0:
|
|
|
|
config.net.discPort = config.net.bindPort
|
2018-04-27 08:53:53 +00:00
|
|
|
|
2021-04-29 05:25:13 +00:00
|
|
|
proc processArguments*(msg: var string): ConfigStatus =
|
|
|
|
var opt = initOptParser()
|
|
|
|
processArguments(msg, opt)
|
|
|
|
|
2019-03-20 13:41:25 +00:00
|
|
|
proc processConfiguration*(pathname: string): ConfigStatus =
|
2018-04-27 08:53:53 +00:00
|
|
|
## Process configuration file `pathname` and update `NimbusConfiguration`.
|
|
|
|
result = Success
|