config: copy chainId to networkid if networkid not set in cli

although they are technically different, but in reality,
many networks are using the same id for ChainId dan NetworkId.
in this commit, we set networkid from config file's chainId.
This commit is contained in:
jangko 2021-08-05 19:39:29 +07:00
parent 4459fc3519
commit 5e87624315
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 23 additions and 4 deletions

View File

@ -847,6 +847,13 @@ when declared(os.paramCount): # not available with `--app:lib`
if config.net.discPort == 0: if config.net.discPort == 0:
config.net.discPort = config.net.bindPort 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 = proc processArguments*(msg: var string): ConfigStatus =
var opt = initOptParser() var opt = initOptParser()
processArguments(msg, opt) processArguments(msg, opt)

View File

@ -28,24 +28,36 @@ proc miscMain*() =
const genesisFile = "tests" / "customgenesis" / "calaveras.json" const genesisFile = "tests" / "customgenesis" / "calaveras.json"
test "networkid cli": test "networkid cli":
var msg: string var msg: string
var opt = initOptParser("--customnetwork:" & genesisFile & " --networkid:123") var opt = initOptParser("--customnetwork:" & genesisFile & " --networkid:345")
let res = processArguments(msg, opt) let res = processArguments(msg, opt)
if res != Success: if res != Success:
echo msg echo msg
quit(QuitFailure) quit(QuitFailure)
let conf = getConfiguration() 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 msg: string
var opt = initOptParser(" --networkid:123 --customnetwork:" & genesisFile) var opt = initOptParser("--networkid:678 --customnetwork:" & genesisFile)
let res = processArguments(msg, opt) let res = processArguments(msg, opt)
if res != Success: if res != Success:
echo msg echo msg
quit(QuitFailure) quit(QuitFailure)
let conf = getConfiguration() 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 check conf.net.networkId == 123.NetworkId
when isMainModule: when isMainModule: