Smarter algorithm for finding the nHeight for the last block

This commit is contained in:
Evan Duffield 2015-07-04 08:28:55 -07:00
parent 6fc05e7fa8
commit 7481a27fe4
2 changed files with 6 additions and 10 deletions

View File

@ -2943,11 +2943,9 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
{
nHeight = pindexPrev->nHeight+1;
} else { //out of order
BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex){
if(item.first == block.hashPrevBlock) {
nHeight = item.second->nHeight+1;
}
}
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
if (mi != mapBlockIndex.end() && (*mi).second)
nHeight = (*mi).second->nHeight+1;
}
if(nHeight != 0){

View File

@ -28,11 +28,9 @@ bool IsBlockValueValid(const CBlock& block, int64_t nExpectedValue){
{
nHeight = pindexPrev->nHeight+1;
} else { //out of order
BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex){
if(item.first == block.hashPrevBlock) {
nHeight = item.second->nHeight+1;
}
}
BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock);
if (mi != mapBlockIndex.end() && (*mi).second)
nHeight = (*mi).second->nHeight+1;
}
if(nHeight == 0){