fix persist tool
This commit is contained in:
parent
0c887b3711
commit
9f590a22e8
|
@ -222,7 +222,7 @@ proc processList(v: string, o: var seq[string]) =
|
||||||
if len(n) > 0:
|
if len(n) > 0:
|
||||||
o.add(n)
|
o.add(n)
|
||||||
|
|
||||||
proc processInteger(v: string, o: var int): ConfigStatus =
|
proc processInteger*(v: string, o: var int): ConfigStatus =
|
||||||
## Convert string to integer.
|
## Convert string to integer.
|
||||||
try:
|
try:
|
||||||
o = parseInt(v)
|
o = parseInt(v)
|
||||||
|
@ -512,6 +512,14 @@ template checkArgument(a, b, c, e: untyped) =
|
||||||
result = res
|
result = res
|
||||||
break
|
break
|
||||||
|
|
||||||
|
proc getDefaultDataDir*(): string =
|
||||||
|
when defined(windows):
|
||||||
|
"AppData" / "Roaming" / "Nimbus" / "DB"
|
||||||
|
elif defined(macosx):
|
||||||
|
"Library" / "Application Support" / "Nimbus" / "DB"
|
||||||
|
else:
|
||||||
|
".cache" / "nimbus" / "db"
|
||||||
|
|
||||||
proc initConfiguration(): NimbusConfiguration =
|
proc initConfiguration(): NimbusConfiguration =
|
||||||
## Allocates and initializes `NimbusConfiguration` with default values
|
## Allocates and initializes `NimbusConfiguration` with default values
|
||||||
result = new NimbusConfiguration
|
result = new NimbusConfiguration
|
||||||
|
@ -527,12 +535,7 @@ proc initConfiguration(): NimbusConfiguration =
|
||||||
result.net.discPort = 30303'u16
|
result.net.discPort = 30303'u16
|
||||||
result.net.ident = NimbusIdent
|
result.net.ident = NimbusIdent
|
||||||
|
|
||||||
const dataDir = when defined(windows):
|
const dataDir = getDefaultDataDir()
|
||||||
"AppData" / "Roaming" / "Nimbus" / "DB"
|
|
||||||
elif defined(macosx):
|
|
||||||
"Library" / "Application Support" / "Nimbus" / "DB"
|
|
||||||
else:
|
|
||||||
".cache" / "nimbus" / "db"
|
|
||||||
|
|
||||||
result.dataDir = getHomeDir() / dataDir
|
result.dataDir = getHomeDir() / dataDir
|
||||||
result.prune = PruneMode.Full
|
result.prune = PruneMode.Full
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
eth_common, stint, byteutils, nimcrypto,
|
eth_common, stint, byteutils, nimcrypto,
|
||||||
chronicles, rlp, downloader
|
chronicles, rlp, downloader, configuration
|
||||||
|
|
||||||
import
|
import
|
||||||
eth_trie/[hexary, db, defs],
|
eth_trie/[hexary, db, defs],
|
||||||
../nimbus/db/[storage_types, db_chain, select_backend],
|
../nimbus/db/[storage_types, db_chain, select_backend],
|
||||||
../nimbus/[genesis, utils, config],
|
../nimbus/[genesis, utils],
|
||||||
../nimbus/p2p/chain
|
../nimbus/p2p/chain
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -39,8 +39,9 @@ proc main() =
|
||||||
let chainDB = newBaseChainDB(trieDB, false)
|
let chainDB = newBaseChainDB(trieDB, false)
|
||||||
|
|
||||||
# move head to block number ...
|
# move head to block number ...
|
||||||
#var parentBlock = requestBlock(49438.u256)
|
if conf.head != 0.u256:
|
||||||
#chainDB.setHead(parentBlock.header)
|
var parentBlock = requestBlock(conf.head)
|
||||||
|
chainDB.setHead(parentBlock.header)
|
||||||
|
|
||||||
if canonicalHeadHashKey().toOpenArray notin trieDB:
|
if canonicalHeadHashKey().toOpenArray notin trieDB:
|
||||||
persistToDb(db):
|
persistToDb(db):
|
||||||
|
@ -51,16 +52,16 @@ proc main() =
|
||||||
var blockNumber = head.blockNumber + 1
|
var blockNumber = head.blockNumber + 1
|
||||||
var chain = newChain(chainDB)
|
var chain = newChain(chainDB)
|
||||||
|
|
||||||
const
|
let numBlocksToCommit = conf.numCommits
|
||||||
numBlocksToCommit = 128
|
|
||||||
numBlocksToDownload = 20000
|
|
||||||
|
|
||||||
var headers = newSeqOfCap[BlockHeader](numBlocksToCommit)
|
var headers = newSeqOfCap[BlockHeader](numBlocksToCommit)
|
||||||
var bodies = newSeqOfCap[BlockBody](numBlocksToCommit)
|
var bodies = newSeqOfCap[BlockBody](numBlocksToCommit)
|
||||||
var one = 1.u256
|
var one = 1.u256
|
||||||
|
|
||||||
var numBlocks = 0
|
var numBlocks = 0
|
||||||
for _ in 0 ..< numBlocksToDownload:
|
var counter = 0
|
||||||
|
|
||||||
|
while true:
|
||||||
info "REQUEST HEADER", blockNumber=blockNumber
|
info "REQUEST HEADER", blockNumber=blockNumber
|
||||||
var thisBlock = requestBlock(blockNumber)
|
var thisBlock = requestBlock(blockNumber)
|
||||||
|
|
||||||
|
@ -71,13 +72,30 @@ proc main() =
|
||||||
|
|
||||||
if numBlocks == numBlocksToCommit:
|
if numBlocks == numBlocksToCommit:
|
||||||
persistToDb(db):
|
persistToDb(db):
|
||||||
discard chain.persistBlocks(headers, bodies)
|
if chain.persistBlocks(headers, bodies) != ValidationResult.OK:
|
||||||
|
break
|
||||||
numBlocks = 0
|
numBlocks = 0
|
||||||
headers.setLen(0)
|
headers.setLen(0)
|
||||||
bodies.setLen(0)
|
bodies.setLen(0)
|
||||||
|
|
||||||
|
inc counter
|
||||||
|
if conf.maxBlocks != 0 and counter >= conf.maxBlocks:
|
||||||
|
break
|
||||||
|
|
||||||
if numBlocks > 0:
|
if numBlocks > 0:
|
||||||
persistToDb(db):
|
persistToDb(db):
|
||||||
discard chain.persistBlocks(headers, bodies)
|
discard chain.persistBlocks(headers, bodies)
|
||||||
|
|
||||||
main()
|
when isMainModule:
|
||||||
|
var message: string
|
||||||
|
|
||||||
|
## Processing command line arguments
|
||||||
|
if processArguments(message) != Success:
|
||||||
|
echo message
|
||||||
|
quit(QuitFailure)
|
||||||
|
else:
|
||||||
|
if len(message) > 0:
|
||||||
|
echo message
|
||||||
|
quit(QuitSuccess)
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in New Issue