mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 05:44:40 +00:00
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()
|
||||||
|
|
||||||
|
try:
|
||||||
while true:
|
while true:
|
||||||
let header = rlp.read(EthHeader).header
|
let header = rlp.read(EthHeader).header
|
||||||
let body = rlp.readRecordType(BlockBody, false)
|
let body = rlp.readRecordType(BlockBody, false)
|
||||||
if header.blockNumber > head.blockNumber:
|
if header.blockNumber > head.blockNumber:
|
||||||
headers.add header
|
let valid = chain.persistBlocks([header], [body])
|
||||||
bodies.add body
|
|
||||||
if not rlp.hasData:
|
|
||||||
break
|
|
||||||
|
|
||||||
let valid = chain.persistBlocks(headers, bodies)
|
|
||||||
if valid == ValidationResult.Error:
|
if valid == ValidationResult.Error:
|
||||||
error "failed to import rlp encoded blocks", fileName = importFile
|
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)
|
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
|
||||||
|
if not importRlpBlock(conf.importFile, chainDB):
|
||||||
|
quit(QuitFailure)
|
||||||
|
else:
|
||||||
quit(QuitSuccess)
|
quit(QuitSuccess)
|
||||||
|
|
||||||
let res = conf.loadKeystoreFiles()
|
let res = conf.loadKeystoreFiles()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user