diff --git a/nimbus/config.nim b/nimbus/config.nim index 1a45762ce..af85b780d 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -847,6 +847,13 @@ when declared(os.paramCount): # not available with `--app:lib` if config.net.discPort == 0: config.net.discPort = config.net.bindPort + if NetworkIdSet notin config.net.flags and config.net.networkId == CustomNet: + # WARNING: networkId and chainId are two distinct things + # they usage should not be mixed in other places + # we only set networkId to chainId if networkId not set in cli and + # we are using custom genesis/custom chain config via json file. + config.net.networkId = NetworkId(config.customGenesis.config.chainId) + proc processArguments*(msg: var string): ConfigStatus = var opt = initOptParser() processArguments(msg, opt) diff --git a/tests/test_misc.nim b/tests/test_misc.nim index ba58327f5..5a4c1bcf0 100644 --- a/tests/test_misc.nim +++ b/tests/test_misc.nim @@ -28,24 +28,36 @@ proc miscMain*() = const genesisFile = "tests" / "customgenesis" / "calaveras.json" test "networkid cli": var msg: string - var opt = initOptParser("--customnetwork:" & genesisFile & " --networkid:123") + var opt = initOptParser("--customnetwork:" & genesisFile & " --networkid:345") let res = processArguments(msg, opt) if res != Success: echo msg quit(QuitFailure) let conf = getConfiguration() - check conf.net.networkId == 123.NetworkId + check conf.net.networkId == 345.NetworkId - test "networkid first, customnetwork next": + test "networkid first, customnetwork next": var msg: string - var opt = initOptParser(" --networkid:123 --customnetwork:" & genesisFile) + var opt = initOptParser("--networkid:678 --customnetwork:" & genesisFile) let res = processArguments(msg, opt) if res != Success: echo msg quit(QuitFailure) let conf = getConfiguration() + check conf.net.networkId == 678.NetworkId + + test "networkid not set, copy from chainId of customnetwork": + let conf = getConfiguration() + conf.net.flags.excl NetworkIdSet + var msg: string + var opt = initOptParser("--customnetwork:" & genesisFile) + let res = processArguments(msg, opt) + if res != Success: + echo msg + quit(QuitFailure) + check conf.net.networkId == 123.NetworkId when isMainModule: