From 9e511dbbdd36c7c467d9882f37b2976fe93cbcae Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Thu, 14 Jul 2016 17:02:39 -0600 Subject: [PATCH] Rename CSerialsCacheEntry. --- src/coins.cpp | 38 +++++++++++++++++++------------------- src/coins.h | 22 +++++++++++----------- src/test/coins_tests.cpp | 18 +++++++++--------- src/txdb.cpp | 2 +- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index f7a205bb8..d60269962 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -41,7 +41,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 &serial) const { return false; } +bool CCoinsView::GetNullifier(const uint256 &nullifier) 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(); } @@ -57,7 +57,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 &serial) const { return base->GetNullifier(serial); } +bool CCoinsViewBacked::GetNullifier(const uint256 &nullifier) const { return base->GetNullifier(nullifier); } 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(); } @@ -128,16 +128,16 @@ bool CCoinsViewCache::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tr return true; } -bool CCoinsViewCache::GetNullifier(const uint256 &serial) const { - CNullifiersMap::iterator it = cacheNullifiers.find(serial); +bool CCoinsViewCache::GetNullifier(const uint256 &nullifier) const { + CNullifiersMap::iterator it = cacheNullifiers.find(nullifier); if (it != cacheNullifiers.end()) return it->second.entered; - CSerialsCacheEntry entry; - bool tmp = base->GetNullifier(serial); + CNullifiersCacheEntry entry; + bool tmp = base->GetNullifier(nullifier); entry.entered = tmp; - cacheNullifiers.insert(std::make_pair(serial, entry)); + cacheNullifiers.insert(std::make_pair(nullifier, entry)); return tmp; } @@ -185,10 +185,10 @@ void CCoinsViewCache::PopAnchor(const uint256 &newrt) { } } -void CCoinsViewCache::SetNullifier(const uint256 &serial, bool spent) { - std::pair ret = cacheNullifiers.insert(std::make_pair(serial, CSerialsCacheEntry())); +void CCoinsViewCache::SetNullifier(const uint256 &nullifier, bool spent) { + std::pair ret = cacheNullifiers.insert(std::make_pair(nullifier, CNullifiersCacheEntry())); ret.first->second.entered = spent; - ret.first->second.flags |= CSerialsCacheEntry::DIRTY; + ret.first->second.flags |= CNullifiersCacheEntry::DIRTY; } bool CCoinsViewCache::GetCoins(const uint256 &txid, CCoins &coins) const { @@ -328,22 +328,22 @@ bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, for (CNullifiersMap::iterator child_it = mapNullifiers.begin(); child_it != mapNullifiers.end();) { - if (child_it->second.flags & CSerialsCacheEntry::DIRTY) { // Ignore non-dirty entries (optimization). + if (child_it->second.flags & CNullifiersCacheEntry::DIRTY) { // Ignore non-dirty entries (optimization). CNullifiersMap::iterator parent_it = cacheNullifiers.find(child_it->first); if (parent_it == cacheNullifiers.end()) { if (child_it->second.entered) { - // Parent doesn't have an entry, but child has a SPENT serial. - // Move the spent serial up. + // Parent doesn't have an entry, but child has a SPENT nullifier. + // Move the spent nullifier up. - CSerialsCacheEntry& entry = cacheNullifiers[child_it->first]; + CNullifiersCacheEntry& entry = cacheNullifiers[child_it->first]; entry.entered = true; - entry.flags = CSerialsCacheEntry::DIRTY; + entry.flags = CNullifiersCacheEntry::DIRTY; } } else { if (parent_it->second.entered != child_it->second.entered) { parent_it->second.entered = child_it->second.entered; - parent_it->second.flags |= CSerialsCacheEntry::DIRTY; + parent_it->second.flags |= CNullifiersCacheEntry::DIRTY; } } } @@ -396,10 +396,10 @@ bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { - BOOST_FOREACH(const uint256& serial, joinsplit.nullifiers) + BOOST_FOREACH(const uint256& nullifier, joinsplit.nullifiers) { - if (GetNullifier(serial)) { - // If the serial is set, this transaction + if (GetNullifier(nullifier)) { + // If the nullifier is set, this transaction // double-spends! return false; } diff --git a/src/coins.h b/src/coins.h index f92529f4b..af78782e5 100644 --- a/src/coins.h +++ b/src/coins.h @@ -309,21 +309,21 @@ struct CAnchorsCacheEntry CAnchorsCacheEntry() : entered(false), flags(0) {} }; -struct CSerialsCacheEntry +struct CNullifiersCacheEntry { - bool entered; // If the serial is spent or not + bool entered; // If the nullifier is spent or not unsigned char flags; enum Flags { DIRTY = (1 << 0), // This cache entry is potentially different from the version in the parent view. }; - CSerialsCacheEntry() : entered(false), flags(0) {} + CNullifiersCacheEntry() : entered(false), flags(0) {} }; typedef boost::unordered_map CCoinsMap; typedef boost::unordered_map CAnchorsMap; -typedef boost::unordered_map CNullifiersMap; +typedef boost::unordered_map CNullifiersMap; struct CCoinsStats { @@ -346,8 +346,8 @@ public: //! Retrieve the tree at a particular anchored root in the chain virtual bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const; - //! Determine whether a serial is spent or not - virtual bool GetNullifier(const uint256 &serial) const; + //! Determine whether a nullifier is spent or not + virtual bool GetNullifier(const uint256 &nullifier) const; //! Retrieve the CCoins (unspent transaction outputs) for a given txid virtual bool GetCoins(const uint256 &txid, CCoins &coins) const; @@ -387,7 +387,7 @@ protected: public: CCoinsViewBacked(CCoinsView *viewIn); bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const; - bool GetNullifier(const uint256 &serial) const; + bool GetNullifier(const uint256 &nullifier) const; bool GetCoins(const uint256 &txid, CCoins &coins) const; bool HaveCoins(const uint256 &txid) const; uint256 GetBestBlock() const; @@ -451,7 +451,7 @@ public: // Standard CCoinsView methods bool GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree) const; - bool GetNullifier(const uint256 &serial) const; + bool GetNullifier(const uint256 &nullifier) const; bool GetCoins(const uint256 &txid, CCoins &coins) const; bool HaveCoins(const uint256 &txid) const; uint256 GetBestBlock() const; @@ -472,8 +472,8 @@ public: // the new current root. void PopAnchor(const uint256 &rt); - // Marks a serial as spent or not. - void SetNullifier(const uint256 &serial, bool spent); + // Marks a nullifier as spent or not. + void SetNullifier(const uint256 &nullifier, bool spent); /** * Return a pointer to CCoins in the cache, or NULL if not found. This is @@ -515,7 +515,7 @@ public: //! Check whether all prevouts of the transaction are present in the UTXO set represented by this view bool HaveInputs(const CTransaction& tx) const; - //! Check whether all joinsplit requirements (anchors/serials) are satisfied + //! Check whether all joinsplit requirements (anchors/nullifiers) are satisfied bool HaveJoinSplitRequirements(const CTransaction& tx) const; //! Return priority of tx at height nHeight diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 6ca42ca6b..97fe5a167 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -163,28 +163,28 @@ uint256 appendRandomCommitment(ZCIncrementalMerkleTree &tree) BOOST_FIXTURE_TEST_SUITE(coins_tests, BasicTestingSetup) -BOOST_AUTO_TEST_CASE(serials_test) +BOOST_AUTO_TEST_CASE(nullifiers_test) { CCoinsViewTest base; CCoinsViewCacheTest cache(&base); - uint256 myserial = GetRandHash(); + uint256 nf = GetRandHash(); - BOOST_CHECK(!cache.GetNullifier(myserial)); - cache.SetNullifier(myserial, true); - BOOST_CHECK(cache.GetNullifier(myserial)); + BOOST_CHECK(!cache.GetNullifier(nf)); + cache.SetNullifier(nf, true); + BOOST_CHECK(cache.GetNullifier(nf)); cache.Flush(); CCoinsViewCacheTest cache2(&base); - BOOST_CHECK(cache2.GetNullifier(myserial)); - cache2.SetNullifier(myserial, false); - BOOST_CHECK(!cache2.GetNullifier(myserial)); + BOOST_CHECK(cache2.GetNullifier(nf)); + cache2.SetNullifier(nf, false); + BOOST_CHECK(!cache2.GetNullifier(nf)); cache2.Flush(); CCoinsViewCacheTest cache3(&base); - BOOST_CHECK(!cache3.GetNullifier(myserial)); + BOOST_CHECK(!cache3.GetNullifier(nf)); } BOOST_AUTO_TEST_CASE(anchors_flush_test) diff --git a/src/txdb.cpp b/src/txdb.cpp index df02c4a5a..accbd47e4 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -138,7 +138,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, } for (CNullifiersMap::iterator it = mapNullifiers.begin(); it != mapNullifiers.end();) { - if (it->second.flags & CSerialsCacheEntry::DIRTY) { + if (it->second.flags & CNullifiersCacheEntry::DIRTY) { BatchWriteSerial(batch, it->first, it->second.entered); // TODO: changed++? }