aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2012-07-19 20:06:20 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2012-08-01 18:23:30 +0000
commit1be064190ed0ca95113cf273082a2d81dc8a4357 (patch)
tree037ef6896b2408ab396e336c890b9e758e64dce7 /src/bitcoinrpc.cpp
parent4060d64fc9de6f11ae69f3961d4f1f0450dd8286 (diff)
downloadbitcoin-1be064190ed0ca95113cf273082a2d81dc8a4357.tar.xz
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
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r--src/bitcoinrpc.cpp5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 62b0b497ed..474207bdce 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();
}