diff --git a/eth/common/eth_types.nim b/eth/common/eth_types.nim index 2415a0e..043b22c 100644 --- a/eth/common/eth_types.nim +++ b/eth/common/eth_types.nim @@ -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.} = diff --git a/eth/p2p/blockchain_utils.nim b/eth/p2p/blockchain_utils.nim index ab30408..1e164c2 100644 --- a/eth/p2p/blockchain_utils.nim +++ b/eth/p2p/blockchain_utils.nim @@ -12,8 +12,12 @@ proc getBlockHeaders*(db: AbstractChainDB, result.add foundBlock while uint64(result.len) < req.maxResults: - if not db.getSuccessorHeader(foundBlock, foundBlock): - break + 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 template fetcher*(fetcherName, fetchingFunc, InputType, ResultType: untyped) = diff --git a/eth/p2p/rlpx_protocols/eth_protocol.nim b/eth/p2p/rlpx_protocols/eth_protocol.nim index 5e8cc45..951f981 100644 --- a/eth/p2p/rlpx_protocols/eth_protocol.nim +++ b/eth/p2p/rlpx_protocols/eth_protocol.nim @@ -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])