Handle missing blocks better in block_pool.getBlockRange

This commit is contained in:
Zahary Karadjov 2019-11-27 13:45:34 +02:00
parent 897176761d
commit 8c3ea1cabf
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609

View File

@ -366,7 +366,8 @@ proc getBlockRange*(pool: BlockPool, headBlock: Eth2Digest,
return return
template skip(n: int) = template skip(n: int) =
for i in 0 ..< n: let targetSlot = b.slot - Slot(n)
while b.slot > targetSlot:
if b.parent == nil: if b.parent == nil:
trace "stopping at parentless block", slot = b.slot, root = b.root trace "stopping at parentless block", slot = b.slot, root = b.root
return return
@ -391,7 +392,7 @@ proc getBlockRange*(pool: BlockPool, headBlock: Eth2Digest,
skip blocksToSkip skip blocksToSkip
# From here, we can just write out the requested block range: # From here, we can just write out the requested block range:
while b != nil and result > 0: while b != nil and b.slot >= startSlot and result > 0:
dec result dec result
output[result] = b output[result] = b
trace "getBlockRange result", position = result, blockSlot = b.slot trace "getBlockRange result", position = result, blockSlot = b.slot