Support skip and reverse in the GetBlockHeaders request + reactivate getBlockBodies

This commit is contained in:
kdeme 2019-07-08 13:15:50 +02:00 committed by zah
parent 022139db50
commit 3088cb462e
3 changed files with 11 additions and 5 deletions

View File

@ -345,7 +345,10 @@ proc getBlockHeader*(db: AbstractChainDB, b: BlockNumber): BlockHeaderRef {.gcsa
method getBestBlockHeader*(self: AbstractChainDB): BlockHeader {.base, gcsafe.} =
notImplemented()
method getSuccessorHeader*(db: AbstractChainDB, h: BlockHeader, output: var BlockHeader): bool {.base, gcsafe.} =
method getSuccessorHeader*(db: AbstractChainDB, h: BlockHeader, output: var BlockHeader, skip = 0'u): bool {.base, gcsafe.} =
notImplemented()
method getAncestorHeader*(db: AbstractChainDB, h: BlockHeader, output: var BlockHeader, skip = 0'u): bool {.base, gcsafe.} =
notImplemented()
method getBlockBody*(db: AbstractChainDB, blockHash: KeccakHash): BlockBodyRef {.base, gcsafe.} =

View File

@ -12,7 +12,11 @@ proc getBlockHeaders*(db: AbstractChainDB,
result.add foundBlock
while uint64(result.len) < req.maxResults:
if not db.getSuccessorHeader(foundBlock, foundBlock):
if not req.reverse:
if not db.getSuccessorHeader(foundBlock, foundBlock, req.skip):
break
else:
if not db.getAncestorHeader(foundBlock, foundBlock, req.skip):
break
result.add foundBlock

View File

@ -91,8 +91,7 @@ p2pProtocol eth(version = protocolVersion,
await peer.disconnect(BreachOfProtocol)
return
# TODO: implement `getBlockBodies` and reactivate this code
# await response.send(peer.network.chain.getBlockBodies(hashes))
await response.send(peer.network.chain.getBlockBodies(hashes))
proc blockBodies(peer: Peer, blocks: openarray[BlockBody])