aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Morcos <morcos@chaincode.com>2015-11-11 13:02:02 -0500
committerAlex Morcos <morcos@chaincode.com>2015-11-11 21:19:19 -0500
commit03c82826f97af98c9c90b3500945654606129bc1 (patch)
tree2a1e697ace349dc33e9fe7c87022e46c43551d9e /src
parent14470f9aa6baf02ca7162564f397153a2da0c592 (diff)
Make CCoinsViewTest behave like CCoinsViewDB
Diffstat (limited to 'src')
-rw-r--r--src/test/coins_tests.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp
index 13d848311a..65f739df26 100644
--- a/src/test/coins_tests.cpp
+++ b/src/test/coins_tests.cpp
@@ -45,15 +45,18 @@ public:
bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock)
{
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) {
- map_[it->first] = it->second.coins;
- if (it->second.coins.IsPruned() && insecure_rand() % 3 == 0) {
- // Randomly delete empty entries on write.
- map_.erase(it->first);
+ if (it->second.flags & CCoinsCacheEntry::DIRTY) {
+ // Same optimization used in CCoinsViewDB is to only write dirty entries.
+ map_[it->first] = it->second.coins;
+ if (it->second.coins.IsPruned() && insecure_rand() % 3 == 0) {
+ // Randomly delete empty entries on write.
+ map_.erase(it->first);
+ }
}
mapCoins.erase(it++);
}
- mapCoins.clear();
- hashBestBlock_ = hashBlock;
+ if (!hashBlock.IsNull())
+ hashBestBlock_ = hashBlock;
return true;
}