Skip to content

Commit

Permalink
Fix incorrect usage of begin() when genesis block is requested in "pr…
Browse files Browse the repository at this point in the history
…otx diff" (#2699)

* Fix incorrect usage of begin() when genesis block is requested in "protx diff"

.begin() on mapBlockIndex does NOT return the genesis block, but just the
block with lowest hash.

The fix is to use chainActive[0] to get the genesis block.

* Update src/evo/simplifiedmns.cpp

Co-Authored-By: codablock <ablock84@gmail.com>
  • Loading branch information
codablock authored and UdjinM6 committed Feb 12, 2019
1 parent b239bb2 commit c0cb274
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/evo/simplifiedmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,27 @@ bool BuildSimplifiedMNListDiff(const uint256& baseBlockHash, const uint256& bloc
AssertLockHeld(cs_main);
mnListDiffRet = CSimplifiedMNListDiff();

BlockMap::iterator baseBlockIt = mapBlockIndex.begin();
const CBlockIndex* baseBlockIndex = chainActive.Genesis();
if (!baseBlockHash.IsNull()) {
baseBlockIt = mapBlockIndex.find(baseBlockHash);
auto it = mapBlockIndex.find(baseBlockHash);
if (it == mapBlockIndex.end()) {
errorRet = strprintf("block %s not found", baseBlockHash.ToString());
return false;
}
baseBlockIndex = it->second;
}
auto blockIt = mapBlockIndex.find(blockHash);
if (baseBlockIt == mapBlockIndex.end()) {
errorRet = strprintf("block %s not found", baseBlockHash.ToString());
return false;
}
if (blockIt == mapBlockIndex.end()) {
errorRet = strprintf("block %s not found", blockHash.ToString());
return false;
}
const CBlockIndex* blockIndex = blockIt->second;

if (!chainActive.Contains(baseBlockIt->second) || !chainActive.Contains(blockIt->second)) {
if (!chainActive.Contains(baseBlockIndex) || !chainActive.Contains(blockIndex)) {
errorRet = strprintf("block %s and %s are not in the same chain", baseBlockHash.ToString(), blockHash.ToString());
return false;
}
if (baseBlockIt->second->nHeight > blockIt->second->nHeight) {
if (baseBlockIndex->nHeight > blockIndex->nHeight) {
errorRet = strprintf("base block %s is higher then block %s", baseBlockHash.ToString(), blockHash.ToString());
return false;
}
Expand All @@ -150,7 +152,7 @@ bool BuildSimplifiedMNListDiff(const uint256& baseBlockHash, const uint256& bloc

// TODO store coinbase TX in CBlockIndex
CBlock block;
if (!ReadBlockFromDisk(block, blockIt->second, Params().GetConsensus())) {
if (!ReadBlockFromDisk(block, blockIndex, Params().GetConsensus())) {
errorRet = strprintf("failed to read block %s from disk", blockHash.ToString());
return false;
}
Expand Down

0 comments on commit c0cb274

Please sign in to comment.