Changeset View
Changeset View
Standalone View
Standalone View
src/test/coins_tests.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public: | ||||
bool HaveCoin(const COutPoint &outpoint) const override { | bool HaveCoin(const COutPoint &outpoint) const override { | ||||
Coin coin; | Coin coin; | ||||
return GetCoin(outpoint, coin); | return GetCoin(outpoint, coin); | ||||
} | } | ||||
uint256 GetBestBlock() const override { return hashBestBlock_; } | uint256 GetBestBlock() const override { return hashBestBlock_; } | ||||
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override { | bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, | ||||
CUtxoCommit *commitDelta) override { | |||||
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { | for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { | ||||
if (it->second.flags & CCoinsCacheEntry::DIRTY) { | if (it->second.flags & CCoinsCacheEntry::DIRTY) { | ||||
// Same optimization used in CCoinsViewDB is to only write dirty | // Same optimization used in CCoinsViewDB is to only write dirty | ||||
// entries. | // entries. | ||||
map_[it->first] = it->second.coin; | map_[it->first] = it->second.coin; | ||||
if (it->second.coin.IsSpent() && InsecureRandRange(3) == 0) { | if (it->second.coin.IsSpent() && InsecureRandRange(3) == 0) { | ||||
// Randomly delete empty entries on write. | // Randomly delete empty entries on write. | ||||
map_.erase(it->first); | map_.erase(it->first); | ||||
▲ Show 20 Lines • Show All 540 Lines • ▼ Show 20 Lines | if (it == map.end()) { | ||||
flags = it->second.flags; | flags = it->second.flags; | ||||
assert(flags != NO_ENTRY); | assert(flags != NO_ENTRY); | ||||
} | } | ||||
} | } | ||||
void WriteCoinViewEntry(CCoinsView &view, const Amount value, char flags) { | void WriteCoinViewEntry(CCoinsView &view, const Amount value, char flags) { | ||||
CCoinsMap map; | CCoinsMap map; | ||||
InsertCoinMapEntry(map, value, flags); | InsertCoinMapEntry(map, value, flags); | ||||
view.BatchWrite(map, {}); | view.BatchWrite(map, {}, nullptr); | ||||
} | } | ||||
class SingleEntryCacheTest { | class SingleEntryCacheTest { | ||||
public: | public: | ||||
SingleEntryCacheTest(const Amount base_value, const Amount cache_value, | SingleEntryCacheTest(const Amount base_value, const Amount cache_value, | ||||
char cache_flags) { | char cache_flags) { | ||||
WriteCoinViewEntry(base, base_value, | WriteCoinViewEntry(base, base_value, | ||||
base_value == ABSENT ? NO_ENTRY : DIRTY); | base_value == ABSENT ? NO_ENTRY : DIRTY); | ||||
▲ Show 20 Lines • Show All 276 Lines • Show Last 20 Lines |