Add check for reverse getBlockHeaders

This commit is contained in:
kdeme 2019-07-08 16:51:26 +02:00 committed by zah
parent 3088cb462e
commit 1797b76351
1 changed files with 10 additions and 8 deletions

View File

@ -10,7 +10,8 @@ proc getBlockHeaders*(db: AbstractChainDB,
var foundBlock: BlockHeader var foundBlock: BlockHeader
if db.getBlockHeader(req.startBlock, foundBlock): if db.getBlockHeader(req.startBlock, foundBlock):
result.add foundBlock result.add foundBlock
# Quick sanity check for lower bounds, code should be safe though without.
if not req.reverse or (foundBlock.blockNumber >= (req.skip + 1).toBlockNumber):
while uint64(result.len) < req.maxResults: while uint64(result.len) < req.maxResults:
if not req.reverse: if not req.reverse:
if not db.getSuccessorHeader(foundBlock, foundBlock, req.skip): if not db.getSuccessorHeader(foundBlock, foundBlock, req.skip):
@ -20,6 +21,7 @@ proc getBlockHeaders*(db: AbstractChainDB,
break break
result.add foundBlock result.add foundBlock
template fetcher*(fetcherName, fetchingFunc, InputType, ResultType: untyped) = template fetcher*(fetcherName, fetchingFunc, InputType, ResultType: untyped) =
proc fetcherName*(db: AbstractChainDB, proc fetcherName*(db: AbstractChainDB,
lookups: openarray[InputType]): seq[ResultType] {.gcsafe.} = lookups: openarray[InputType]): seq[ResultType] {.gcsafe.} =