From 0fe8010a10bafd67f9131b2da034fb9cd7fc5024 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 12 May 2013 15:50:22 +0200 Subject: Make FindBlockByHeight constant-time. Remove the pnext pointer in CBlockIndex, and replace it with a vBlockIndexByHeight vector (no effect on memory usage). pnext can now be replaced by vBlockIndexByHeight[nHeight+1], but FindBlockByHeight becomes constant-time. This also means the entire mapBlockIndex structure and the block index entries in it become purely blocktree-related data, and independent from the currently active chain, potentially allowing them to be protected by separate mutexes in the future. --- src/rpcblockchain.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/rpcblockchain.cpp') diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 11af1abf5..b1b0c1ac1 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -65,8 +65,9 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex) if (blockindex->pprev) result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex())); - if (blockindex->pnext) - result.push_back(Pair("nextblockhash", blockindex->pnext->GetBlockHash().GetHex())); + CBlockIndex *pnext = blockindex->GetNextInMainChain(); + if (pnext) + result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex())); return result; } -- cgit v1.2.3