diff --git a/src/coins.cpp b/src/coins.cpp index a8e270fc5..f291cea2d 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -52,7 +52,7 @@ bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers) { return false; } bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; } @@ -70,8 +70,8 @@ bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, - CNullifiersMap &mapSaplingNullifiers) { return base->BatchWrite(mapCoins, hashBlock, hashAnchor, mapAnchors, mapNullifiers, mapSaplingNullifiers); } + CNullifiersMap &mapSproutNullifiers, + CNullifiersMap &mapSaplingNullifiers) { return base->BatchWrite(mapCoins, hashBlock, hashAnchor, mapAnchors, mapSproutNullifiers, mapSaplingNullifiers); } bool CCoinsViewBacked::GetStats(CCoinsStats &stats) const { return base->GetStats(stats); } CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {} @@ -86,7 +86,7 @@ CCoinsViewCache::~CCoinsViewCache() size_t CCoinsViewCache::DynamicMemoryUsage() const { return memusage::DynamicUsage(cacheCoins) + memusage::DynamicUsage(cacheAnchors) + - memusage::DynamicUsage(cacheNullifiers) + + memusage::DynamicUsage(cacheSproutNullifiers) + memusage::DynamicUsage(cacheSaplingNullifiers) + cachedCoinsUsage; } @@ -137,7 +137,7 @@ bool CCoinsViewCache::GetNullifier(const uint256 &nullifier, NullifierType type) CNullifiersMap* cacheToUse; switch (type) { case SPROUT_NULLIFIER: - cacheToUse = &cacheNullifiers; + cacheToUse = &cacheSproutNullifiers; break; case SAPLING_NULLIFIER: cacheToUse = &cacheSaplingNullifiers; @@ -213,7 +213,7 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) { void CCoinsViewCache::SetNullifiers(const CTransaction& tx, bool spent) { for (const JSDescription &joinsplit : tx.vjoinsplit) { for (const uint256 &nullifier : joinsplit.nullifiers) { - std::pair ret = cacheNullifiers.insert(std::make_pair(nullifier, CNullifiersCacheEntry())); + std::pair ret = cacheSproutNullifiers.insert(std::make_pair(nullifier, CNullifiersCacheEntry())); ret.first->second.entered = spent; ret.first->second.flags |= CNullifiersCacheEntry::DIRTY; } @@ -316,7 +316,7 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn, const uint256 &hashAnchorIn, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers) { assert(!hasModifier); for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) { @@ -379,7 +379,7 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, mapAnchors.erase(itOld); } - ::BatchWriteNullifiers(mapNullifiers, cacheNullifiers); + ::BatchWriteNullifiers(mapSproutNullifiers, cacheSproutNullifiers); ::BatchWriteNullifiers(mapSaplingNullifiers, cacheSaplingNullifiers); hashAnchor = hashAnchorIn; @@ -388,10 +388,10 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, } bool CCoinsViewCache::Flush() { - bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheAnchors, cacheNullifiers, cacheSaplingNullifiers); + bool fOk = base->BatchWrite(cacheCoins, hashBlock, hashAnchor, cacheAnchors, cacheSproutNullifiers, cacheSaplingNullifiers); cacheCoins.clear(); cacheAnchors.clear(); - cacheNullifiers.clear(); + cacheSproutNullifiers.clear(); cacheSaplingNullifiers.clear(); cachedCoinsUsage = 0; return fOk; diff --git a/src/coins.h b/src/coins.h index 7fffa8dab..e2b454649 100644 --- a/src/coins.h +++ b/src/coins.h @@ -351,7 +351,7 @@ public: const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers); //! Calculate statistics about the unspent transaction output set @@ -381,7 +381,7 @@ public: const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers); bool GetStats(CCoinsStats &stats) const; }; @@ -425,7 +425,7 @@ protected: mutable CCoinsMap cacheCoins; mutable uint256 hashAnchor; mutable CAnchorsMap cacheAnchors; - mutable CNullifiersMap cacheNullifiers; + mutable CNullifiersMap cacheSproutNullifiers; mutable CNullifiersMap cacheSaplingNullifiers; /* Cached dynamic memory usage for the inner CCoins objects. */ @@ -447,7 +447,7 @@ public: const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers); @@ -459,7 +459,7 @@ public: // the new current root. void PopAnchor(const uint256 &rt); - // Marks a nullifiers for a given transaction as spent or not. + // Marks nullifiers for a given transaction as spent or not. void SetNullifiers(const CTransaction& tx, bool spent); /** diff --git a/src/gtest/test_mempool.cpp b/src/gtest/test_mempool.cpp index 4203cf6f1..981c4eb08 100644 --- a/src/gtest/test_mempool.cpp +++ b/src/gtest/test_mempool.cpp @@ -56,7 +56,7 @@ public: const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers) { return false; } diff --git a/src/gtest/test_validation.cpp b/src/gtest/test_validation.cpp index d321e11e0..710e3c600 100644 --- a/src/gtest/test_validation.cpp +++ b/src/gtest/test_validation.cpp @@ -51,7 +51,7 @@ public: const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap saplingNullifiersMap) { return false; } diff --git a/src/main.cpp b/src/main.cpp index 9d7e38099..784d5e09b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1270,13 +1270,15 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { - if (pool.nullifierExists(nf, SPROUT_NULLIFIER)) + if (pool.nullifierExists(nf, SPROUT_NULLIFIER)) { return false; + } } } for (const SpendDescription &spendDescription : tx.vShieldedSpend) { - if (pool.nullifierExists(spendDescription.nullifier, SAPLING_NULLIFIER)) + if (pool.nullifierExists(spendDescription.nullifier, SAPLING_NULLIFIER)) { return false; + } } } diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 2d29338ce..8225fce5d 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -28,7 +28,7 @@ class CCoinsViewTest : public CCoinsView uint256 hashBestAnchor_; std::map map_; std::map mapAnchors_; - std::map mapNullifiers_; + std::map mapSproutNullifiers_; std::map mapSaplingNullifiers_; public: @@ -57,7 +57,7 @@ public: const std::map* mapToUse; switch (type) { case SPROUT_NULLIFIER: - mapToUse = &mapNullifiers_; + mapToUse = &mapSproutNullifiers_; break; case SAPLING_NULLIFIER: mapToUse = &mapSaplingNullifiers_; @@ -116,7 +116,7 @@ public: const uint256& hashBlock, const uint256& hashAnchor, CAnchorsMap& mapAnchors, - CNullifiersMap& mapNullifiers, + CNullifiersMap& mapSproutNullifiers, CNullifiersMap& mapSaplingNullifiers) { for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); ) { @@ -139,7 +139,7 @@ public: mapAnchors.erase(it++); } - BatchWriteNullifiers(mapNullifiers, mapNullifiers_); + BatchWriteNullifiers(mapSproutNullifiers, mapSproutNullifiers_); BatchWriteNullifiers(mapSaplingNullifiers, mapSaplingNullifiers_); mapCoins.clear(); @@ -162,7 +162,7 @@ public: // Manually recompute the dynamic usage of the whole data, and compare it. size_t ret = memusage::DynamicUsage(cacheCoins) + memusage::DynamicUsage(cacheAnchors) + - memusage::DynamicUsage(cacheNullifiers) + + memusage::DynamicUsage(cacheSproutNullifiers) + memusage::DynamicUsage(cacheSaplingNullifiers); for (CCoinsMap::iterator it = cacheCoins.begin(); it != cacheCoins.end(); it++) { ret += it->second.coins.DynamicMemoryUsage(); diff --git a/src/txdb.cpp b/src/txdb.cpp index 715f295f7..4759ff106 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -109,7 +109,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers) { CDBBatch batch(db); size_t count = 0; @@ -140,7 +140,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, mapAnchors.erase(itOld); } - ::BatchWriteNullifiers(batch, mapNullifiers, DB_NULLIFIER); + ::BatchWriteNullifiers(batch, mapSproutNullifiers, DB_NULLIFIER); ::BatchWriteNullifiers(batch, mapSaplingNullifiers, DB_SAPLING_NULLIFIER); if (!hashBlock.IsNull()) diff --git a/src/txdb.h b/src/txdb.h index 01bc576fc..53f3c31c6 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -45,7 +45,7 @@ public: const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap &mapSaplingNullifiers); bool GetStats(CCoinsStats &stats) const; }; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 626bd9df6..9480d81cd 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -107,7 +107,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i); BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { - mapNullifiers[nf] = &tx; + mapSproutNullifiers[nf] = &tx; } } for (const SpendDescription &spendDescription : tx.vShieldedSpend) { @@ -121,6 +121,7 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, return true; } + void CTxMemPool::remove(const CTransaction &origTx, std::list& removed, bool fRecursive) { // Remove transaction from memory pool @@ -159,7 +160,7 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list& rem mapNextTx.erase(txin.prevout); BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256& nf, joinsplit.nullifiers) { - mapNullifiers.erase(nf); + mapSproutNullifiers.erase(nf); } } for (const SpendDescription &spendDescription : tx.vShieldedSpend) { @@ -248,11 +249,12 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { - std::map::iterator it = mapNullifiers.find(nf); - if (it != mapNullifiers.end()) { + std::map::iterator it = mapSproutNullifiers.find(nf); + if (it != mapSproutNullifiers.end()) { const CTransaction &txConflict = *it->second; - if (txConflict != tx) + if (txConflict != tx) { remove(txConflict, removed, true); + } } } } @@ -260,8 +262,9 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list std::map::iterator it = mapSaplingNullifiers.find(spendDescription.nullifier); if (it != mapSaplingNullifiers.end()) { const CTransaction &txConflict = *it->second; - if (txConflict != tx) + if (txConflict != tx) { remove(txConflict, removed, true); + } } } } @@ -461,7 +464,7 @@ void CTxMemPool::checkNullifiers(NullifierType type) const const std::map* mapToUse; switch (type) { case SPROUT_NULLIFIER: - mapToUse = &mapNullifiers; + mapToUse = &mapSproutNullifiers; break; case SAPLING_NULLIFIER: mapToUse = &mapSaplingNullifiers; @@ -583,7 +586,7 @@ bool CTxMemPool::nullifierExists(const uint256& nullifier, NullifierType type) c { switch (type) { case SPROUT_NULLIFIER: - return mapNullifiers.count(nullifier); + return mapSproutNullifiers.count(nullifier); case SAPLING_NULLIFIER: return mapSaplingNullifiers.count(nullifier); default: diff --git a/src/txmempool.h b/src/txmempool.h index 1b5b3e6b0..0397c6d7f 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -131,7 +131,7 @@ private: uint64_t totalTxSize = 0; //! sum of all mempool tx' byte sizes uint64_t cachedInnerUsage; //! sum of dynamic memory usage of all the map elements (NOT the maps themselves) - std::map mapNullifiers; + std::map mapSproutNullifiers; std::map mapSaplingNullifiers; void checkNullifiers(NullifierType type) const; @@ -154,7 +154,7 @@ public: indexed_transaction_set mapTx; std::map mapNextTx; std::map > mapDeltas; - + CTxMemPool(const CFeeRate& _minRelayFee); ~CTxMemPool(); diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 236a22686..1d4ad78c8 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -382,7 +382,7 @@ public: const uint256 &hashBlock, const uint256 &hashAnchor, CAnchorsMap &mapAnchors, - CNullifiersMap &mapNullifiers, + CNullifiersMap &mapSproutNullifiers, CNullifiersMap& mapSaplingNullifiers) { return false; }