mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
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
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user