bool CCoinsView::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) { return false; }
bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
- CNullifiersMap &mapSaplingNullifiers) { return base->BatchWrite(mapCoins, hashBlock, hashAnchor, mapAnchors, mapSproutNullifiers, mapSaplingNullifiers); }
+ CNullifiersMap &mapSaplingNullifiers) { return base->BatchWrite(mapCoins, hashBlock, hashAnchor, mapSproutAnchors, mapSproutNullifiers, mapSaplingNullifiers); }
bool CCoinsViewBacked::GetStats(CCoinsStats &stats) const { return base->GetStats(stats); }
CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {}
size_t CCoinsViewCache::DynamicMemoryUsage() const {
return memusage::DynamicUsage(cacheCoins) +
- memusage::DynamicUsage(cacheAnchors) +
+ memusage::DynamicUsage(cacheSproutAnchors) +
memusage::DynamicUsage(cacheSproutNullifiers) +
memusage::DynamicUsage(cacheSaplingNullifiers) +
cachedCoinsUsage;
bool CCoinsViewCache::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const {
- CAnchorsMap::const_iterator it = cacheAnchors.find(rt);
- if (it != cacheAnchors.end()) {
+ CAnchorsSproutMap::const_iterator it = cacheSproutAnchors.find(rt);
+ if (it != cacheSproutAnchors.end()) {
if (it->second.entered) {
tree = it->second.tree;
return true;
return false;
}
- CAnchorsMap::iterator ret = cacheAnchors.insert(std::make_pair(rt, CAnchorsCacheEntry())).first;
+ CAnchorsSproutMap::iterator ret = cacheSproutAnchors.insert(std::make_pair(rt, CAnchorsSproutCacheEntry())).first;
ret->second.entered = true;
ret->second.tree = tree;
cachedCoinsUsage += ret->second.tree.DynamicMemoryUsage();
auto currentRoot = GetBestAnchor();
// We don't want to overwrite an anchor we already have.
- // This occurs when a block doesn't modify mapAnchors at all,
+ // This occurs when a block doesn't modify mapSproutAnchors at all,
// because there are no joinsplits. We could get around this a
- // different way (make all blocks modify mapAnchors somehow)
+ // different way (make all blocks modify mapSproutAnchors somehow)
// but this is simpler to reason about.
if (currentRoot != newrt) {
- auto insertRet = cacheAnchors.insert(std::make_pair(newrt, CAnchorsCacheEntry()));
- CAnchorsMap::iterator ret = insertRet.first;
+ auto insertRet = cacheSproutAnchors.insert(std::make_pair(newrt, CAnchorsSproutCacheEntry()));
+ CAnchorsSproutMap::iterator ret = insertRet.first;
ret->second.entered = true;
ret->second.tree = tree;
- ret->second.flags = CAnchorsCacheEntry::DIRTY;
+ ret->second.flags = CAnchorsSproutCacheEntry::DIRTY;
if (insertRet.second) {
// An insert took place
}
// Mark the anchor as unentered, removing it from view
- cacheAnchors[currentRoot].entered = false;
+ cacheSproutAnchors[currentRoot].entered = false;
// Mark the cache entry as dirty so it's propagated
- cacheAnchors[currentRoot].flags = CAnchorsCacheEntry::DIRTY;
+ cacheSproutAnchors[currentRoot].flags = CAnchorsSproutCacheEntry::DIRTY;
// Mark the new root as the best anchor
hashAnchor = newrt;
bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlockIn,
const uint256 &hashAnchorIn,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) {
assert(!hasModifier);
mapCoins.erase(itOld);
}
- for (CAnchorsMap::iterator child_it = mapAnchors.begin(); child_it != mapAnchors.end();)
+ for (CAnchorsSproutMap::iterator child_it = mapSproutAnchors.begin(); child_it != mapSproutAnchors.end();)
{
- if (child_it->second.flags & CAnchorsCacheEntry::DIRTY) {
- CAnchorsMap::iterator parent_it = cacheAnchors.find(child_it->first);
+ if (child_it->second.flags & CAnchorsSproutCacheEntry::DIRTY) {
+ CAnchorsSproutMap::iterator parent_it = cacheSproutAnchors.find(child_it->first);
- if (parent_it == cacheAnchors.end()) {
- CAnchorsCacheEntry& entry = cacheAnchors[child_it->first];
+ if (parent_it == cacheSproutAnchors.end()) {
+ CAnchorsSproutCacheEntry& entry = cacheSproutAnchors[child_it->first];
entry.entered = child_it->second.entered;
entry.tree = child_it->second.tree;
- entry.flags = CAnchorsCacheEntry::DIRTY;
+ entry.flags = CAnchorsSproutCacheEntry::DIRTY;
cachedCoinsUsage += entry.tree.DynamicMemoryUsage();
} else {
if (parent_it->second.entered != child_it->second.entered) {
// The parent may have removed the entry.
parent_it->second.entered = child_it->second.entered;
- parent_it->second.flags |= CAnchorsCacheEntry::DIRTY;
+ parent_it->second.flags |= CAnchorsSproutCacheEntry::DIRTY;
}
}
}
- CAnchorsMap::iterator itOld = child_it++;
- mapAnchors.erase(itOld);
+ CAnchorsSproutMap::iterator itOld = child_it++;
+ mapSproutAnchors.erase(itOld);
}
::BatchWriteNullifiers(mapSproutNullifiers, cacheSproutNullifiers);
}
bool CCoinsViewCache::Flush() {
- bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheAnchors, cacheSproutNullifiers, cacheSaplingNullifiers);
+ bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheSproutAnchors, cacheSproutNullifiers, cacheSaplingNullifiers);
cacheCoins.clear();
- cacheAnchors.clear();
+ cacheSproutAnchors.clear();
cacheSproutNullifiers.clear();
cacheSaplingNullifiers.clear();
cachedCoinsUsage = 0;
CCoinsCacheEntry() : coins(), flags(0) {}
};
-struct CAnchorsCacheEntry
+struct CAnchorsSproutCacheEntry
{
bool entered; // This will be false if the anchor is removed from the cache
ZCIncrementalMerkleTree tree; // The tree itself
DIRTY = (1 << 0), // This cache entry is potentially different from the version in the parent view.
};
- CAnchorsCacheEntry() : entered(false), flags(0) {}
+ CAnchorsSproutCacheEntry() : entered(false), flags(0) {}
};
struct CNullifiersCacheEntry
};
typedef boost::unordered_map<uint256, CCoinsCacheEntry, CCoinsKeyHasher> CCoinsMap;
-typedef boost::unordered_map<uint256, CAnchorsCacheEntry, CCoinsKeyHasher> CAnchorsMap;
+typedef boost::unordered_map<uint256, CAnchorsSproutCacheEntry, CCoinsKeyHasher> CAnchorsSproutMap;
typedef boost::unordered_map<uint256, CNullifiersCacheEntry, CCoinsKeyHasher> CNullifiersMap;
struct CCoinsStats
virtual bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers);
bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers);
bool GetStats(CCoinsStats &stats) const;
mutable uint256 hashBlock;
mutable CCoinsMap cacheCoins;
mutable uint256 hashAnchor;
- mutable CAnchorsMap cacheAnchors;
+ mutable CAnchorsSproutMap cacheSproutAnchors;
mutable CNullifiersMap cacheSproutNullifiers;
mutable CNullifiersMap cacheSaplingNullifiers;
bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers);
bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) {
return false;
bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap saplingNullifiersMap) {
return false;
uint256 hashBestBlock_;
uint256 hashBestAnchor_;
std::map<uint256, CCoins> map_;
- std::map<uint256, ZCIncrementalMerkleTree> mapAnchors_;
+ std::map<uint256, ZCIncrementalMerkleTree> mapSproutAnchors_;
std::map<uint256, bool> mapSproutNullifiers_;
std::map<uint256, bool> mapSaplingNullifiers_;
return true;
}
- std::map<uint256, ZCIncrementalMerkleTree>::const_iterator it = mapAnchors_.find(rt);
- if (it == mapAnchors_.end()) {
+ std::map<uint256, ZCIncrementalMerkleTree>::const_iterator it = mapSproutAnchors_.find(rt);
+ if (it == mapSproutAnchors_.end()) {
return false;
} else {
tree = it->second;
bool BatchWrite(CCoinsMap& mapCoins,
const uint256& hashBlock,
const uint256& hashAnchor,
- CAnchorsMap& mapAnchors,
+ CAnchorsSproutMap& mapSproutAnchors,
CNullifiersMap& mapSproutNullifiers,
CNullifiersMap& mapSaplingNullifiers)
{
}
mapCoins.erase(it++);
}
- for (CAnchorsMap::iterator it = mapAnchors.begin(); it != mapAnchors.end(); ) {
+ for (CAnchorsSproutMap::iterator it = mapSproutAnchors.begin(); it != mapSproutAnchors.end(); ) {
if (it->second.entered) {
std::map<uint256, ZCIncrementalMerkleTree>::iterator ret =
- mapAnchors_.insert(std::make_pair(it->first, ZCIncrementalMerkleTree())).first;
+ mapSproutAnchors_.insert(std::make_pair(it->first, ZCIncrementalMerkleTree())).first;
ret->second = it->second.tree;
} else {
- mapAnchors_.erase(it->first);
+ mapSproutAnchors_.erase(it->first);
}
- mapAnchors.erase(it++);
+ mapSproutAnchors.erase(it++);
}
BatchWriteNullifiers(mapSproutNullifiers, mapSproutNullifiers_);
BatchWriteNullifiers(mapSaplingNullifiers, mapSaplingNullifiers_);
mapCoins.clear();
- mapAnchors.clear();
+ mapSproutAnchors.clear();
hashBestBlock_ = hashBlock;
hashBestAnchor_ = hashAnchor;
return true;
{
// Manually recompute the dynamic usage of the whole data, and compare it.
size_t ret = memusage::DynamicUsage(cacheCoins) +
- memusage::DynamicUsage(cacheAnchors) +
+ memusage::DynamicUsage(cacheSproutAnchors) +
memusage::DynamicUsage(cacheSproutNullifiers) +
memusage::DynamicUsage(cacheSaplingNullifiers);
for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) {
bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers) {
CDBBatch batch(db);
mapCoins.erase(itOld);
}
- for (CAnchorsMap::iterator it = mapAnchors.begin(); it != mapAnchors.end();) {
- if (it->second.flags & CAnchorsCacheEntry::DIRTY) {
+ for (CAnchorsSproutMap::iterator it = mapSproutAnchors.begin(); it != mapSproutAnchors.end();) {
+ if (it->second.flags & CAnchorsSproutCacheEntry::DIRTY) {
if (!it->second.entered)
batch.Erase(make_pair(DB_ANCHOR, it->first));
else {
}
// TODO: changed++?
}
- CAnchorsMap::iterator itOld = it++;
- mapAnchors.erase(itOld);
+ CAnchorsSproutMap::iterator itOld = it++;
+ mapSproutAnchors.erase(itOld);
}
::BatchWriteNullifiers(batch, mapSproutNullifiers, DB_NULLIFIER);
bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap &mapSaplingNullifiers);
bool GetStats(CCoinsStats &stats) const;
bool BatchWrite(CCoinsMap &mapCoins,
const uint256 &hashBlock,
const uint256 &hashAnchor,
- CAnchorsMap &mapAnchors,
+ CAnchorsSproutMap &mapSproutAnchors,
CNullifiersMap &mapSproutNullifiers,
CNullifiersMap& mapSaplingNullifiers) {
return false;