Skip to content

Commit 23701c9

Browse files
author
pmmiranda
committed
Fixed behaviour on consensus layer about reading program options
from command line, instead of loading the ones already filtered.
1 parent 431ac36 commit 23701c9

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

nimbus/consensus/consensus_layer.nim

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import
1212
chronos,
1313
chronicles,
1414
results,
15+
confutils,
1516
../conf,
1617
../common/utils,
1718
./wrapper_consensus,
@@ -21,13 +22,42 @@ import
2122
logScope:
2223
topics = "Consensus layer"
2324

24-
proc startBeaconNode(configs: seq[string]) {.raises: [CatchableError].} =
25-
proc commandLineParams(): seq[string] =
26-
configs
25+
proc makeConfig*(
26+
cmdCommandList: seq[string], ConfType: type
27+
): Result[ConfType, string] =
28+
{.push warning[ProveInit]: off.}
29+
let config =
30+
try:
31+
ConfType.load(
32+
cmdLine = cmdCommandList,
33+
secondarySources = proc(
34+
config: ConfType, sources: auto
35+
) {.raises: [ConfigurationError], gcsafe.} =
36+
if config.configFile.isSome:
37+
sources.addConfigFile(Toml, config.configFile.get)
38+
,
39+
)
40+
except CatchableError as exc:
41+
# We need to log to stderr here, because logging hasn't been configured yet
42+
var msg = "Failure while loading the configuration:\p" & exc.msg & "\p"
43+
if (exc[] of ConfigurationError) and not (isNil(exc.parent)) and
44+
(exc.parent[] of TomlFieldReadingError):
45+
let fieldName = ((ref TomlFieldReadingError)(exc.parent)).field
46+
if fieldName in
47+
[
48+
"el", "web3-url", "bootstrap-node", "direct-peer",
49+
"validator-monitor-pubkey",
50+
]:
51+
msg &=
52+
"Since the '" & fieldName & "' option is allowed to " &
53+
"have more than one value, please make sure to supply " &
54+
"a properly formatted TOML array\p"
55+
return err(msg)
56+
{.pop.}
57+
ok(config)
2758

28-
var config = makeBannerAndConfig(
29-
"clientId", "copyrights", "nimBanner", "SPEC_VERSION", [], BeaconNodeConf
30-
).valueOr:
59+
proc startBeaconNode(paramsList: seq[string]) {.raises: [CatchableError].} =
60+
var config = makeConfig(paramsList, BeaconNodeConf).valueOr:
3161
error "Error starting consensus", err = error
3262
quit QuitFailure
3363

0 commit comments

Comments
 (0)