Skip to content

Commit 03c8282

Browse files
committed
Make CCoinsViewTest behave like CCoinsViewDB
1 parent 14470f9 commit 03c8282

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/test/coins_tests.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ class CCoinsViewTest : public CCoinsView
4545
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock)
4646
{
4747
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) {
48-
map_[it->first] = it->second.coins;
49-
if (it->second.coins.IsPruned() && insecure_rand() % 3 == 0) {
50-
// Randomly delete empty entries on write.
51-
map_.erase(it->first);
48+
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
49+
// Same optimization used in CCoinsViewDB is to only write dirty entries.
50+
map_[it->first] = it->second.coins;
51+
if (it->second.coins.IsPruned() && insecure_rand() % 3 == 0) {
52+
// Randomly delete empty entries on write.
53+
map_.erase(it->first);
54+
}
5255
}
5356
mapCoins.erase(it++);
5457
}
55-
mapCoins.clear();
56-
hashBestBlock_ = hashBlock;
58+
if (!hashBlock.IsNull())
59+
hashBestBlock_ = hashBlock;
5760
return true;
5861
}
5962

0 commit comments

Comments
 (0)