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
|
EthHeader = object
|
||||||
header: BlockHeader
|
header: BlockHeader
|
||||||
|
|
||||||
proc importRlpBlock*(importFile: string, chainDB: BasechainDB) =
|
proc importRlpBlock*(importFile: string, chainDB: BasechainDB): bool =
|
||||||
let res = io2.readAllBytes(importFile)
|
let res = io2.readAllBytes(importFile)
|
||||||
if res.isErr:
|
if res.isErr:
|
||||||
error "failed to import", fileName = importFile
|
error "failed to import", fileName = importFile
|
||||||
quit(QuitFailure)
|
return false
|
||||||
|
|
||||||
var chain = newChain(chainDB)
|
var chain = newChain(chainDB)
|
||||||
# the encoded rlp can contains one or more blocks
|
# the encoded rlp can contains one or more blocks
|
||||||
var rlp = rlpFromBytes(res.get)
|
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()
|
let head = chainDB.getCanonicalHead()
|
||||||
|
|
||||||
while true:
|
try:
|
||||||
let header = rlp.read(EthHeader).header
|
while true:
|
||||||
let body = rlp.readRecordType(BlockBody, false)
|
let header = rlp.read(EthHeader).header
|
||||||
if header.blockNumber > head.blockNumber:
|
let body = rlp.readRecordType(BlockBody, false)
|
||||||
headers.add header
|
if header.blockNumber > head.blockNumber:
|
||||||
bodies.add body
|
let valid = chain.persistBlocks([header], [body])
|
||||||
if not rlp.hasData:
|
if valid == ValidationResult.Error:
|
||||||
break
|
error "failed to import rlp encoded blocks", fileName = importFile
|
||||||
|
return false
|
||||||
|
if not rlp.hasData:
|
||||||
|
break
|
||||||
|
except CatchableError as e:
|
||||||
|
error "rlp error", fileName = importFile, msg = e.msg, exception = e.name
|
||||||
|
return false
|
||||||
|
|
||||||
let valid = chain.persistBlocks(headers, bodies)
|
return true
|
||||||
if valid == ValidationResult.Error:
|
|
||||||
error "failed to import rlp encoded blocks", fileName = importFile
|
|
||||||
quit(QuitFailure)
|
|
||||||
|
|
|
@ -60,8 +60,11 @@ proc start(nimbus: NimbusNode) =
|
||||||
doAssert(canonicalHeadHashKey().toOpenArray in trieDB)
|
doAssert(canonicalHeadHashKey().toOpenArray in trieDB)
|
||||||
|
|
||||||
if conf.importFile.len > 0:
|
if conf.importFile.len > 0:
|
||||||
importRlpBlock(conf.importFile, chainDB)
|
# success or not, we quit after importing blocks
|
||||||
quit(QuitSuccess)
|
if not importRlpBlock(conf.importFile, chainDB):
|
||||||
|
quit(QuitFailure)
|
||||||
|
else:
|
||||||
|
quit(QuitSuccess)
|
||||||
|
|
||||||
let res = conf.loadKeystoreFiles()
|
let res = conf.loadKeystoreFiles()
|
||||||
if res.isErr:
|
if res.isErr:
|
||||||
|
|
Loading…
Reference in New Issue