diff --git a/src/coins.cpp b/src/coins.cpp index 0559a8820..87b00a226 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -43,7 +43,7 @@ bool CCoins::Spend(uint32_t nPos) return true; } bool CCoinsView::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const { return false; } -bool CCoinsView::GetNullifier(const uint256 &nullifier, NullifierType type) const { return false; } +bool CCoinsView::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return false; } bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; } bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; } uint256 CCoinsView::GetBestBlock() const { return uint256(); } @@ -60,7 +60,7 @@ bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; } CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { } bool CCoinsViewBacked::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const { return base->GetAnchorAt(rt, tree); } -bool CCoinsViewBacked::GetNullifier(const uint256 &nullifier, NullifierType type) const { return base->GetNullifier(nullifier, type); } +bool CCoinsViewBacked::GetNullifier(const uint256 &nullifier, ShieldedType type) const { return base->GetNullifier(nullifier, type); } bool CCoinsViewBacked::GetCoins(const uint256 &txid, CCoins &coins) const { return base->GetCoins(txid, coins); } bool CCoinsViewBacked::HaveCoins(const uint256 &txid) const { return base->HaveCoins(txid); } uint256 CCoinsViewBacked::GetBestBlock() const { return base->GetBestBlock(); } @@ -133,13 +133,13 @@ bool CCoinsViewCache::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tr return true; } -bool CCoinsViewCache::GetNullifier(const uint256 &nullifier, NullifierType type) const { +bool CCoinsViewCache::GetNullifier(const uint256 &nullifier, ShieldedType type) const { CNullifiersMap* cacheToUse; switch (type) { - case SPROUT_NULLIFIER: + case SPROUT: cacheToUse = &cacheSproutNullifiers; break; - case SAPLING_NULLIFIER: + case SAPLING: cacheToUse = &cacheSaplingNullifiers; break; default: @@ -430,7 +430,7 @@ bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const { BOOST_FOREACH(const uint256& nullifier, joinsplit.nullifiers) { - if (GetNullifier(nullifier, SPROUT_NULLIFIER)) { + if (GetNullifier(nullifier, SPROUT)) { // If the nullifier is set, this transaction // double-spends! return false; @@ -454,7 +454,7 @@ bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const } for (const SpendDescription &spendDescription : tx.vShieldedSpend) { - if (GetNullifier(spendDescription.nullifier, SAPLING_NULLIFIER)) // Prevent double spends + if (GetNullifier(spendDescription.nullifier, SAPLING)) // Prevent double spends return false; } diff --git a/src/coins.h b/src/coins.h index e2b454649..a796c9bfb 100644 --- a/src/coins.h +++ b/src/coins.h @@ -298,10 +298,10 @@ struct CNullifiersCacheEntry CNullifiersCacheEntry() : entered(false), flags(0) {} }; -enum NullifierType +enum ShieldedType { - SPROUT_NULLIFIER, - SAPLING_NULLIFIER, + SPROUT, + SAPLING, }; typedef boost::unordered_map CCoinsMap; @@ -330,7 +330,7 @@ public: virtual bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const; //! Determine whether a nullifier is spent or not - virtual bool GetNullifier(const uint256 &nullifier, NullifierType type) const; + virtual bool GetNullifier(const uint256 &nullifier, ShieldedType type) const; //! Retrieve the CCoins (unspent transaction outputs) for a given txid virtual bool GetCoins(const uint256 &txid, CCoins &coins) const; @@ -371,7 +371,7 @@ protected: public: CCoinsViewBacked(CCoinsView *viewIn); bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const; - bool GetNullifier(const uint256 &nullifier, NullifierType type) const; + bool GetNullifier(const uint256 &nullifier, ShieldedType type) const; bool GetCoins(const uint256 &txid, CCoins &coins) const; bool HaveCoins(const uint256 &txid) const; uint256 GetBestBlock() const; @@ -437,7 +437,7 @@ public: // Standard CCoinsView methods bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const; - bool GetNullifier(const uint256 &nullifier, NullifierType type) const; + bool GetNullifier(const uint256 &nullifier, ShieldedType type) const; bool GetCoins(const uint256 &txid, CCoins &coins) const; bool HaveCoins(const uint256 &txid) const; uint256 GetBestBlock() const; diff --git a/src/gtest/test_mempool.cpp b/src/gtest/test_mempool.cpp index 981c4eb08..2a74ea9b3 100644 --- a/src/gtest/test_mempool.cpp +++ b/src/gtest/test_mempool.cpp @@ -23,7 +23,7 @@ public: return false; } - bool GetNullifier(const uint256 &nf, NullifierType type) const { + bool GetNullifier(const uint256 &nf, ShieldedType type) const { return false; } diff --git a/src/gtest/test_validation.cpp b/src/gtest/test_validation.cpp index 710e3c600..cabeeb3a7 100644 --- a/src/gtest/test_validation.cpp +++ b/src/gtest/test_validation.cpp @@ -25,7 +25,7 @@ public: return false; } - bool GetNullifier(const uint256 &nf, NullifierType type) const { + bool GetNullifier(const uint256 &nf, ShieldedType type) const { return false; } diff --git a/src/main.cpp b/src/main.cpp index bca80c31a..95c8b094a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1305,13 +1305,13 @@ 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)) { return false; } } } for (const SpendDescription &spendDescription : tx.vShieldedSpend) { - if (pool.nullifierExists(spendDescription.nullifier, SAPLING_NULLIFIER)) { + if (pool.nullifierExists(spendDescription.nullifier, SAPLING)) { return false; } } diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index ae147ea08..2767112e6 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -52,14 +52,14 @@ public: } } - bool GetNullifier(const uint256 &nf, NullifierType type) const + bool GetNullifier(const uint256 &nf, ShieldedType type) const { const std::map* mapToUse; switch (type) { - case SPROUT_NULLIFIER: + case SPROUT: mapToUse = &mapSproutNullifiers_; break; - case SAPLING_NULLIFIER: + case SAPLING: mapToUse = &mapSaplingNullifiers_; break; default: @@ -215,11 +215,11 @@ BOOST_FIXTURE_TEST_SUITE(coins_tests, BasicTestingSetup) void checkNullifierCache(const CCoinsViewCacheTest &cache, const TxWithNullifiers &txWithNullifiers, bool shouldBeInCache) { // Make sure the nullifiers have not gotten mixed up - BOOST_CHECK(!cache.GetNullifier(txWithNullifiers.sproutNullifier, SAPLING_NULLIFIER)); - BOOST_CHECK(!cache.GetNullifier(txWithNullifiers.saplingNullifier, SPROUT_NULLIFIER)); + BOOST_CHECK(!cache.GetNullifier(txWithNullifiers.sproutNullifier, SAPLING)); + BOOST_CHECK(!cache.GetNullifier(txWithNullifiers.saplingNullifier, SPROUT)); // Check if the nullifiers either are or are not in the cache - bool containsSproutNullifier = cache.GetNullifier(txWithNullifiers.sproutNullifier, SPROUT_NULLIFIER); - bool containsSaplingNullifier = cache.GetNullifier(txWithNullifiers.saplingNullifier, SAPLING_NULLIFIER); + bool containsSproutNullifier = cache.GetNullifier(txWithNullifiers.sproutNullifier, SPROUT); + bool containsSaplingNullifier = cache.GetNullifier(txWithNullifiers.saplingNullifier, SAPLING); BOOST_CHECK(containsSproutNullifier == shouldBeInCache); BOOST_CHECK(containsSaplingNullifier == shouldBeInCache); } diff --git a/src/txdb.cpp b/src/txdb.cpp index 2c2f0faaf..eb3617fc6 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -52,14 +52,14 @@ bool CCoinsViewDB::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) return read; } -bool CCoinsViewDB::GetNullifier(const uint256 &nf, NullifierType type) const { +bool CCoinsViewDB::GetNullifier(const uint256 &nf, ShieldedType type) const { bool spent = false; char dbChar; switch (type) { - case SPROUT_NULLIFIER: + case SPROUT: dbChar = DB_NULLIFIER; break; - case SAPLING_NULLIFIER: + case SAPLING: dbChar = DB_SAPLING_NULLIFIER; break; default: diff --git a/src/txdb.h b/src/txdb.h index 53f3c31c6..99ff4f31f 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -36,7 +36,7 @@ public: CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false); bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const; - bool GetNullifier(const uint256 &nf, NullifierType type) const; + bool GetNullifier(const uint256 &nf, ShieldedType type) const; bool GetCoins(const uint256 &txid, CCoins &coins) const; bool HaveCoins(const uint256 &txid) const; uint256 GetBestBlock() const; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 850851aad..6fde29f40 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -394,7 +394,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { - assert(!pcoins->GetNullifier(nf, SPROUT_NULLIFIER)); + assert(!pcoins->GetNullifier(nf, SPROUT)); } ZCIncrementalMerkleTree tree; @@ -413,7 +413,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const intermediates.insert(std::make_pair(tree.root(), tree)); } for (const SpendDescription &spendDescription : tx.vShieldedSpend) { - assert(!pcoins->GetNullifier(spendDescription.nullifier, SAPLING_NULLIFIER)); + assert(!pcoins->GetNullifier(spendDescription.nullifier, SAPLING)); } if (fDependsWait) waitingOnDependants.push_back(&(*it)); @@ -452,21 +452,21 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const assert(it->first == it->second.ptx->vin[it->second.n].prevout); } - checkNullifiers(SPROUT_NULLIFIER); - checkNullifiers(SAPLING_NULLIFIER); + checkNullifiers(SPROUT); + checkNullifiers(SAPLING); assert(totalTxSize == checkTotal); assert(innerUsage == cachedInnerUsage); } -void CTxMemPool::checkNullifiers(NullifierType type) const +void CTxMemPool::checkNullifiers(ShieldedType type) const { const std::map* mapToUse; switch (type) { - case SPROUT_NULLIFIER: + case SPROUT: mapToUse = &mapSproutNullifiers; break; - case SAPLING_NULLIFIER: + case SAPLING: mapToUse = &mapSaplingNullifiers; break; default: @@ -582,12 +582,12 @@ bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const return true; } -bool CTxMemPool::nullifierExists(const uint256& nullifier, NullifierType type) const +bool CTxMemPool::nullifierExists(const uint256& nullifier, ShieldedType type) const { switch (type) { - case SPROUT_NULLIFIER: + case SPROUT: return mapSproutNullifiers.count(nullifier); - case SAPLING_NULLIFIER: + case SAPLING: return mapSaplingNullifiers.count(nullifier); default: throw runtime_error("Unknown nullifier type"); @@ -596,7 +596,7 @@ bool CTxMemPool::nullifierExists(const uint256& nullifier, NullifierType type) c CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { } -bool CCoinsViewMemPool::GetNullifier(const uint256 &nf, NullifierType type) const +bool CCoinsViewMemPool::GetNullifier(const uint256 &nf, ShieldedType type) const { return mempool.nullifierExists(nf, type) || base->GetNullifier(nf, type); } diff --git a/src/txmempool.h b/src/txmempool.h index 0397c6d7f..f37636efb 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -134,7 +134,7 @@ private: std::map mapSproutNullifiers; std::map mapSaplingNullifiers; - void checkNullifiers(NullifierType type) const; + void checkNullifiers(ShieldedType type) const; public: typedef boost::multi_index_container< @@ -192,7 +192,7 @@ public: void ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta); void ClearPrioritisation(const uint256 hash); - bool nullifierExists(const uint256& nullifier, NullifierType type) const; + bool nullifierExists(const uint256& nullifier, ShieldedType type) const; unsigned long size() { @@ -243,7 +243,7 @@ protected: public: CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn); - bool GetNullifier(const uint256 &txid, NullifierType type) const; + bool GetNullifier(const uint256 &txid, ShieldedType type) const; bool GetCoins(const uint256 &txid, CCoins &coins) const; bool HaveCoins(const uint256 &txid) const; }; diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 53d433c86..1567ad01e 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -366,7 +366,7 @@ public: return false; } - bool GetNullifier(const uint256 &nf, NullifierType type) const { + bool GetNullifier(const uint256 &nf, ShieldedType type) const { return false; }