Make CCoinsViewTest behave like CCoinsViewDB

This commit is contained in:
Alex Morcos 2015-11-11 13:02:02 -05:00
parent 14470f9aa6
commit 03c82826f9
1 changed files with 9 additions and 6 deletions

View File

@ -45,14 +45,17 @@ public:
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock) bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock)
{ {
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) { for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) {
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
// Same optimization used in CCoinsViewDB is to only write dirty entries.
map_[it->first] = it->second.coins; map_[it->first] = it->second.coins;
if (it->second.coins.IsPruned() && insecure_rand() % 3 == 0) { if (it->second.coins.IsPruned() && insecure_rand() % 3 == 0) {
// Randomly delete empty entries on write. // Randomly delete empty entries on write.
map_.erase(it->first); map_.erase(it->first);
} }
}
mapCoins.erase(it++); mapCoins.erase(it++);
} }
mapCoins.clear(); if (!hashBlock.IsNull())
hashBestBlock_ = hashBlock; hashBestBlock_ = hashBlock;
return true; return true;
} }