From 1be064190ed0ca95113cf273082a2d81dc8a4357 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 19 Jul 2012 20:06:20 +0000 Subject: Optimize JSON-RPC getblockhash - If the height is in the first half, start at the genesis block and go up, rather than at the top - Cache the last lookup and use it as a reference point if it's close to the next request, to make linear lookups always fast --- src/bitcoinrpc.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/bitcoinrpc.cpp') diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 62b0b497e..474207bdc 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2023,10 +2023,7 @@ Value getblockhash(const Array& params, bool fHelp) if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range."); - CBlock block; - CBlockIndex* pblockindex = mapBlockIndex[hashBestChain]; - while (pblockindex->nHeight > nHeight) - pblockindex = pblockindex->pprev; + CBlockIndex* pblockindex = FindBlockByHeight(nHeight); return pblockindex->phashBlock->GetHex(); } -- cgit v1.2.3