make block numbers out of sequence a CatchableError

and check the Option objects from peer.getBlockBodies(hashes)
This commit is contained in:
Ștefan Talpalaru 2019-05-08 01:41:29 +02:00
parent 69691f56d2
commit 88ded1b7c6
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
1 changed files with 5 additions and 1 deletions

View File

@ -192,17 +192,21 @@ proc obtainBlocksFromPeer(syncCtx: SyncContext, peer: Peer) {.async.} =
var nextIndex = workItem.startIndex
for i in workItem.headers:
if i.blockNumber != nextIndex:
raise newException(Exception, "The block numbers are not in sequence. Not processing this workItem.")
raise newException(CatchableError, "The block numbers are not in sequence. Not processing this workItem.")
else:
nextIndex = nextIndex + 1
hashes.add(blockHash(i))
if hashes.len == maxBodiesFetch:
let b = await peer.getBlockBodies(hashes)
if b.isNone:
raise newException(CatchableError, "Was not able to get the block bodies.")
hashes.setLen(0)
bodies.add(b.get.blocks)
if hashes.len != 0:
let b = await peer.getBlockBodies(hashes)
if b.isNone:
raise newException(CatchableError, "Was not able to get the block bodies.")
bodies.add(b.get.blocks)
if bodies.len == workItem.headers.len: