fixes `importRlpBlocks` in conf_utils.nim
now we are importing block one by one to satisfy some of hive test cases. we also catch exception instead of letting it terminate the process.
This commit is contained in:
parent
43bc010c9c
commit
d2b47139e1
|
@ -19,32 +19,30 @@ type
|
|||
EthHeader = object
|
||||
header: BlockHeader
|
||||
|
||||
proc importRlpBlock*(importFile: string, chainDB: BasechainDB) =
|
||||
proc importRlpBlock*(importFile: string, chainDB: BasechainDB): bool =
|
||||
let res = io2.readAllBytes(importFile)
|
||||
if res.isErr:
|
||||
error "failed to import", fileName = importFile
|
||||
quit(QuitFailure)
|
||||
return false
|
||||
|
||||
var chain = newChain(chainDB)
|
||||
# the encoded rlp can contains one or more blocks
|
||||
var rlp = rlpFromBytes(res.get)
|
||||
|
||||
# separate the header and the body
|
||||
# TODO: probably we need to put it in one struct
|
||||
var headers: seq[BlockHeader]
|
||||
var bodies : seq[BlockBody]
|
||||
let head = chainDB.getCanonicalHead()
|
||||
|
||||
try:
|
||||
while true:
|
||||
let header = rlp.read(EthHeader).header
|
||||
let body = rlp.readRecordType(BlockBody, false)
|
||||
if header.blockNumber > head.blockNumber:
|
||||
headers.add header
|
||||
bodies.add body
|
||||
if not rlp.hasData:
|
||||
break
|
||||
|
||||
let valid = chain.persistBlocks(headers, bodies)
|
||||
let valid = chain.persistBlocks([header], [body])
|
||||
if valid == ValidationResult.Error:
|
||||
error "failed to import rlp encoded blocks", fileName = importFile
|
||||
quit(QuitFailure)
|
||||
return false
|
||||
if not rlp.hasData:
|
||||
break
|
||||
except CatchableError as e:
|
||||
error "rlp error", fileName = importFile, msg = e.msg, exception = e.name
|
||||
return false
|
||||
|
||||
return true
|
||||
|
|
|
@ -60,7 +60,10 @@ proc start(nimbus: NimbusNode) =
|
|||
doAssert(canonicalHeadHashKey().toOpenArray in trieDB)
|
||||
|
||||
if conf.importFile.len > 0:
|
||||
importRlpBlock(conf.importFile, chainDB)
|
||||
# success or not, we quit after importing blocks
|
||||
if not importRlpBlock(conf.importFile, chainDB):
|
||||
quit(QuitFailure)
|
||||
else:
|
||||
quit(QuitSuccess)
|
||||
|
||||
let res = conf.loadKeystoreFiles()
|
||||
|
|
Loading…
Reference in New Issue