Adjust tests to handle Sapling anchor cache
This commit is contained in:
@@ -61,6 +61,7 @@ public:
|
|||||||
const uint256 &hashSproutAnchor,
|
const uint256 &hashSproutAnchor,
|
||||||
const uint256 &hashSaplingAnchor,
|
const uint256 &hashSaplingAnchor,
|
||||||
CAnchorsSproutMap &mapSproutAnchors,
|
CAnchorsSproutMap &mapSproutAnchors,
|
||||||
|
CAnchorsSaplingMap &mapSaplingAnchors,
|
||||||
CNullifiersMap &mapSproutNullifiers,
|
CNullifiersMap &mapSproutNullifiers,
|
||||||
CNullifiersMap &mapSaplingNullifiers) {
|
CNullifiersMap &mapSaplingNullifiers) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
const uint256 &hashSproutAnchor,
|
const uint256 &hashSproutAnchor,
|
||||||
const uint256 &hashSaplingAnchor,
|
const uint256 &hashSaplingAnchor,
|
||||||
CAnchorsSproutMap &mapSproutAnchors,
|
CAnchorsSproutMap &mapSproutAnchors,
|
||||||
|
CAnchorsSaplingMap &mapSaplingAnchors,
|
||||||
CNullifiersMap &mapSproutNullifiers,
|
CNullifiersMap &mapSproutNullifiers,
|
||||||
CNullifiersMap saplingNullifiersMap) {
|
CNullifiersMap saplingNullifiersMap) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class CCoinsViewTest : public CCoinsView
|
|||||||
uint256 hashBestSaplingAnchor_;
|
uint256 hashBestSaplingAnchor_;
|
||||||
std::map<uint256, CCoins> map_;
|
std::map<uint256, CCoins> map_;
|
||||||
std::map<uint256, ZCIncrementalMerkleTree> mapSproutAnchors_;
|
std::map<uint256, ZCIncrementalMerkleTree> mapSproutAnchors_;
|
||||||
|
std::map<uint256, ZCSaplingIncrementalMerkleTree> mapSaplingAnchors_;
|
||||||
std::map<uint256, bool> mapSproutNullifiers_;
|
std::map<uint256, bool> mapSproutNullifiers_;
|
||||||
std::map<uint256, bool> mapSaplingNullifiers_;
|
std::map<uint256, bool> mapSaplingNullifiers_;
|
||||||
|
|
||||||
@@ -54,6 +55,22 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GetSaplingAnchorAt(const uint256& rt, ZCSaplingIncrementalMerkleTree &tree) const {
|
||||||
|
if (rt == ZCSaplingIncrementalMerkleTree::empty_root()) {
|
||||||
|
ZCSaplingIncrementalMerkleTree new_tree;
|
||||||
|
tree = new_tree;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<uint256, ZCSaplingIncrementalMerkleTree>::const_iterator it = mapSaplingAnchors_.find(rt);
|
||||||
|
if (it == mapSaplingAnchors_.end()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
tree = it->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GetNullifier(const uint256 &nf, ShieldedType type) const
|
bool GetNullifier(const uint256 &nf, ShieldedType type) const
|
||||||
{
|
{
|
||||||
const std::map<uint256, bool>* mapToUse;
|
const std::map<uint256, bool>* mapToUse;
|
||||||
@@ -130,6 +147,7 @@ public:
|
|||||||
const uint256& hashSproutAnchor,
|
const uint256& hashSproutAnchor,
|
||||||
const uint256& hashSaplingAnchor,
|
const uint256& hashSaplingAnchor,
|
||||||
CAnchorsSproutMap& mapSproutAnchors,
|
CAnchorsSproutMap& mapSproutAnchors,
|
||||||
|
CAnchorsSaplingMap& mapSaplingAnchors,
|
||||||
CNullifiersMap& mapSproutNullifiers,
|
CNullifiersMap& mapSproutNullifiers,
|
||||||
CNullifiersMap& mapSaplingNullifiers)
|
CNullifiersMap& mapSaplingNullifiers)
|
||||||
{
|
{
|
||||||
@@ -152,12 +170,24 @@ public:
|
|||||||
}
|
}
|
||||||
mapSproutAnchors.erase(it++);
|
mapSproutAnchors.erase(it++);
|
||||||
}
|
}
|
||||||
|
for (CAnchorsSaplingMap::iterator it = mapSaplingAnchors.begin(); it != mapSaplingAnchors.end(); ) {
|
||||||
|
if (it->second.entered) {
|
||||||
|
std::map<uint256, ZCSaplingIncrementalMerkleTree>::iterator ret =
|
||||||
|
mapSaplingAnchors_.insert(std::make_pair(it->first, ZCSaplingIncrementalMerkleTree())).first;
|
||||||
|
|
||||||
|
ret->second = it->second.tree;
|
||||||
|
} else {
|
||||||
|
mapSaplingAnchors_.erase(it->first);
|
||||||
|
}
|
||||||
|
mapSaplingAnchors.erase(it++);
|
||||||
|
}
|
||||||
|
|
||||||
BatchWriteNullifiers(mapSproutNullifiers, mapSproutNullifiers_);
|
BatchWriteNullifiers(mapSproutNullifiers, mapSproutNullifiers_);
|
||||||
BatchWriteNullifiers(mapSaplingNullifiers, mapSaplingNullifiers_);
|
BatchWriteNullifiers(mapSaplingNullifiers, mapSaplingNullifiers_);
|
||||||
|
|
||||||
mapCoins.clear();
|
mapCoins.clear();
|
||||||
mapSproutAnchors.clear();
|
mapSproutAnchors.clear();
|
||||||
|
mapSaplingAnchors.clear();
|
||||||
hashBestBlock_ = hashBlock;
|
hashBestBlock_ = hashBlock;
|
||||||
hashBestSproutAnchor_ = hashSproutAnchor;
|
hashBestSproutAnchor_ = hashSproutAnchor;
|
||||||
hashBestSaplingAnchor_ = hashSaplingAnchor;
|
hashBestSaplingAnchor_ = hashSaplingAnchor;
|
||||||
@@ -177,6 +207,7 @@ public:
|
|||||||
// Manually recompute the dynamic usage of the whole data, and compare it.
|
// Manually recompute the dynamic usage of the whole data, and compare it.
|
||||||
size_t ret = memusage::DynamicUsage(cacheCoins) +
|
size_t ret = memusage::DynamicUsage(cacheCoins) +
|
||||||
memusage::DynamicUsage(cacheSproutAnchors) +
|
memusage::DynamicUsage(cacheSproutAnchors) +
|
||||||
|
memusage::DynamicUsage(cacheSaplingAnchors) +
|
||||||
memusage::DynamicUsage(cacheSproutNullifiers) +
|
memusage::DynamicUsage(cacheSproutNullifiers) +
|
||||||
memusage::DynamicUsage(cacheSaplingNullifiers);
|
memusage::DynamicUsage(cacheSaplingNullifiers);
|
||||||
for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) {
|
for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user