diff --git a/src/gtest/test_mempool.cpp b/src/gtest/test_mempool.cpp index 2056950b6..1fd4cd7e7 100644 --- a/src/gtest/test_mempool.cpp +++ b/src/gtest/test_mempool.cpp @@ -61,6 +61,7 @@ public: const uint256 &hashSproutAnchor, const uint256 &hashSaplingAnchor, CAnchorsSproutMap &mapSproutAnchors, + CAnchorsSaplingMap &mapSaplingAnchors, CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers) { return false; diff --git a/src/gtest/test_validation.cpp b/src/gtest/test_validation.cpp index 2198f592c..8609c93ba 100644 --- a/src/gtest/test_validation.cpp +++ b/src/gtest/test_validation.cpp @@ -56,6 +56,7 @@ public: const uint256 &hashSproutAnchor, const uint256 &hashSaplingAnchor, CAnchorsSproutMap &mapSproutAnchors, + CAnchorsSaplingMap &mapSaplingAnchors, CNullifiersMap &mapSproutNullifiers, CNullifiersMap saplingNullifiersMap) { return false; diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index b7f7f6efd..6f391b7ac 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -29,6 +29,7 @@ class CCoinsViewTest : public CCoinsView uint256 hashBestSaplingAnchor_; std::map map_; std::map mapSproutAnchors_; + std::map mapSaplingAnchors_; std::map mapSproutNullifiers_; std::map 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::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 { const std::map* mapToUse; @@ -130,6 +147,7 @@ public: const uint256& hashSproutAnchor, const uint256& hashSaplingAnchor, CAnchorsSproutMap& mapSproutAnchors, + CAnchorsSaplingMap& mapSaplingAnchors, CNullifiersMap& mapSproutNullifiers, CNullifiersMap& mapSaplingNullifiers) { @@ -152,12 +170,24 @@ public: } mapSproutAnchors.erase(it++); } + for (CAnchorsSaplingMap::iterator it = mapSaplingAnchors.begin(); it != mapSaplingAnchors.end(); ) { + if (it->second.entered) { + std::map::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(mapSaplingNullifiers, mapSaplingNullifiers_); mapCoins.clear(); mapSproutAnchors.clear(); + mapSaplingAnchors.clear(); hashBestBlock_ = hashBlock; hashBestSproutAnchor_ = hashSproutAnchor; hashBestSaplingAnchor_ = hashSaplingAnchor; @@ -177,6 +207,7 @@ public: // Manually recompute the dynamic usage of the whole data, and compare it. size_t ret = memusage::DynamicUsage(cacheCoins) + memusage::DynamicUsage(cacheSproutAnchors) + + memusage::DynamicUsage(cacheSaplingAnchors) + memusage::DynamicUsage(cacheSproutNullifiers) + memusage::DynamicUsage(cacheSaplingNullifiers); for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) {