From 739f36c64087dee365fec5a89025276011b21b1e Mon Sep 17 00:00:00 2001 From: kdeme Date: Mon, 8 Jul 2019 17:10:59 +0200 Subject: [PATCH] Add skip parameter in getSuccessorHeader + add getAncestorHeader --- nimbus/p2p/chain.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nimbus/p2p/chain.nim b/nimbus/p2p/chain.nim index 1b26f42a2..df31b8ad0 100644 --- a/nimbus/p2p/chain.nim +++ b/nimbus/p2p/chain.nim @@ -23,8 +23,14 @@ method getBlockHeader*(c: Chain, b: HashOrNum, output: var BlockHeader): bool {. method getBestBlockHeader*(c: Chain): BlockHeader {.gcsafe.} = c.db.getCanonicalHead() -method getSuccessorHeader*(c: Chain, h: BlockHeader, output: var BlockHeader): bool {.gcsafe.} = - let n = h.blockNumber + 1 +method getSuccessorHeader*(c: Chain, h: BlockHeader, output: var BlockHeader, skip = 0'u): bool {.gcsafe.} = + let n = if skip > 0'u: h.blockNumber + 1 + skip.toBlockNumber + else: h.blockNumber + 1 + result = c.db.getBlockHeader(n, output) + +method getAncestorHeader*(c: Chain, h: BlockHeader, output: var BlockHeader, skip = 0'u): bool {.gcsafe.} = + let n = if skip > 0'u: h.blockNumber - 1 - skip.toBlockNumber + else: h.blockNumber - 1 c.db.getBlockHeader(n, output) method getBlockBody*(c: Chain, blockHash: KeccakHash): BlockBodyRef =