| 55 | uint256 GetBestBlock() const override { return hashBestBlock_; } |
| 56 | |
| 57 | bool BatchWrite(CCoinsMap& mapCoins, const uint256& hashBlock) override |
| 58 | { |
| 59 | for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) { |
| 60 | if (it->second.flags & CCoinsCacheEntry::DIRTY) { |
| 61 | // Same optimization used in CCoinsViewDB is to only write dirty entries. |
| 62 | map_[it->first.second] = it->second.coin; |
| 63 | if (it->second.coin.IsSpent() && InsecureRandRange(3) == 0) { |
| 64 | // Randomly delete empty entries on write. |
| 65 | map_.erase(it->first.second); |
| 66 | } |
| 67 | } |
| 68 | mapCoins.erase(it++); |
| 69 | } |
| 70 | if (!hashBlock.IsNull()) |
| 71 | hashBestBlock_ = hashBlock; |
| 72 | return true; |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | class CCoinsViewCacheTest : public CCoinsViewCache |