fix side chain import

This commit is contained in:
jangko 2023-06-29 06:24:37 +07:00
parent 389ef89632
commit aa6d47864f
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 7 additions and 6 deletions

View File

@ -23,16 +23,17 @@ proc importRlpBlock*(blocksRlp: openArray[byte]; com: CommonRef; importFile: str
errorCount = 0
header: BlockHeader
body: BlockBody
let
head = com.db.getCanonicalHead()
# even though the new imported blocks have block number
# smaller than head, we keep importing it.
# it maybe a side chain.
while rlp.hasData:
try:
rlp.decompose(header, body)
if header.blockNumber > head.blockNumber:
if chain.persistBlocks([header], [body]) == ValidationResult.Error:
# register one more error and continue
errorCount.inc
if chain.persistBlocks([header], [body]) == ValidationResult.Error:
# register one more error and continue
errorCount.inc
except RlpError as e:
# terminate if there was a decoding error
error "rlp error",