mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
fix persist tool to support testnet
This commit is contained in:
parent
3931c1ff5c
commit
2e583e9aa0
@ -1,5 +1,5 @@
|
|||||||
import stint, os, parseopt, strutils
|
import stint, os, parseopt, strutils
|
||||||
from ../nimbus/config import getDefaultDataDir, ConfigStatus, processInteger
|
from ../nimbus/config import getDefaultDataDir, ConfigStatus, processInteger, PublicNetwork
|
||||||
|
|
||||||
export ConfigStatus
|
export ConfigStatus
|
||||||
|
|
||||||
@ -9,6 +9,7 @@ type
|
|||||||
head*: Uint256
|
head*: Uint256
|
||||||
maxBlocks*: int
|
maxBlocks*: int
|
||||||
numCommits*: int
|
numCommits*: int
|
||||||
|
netId*: PublicNetwork
|
||||||
|
|
||||||
var premixConfig {.threadvar.}: PremixConfiguration
|
var premixConfig {.threadvar.}: PremixConfiguration
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ proc initConfiguration(): PremixConfiguration =
|
|||||||
result.head = 0.u256
|
result.head = 0.u256
|
||||||
result.maxBlocks = 0
|
result.maxBlocks = 0
|
||||||
result.numCommits = 128
|
result.numCommits = 128
|
||||||
|
result.netId = MainNet
|
||||||
|
|
||||||
proc getConfiguration*(): PremixConfiguration =
|
proc getConfiguration*(): PremixConfiguration =
|
||||||
if isNil(premixConfig):
|
if isNil(premixConfig):
|
||||||
@ -36,6 +38,15 @@ proc processU256(val: string, o: var Uint256): ConfigStatus =
|
|||||||
o = parse(val, Uint256)
|
o = parse(val, Uint256)
|
||||||
result = Success
|
result = Success
|
||||||
|
|
||||||
|
proc processNetId(val: string, o: var PublicNetwork): ConfigStatus =
|
||||||
|
case val.toLowerAscii()
|
||||||
|
of "main": o = MainNet
|
||||||
|
of "morden": o = MordenNet
|
||||||
|
of "ropsten": o = RopstenNet
|
||||||
|
of "rinkeby": o = RinkebyNet
|
||||||
|
of "goerli": o = GoerliNet
|
||||||
|
of "kovan": o = KovanNet
|
||||||
|
|
||||||
template checkArgument(fun, o: untyped) =
|
template checkArgument(fun, o: untyped) =
|
||||||
## Checks if arguments got processed successfully
|
## Checks if arguments got processed successfully
|
||||||
var res = (fun)(value, o)
|
var res = (fun)(value, o)
|
||||||
@ -72,6 +83,8 @@ proc processArguments*(msg: var string): ConfigStatus =
|
|||||||
of "numcommits":
|
of "numcommits":
|
||||||
checkArgument processInteger, config.numCommits
|
checkArgument processInteger, config.numCommits
|
||||||
config.numCommits = max(config.numCommits, 512)
|
config.numCommits = max(config.numCommits, 512)
|
||||||
|
of "netid":
|
||||||
|
checkArgument processNetId, config.netId
|
||||||
else:
|
else:
|
||||||
msg = "Unknown option " & key
|
msg = "Unknown option " & key
|
||||||
if value.len > 0: msg = msg & " : " & value
|
if value.len > 0: msg = msg & " : " & value
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import
|
import
|
||||||
eth/[common, rlp], stint,
|
eth/[common, rlp], stint,
|
||||||
chronicles, downloader, configuration,
|
chronicles, downloader, configuration,
|
||||||
../nimbus/errors
|
../nimbus/[errors, config]
|
||||||
|
|
||||||
import
|
import
|
||||||
eth/trie/[hexary, db],
|
eth/trie/[hexary, db],
|
||||||
@ -34,10 +34,10 @@ proc main() =
|
|||||||
# 52029 first block with receipts logs
|
# 52029 first block with receipts logs
|
||||||
# 66407 failed transaction
|
# 66407 failed transaction
|
||||||
|
|
||||||
let conf = getConfiguration()
|
let conf = configuration.getConfiguration()
|
||||||
let db = newChainDb(conf.dataDir)
|
let db = newChainDb(conf.dataDir)
|
||||||
let trieDB = trieDB db
|
let trieDB = trieDB db
|
||||||
let chainDB = newBaseChainDB(trieDB, false)
|
let chainDB = newBaseChainDB(trieDB, false, conf.netId)
|
||||||
|
|
||||||
# move head to block number ...
|
# move head to block number ...
|
||||||
if conf.head != 0.u256:
|
if conf.head != 0.u256:
|
||||||
@ -93,7 +93,7 @@ when isMainModule:
|
|||||||
var message: string
|
var message: string
|
||||||
|
|
||||||
## Processing command line arguments
|
## Processing command line arguments
|
||||||
if processArguments(message) != Success:
|
if configuration.processArguments(message) != Success:
|
||||||
echo message
|
echo message
|
||||||
quit(QuitFailure)
|
quit(QuitFailure)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user