diff --git a/src/coins.cpp b/src/coins.cpp index 8db1600c7..b9a74e712 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -200,68 +200,19 @@ CNameIterator* CCoinsViewCache::IterateNames() const { name history. */ void CCoinsViewCache::SetName(const valtype &nameSpace, const valtype &key, const CKevaData& data, bool undo) { -#if 0 - CKevaData oldData; - if (GetName(nameSpace, key, oldData)) { - cacheNames.removeExpireIndex(name, oldData.getHeight()); - - /* Update the name history. If we are undoing, we expect that - the top history item matches the data being set now. If we - are not undoing, push the overwritten data onto the history stack. - Note that we only have to do this if the name already existed - in the database. Otherwise, no special action is required - for the name history. */ - if (fNameHistory) - { - CNameHistory history; - if (!GetNameHistory(name, history)) - { - /* Ensure that the history stack is indeed (still) empty - and was not modified by the failing GetNameHistory call. */ - assert(history.empty()); - } - - if (undo) - history.pop(data); - else - history.push(oldData); - - cacheNames.setHistory(name, history); - } - } else { - assert (!undo); - } -#endif CKevaData namespaceData; if (GetNamespace(nameSpace, namespaceData)) { namespaceData.setUpdateOutpoint(data.getUpdateOutpoint()); cacheNames.setNamespace(nameSpace, namespaceData); } cacheNames.set(nameSpace, key, data); -#if 0 - cacheNames.addExpireIndex(name, data.getHeight()); -#endif } void CCoinsViewCache::DeleteName(const valtype &nameSpace, const valtype &key) { CKevaData oldData; - if (GetName(nameSpace, key, oldData)) { -#if 0 - cacheNames.removeExpireIndex(name, oldData.getHeight()); -#endif - } - else + if (!GetName(nameSpace, key, oldData)) { assert(false); - -#if 0 - if (fNameHistory) - { - /* When deleting a name, the history should already be clean. */ - CNameHistory history; - assert (!GetNameHistory(name, history) || history.empty()); } -#endif - cacheNames.remove(nameSpace, key); } diff --git a/src/keva/common.cpp b/src/keva/common.cpp index 718d11a4f..3992c27c9 100644 --- a/src/keva/common.cpp +++ b/src/keva/common.cpp @@ -210,11 +210,10 @@ void CKevaCache::set(const valtype& nameSpace, const valtype& key, const CKevaData& data) { auto name = std::make_tuple(nameSpace, key); -#if 0 - const std::set::iterator di = deleted.find(name); - if (di != deleted.end ()) + const std::set::iterator di = deleted.find(name); + if (di != deleted.end()) { deleted.erase (di); -#endif + } const EntryMap::iterator ei = entries.find(name); if (ei != entries.end ()) @@ -227,15 +226,11 @@ void CKevaCache::remove(const valtype& nameSpace, const valtype& key) { auto name = std::make_tuple(nameSpace, key); - const EntryMap::iterator ei = entries.find (name); - if (ei != entries.end ()) - entries.erase (ei); + const EntryMap::iterator ei = entries.find(name); + if (ei != entries.end()) + entries.erase(ei); - //JWU TODO: make sure to remove namespace registration when - // the corresponding block is disconnected!!! -#if 0 deleted.insert(name); -#endif } CNameIterator* @@ -244,91 +239,21 @@ CKevaCache::iterateNames(CNameIterator* base) const return new CCacheNameIterator (*this, base); } -#if 0 -bool -CKevaCache::getHistory (const valtype& name, CNameHistory& res) const -{ - assert (fNameHistory); - - const std::map::const_iterator i = history.find (name); - if (i == history.end ()) - return false; - - res = i->second; - return true; -} - -void -CKevaCache::setHistory (const valtype& name, const CNameHistory& data) -{ - assert (fNameHistory); - - const std::map::iterator ei = history.find (name); - if (ei != history.end ()) - ei->second = data; - else - history.insert (std::make_pair (name, data)); -} -#endif - void CKevaCache::updateNamesForHeight (unsigned nHeight, std::set& names) const { /* Seek in the map of cached entries to the first one corresponding to our height. */ - -#if 0 - const ExpireEntry seekEntry(nHeight, valtype ()); - std::map::const_iterator it; - - for (it = expireIndex.lower_bound (seekEntry); it != expireIndex.end (); ++it) - { - const ExpireEntry& cur = it->first; - assert (cur.nHeight >= nHeight); - if (cur.nHeight > nHeight) - break; - - if (it->second) - names.insert (cur.name); - else - names.erase (cur.name); - } -#endif } -#if 0 -void -CKevaCache::addExpireIndex (const valtype& name, unsigned height) -{ - const ExpireEntry entry(height, name); - expireIndex[entry] = true; -} - -void -CKevaCache::removeExpireIndex (const valtype& name, unsigned height) -{ - const ExpireEntry entry(height, name); - expireIndex[entry] = false; -} -#endif - void CKevaCache::apply(const CKevaCache& cache) { for (EntryMap::const_iterator i = cache.entries.begin(); i != cache.entries.end(); ++i) { set(std::get<0>(i->first), std::get<1>(i->first), i->second); } -#if 0 - for (std::set::const_iterator i = cache.deleted.begin(); i != cache.deleted.end(); ++i) { - remove(*i); - } - - for (std::map::const_iterator i - = cache.history.begin (); i != cache.history.end (); ++i) - setHistory (i->first, i->second); - for (std::map::const_iterator i - = cache.expireIndex.begin (); i != cache.expireIndex.end (); ++i) - expireIndex[i->first] = i->second; -#endif + for (std::set::const_iterator i = cache.deleted.begin(); i != cache.deleted.end(); ++i) { + remove(std::get<0>(*i), std::get<1>(*i)); + } } diff --git a/src/keva/common.h b/src/keva/common.h index 01a8c678a..d2e22153b 100644 --- a/src/keva/common.h +++ b/src/keva/common.h @@ -310,107 +310,21 @@ private: public: - /** - * Type for expire-index entries. We have to make sure that - * it is serialised in such a way that ordering is done correctly - * by height. This is not true if we use a std::pair, since then - * the height is serialised as byte-array with little-endian order, - * which does not correspond to the ordering by actual value. - */ -#if 0 - class ExpireEntry - { - public: - - unsigned nHeight; - valtype name; - - inline ExpireEntry () - : nHeight(0), name() - {} - - inline ExpireEntry (unsigned h, const valtype& n) - : nHeight(h), name(n) - {} - - /* Default copy and assignment. */ - - template - inline void - Serialize (Stream& s) const - { - /* Flip the byte order of nHeight to big endian. */ - const uint32_t nHeightFlipped = htobe32 (nHeight); - - ::Serialize (s, nHeightFlipped); - ::Serialize (s, name); - } - - template - inline void - Unserialize (Stream& s) - { - uint32_t nHeightFlipped; - - ::Unserialize (s, nHeightFlipped); - ::Unserialize (s, name); - - /* Unflip the byte order. */ - nHeight = be32toh (nHeightFlipped); - } - - friend inline bool - operator== (const ExpireEntry& a, const ExpireEntry& b) - { - return a.nHeight == b.nHeight && a.name == b.name; - } - - friend inline bool - operator!= (const ExpireEntry& a, const ExpireEntry& b) - { - return !(a == b); - } - - friend inline bool - operator< (const ExpireEntry& a, const ExpireEntry& b) - { - if (a.nHeight != b.nHeight) - return a.nHeight < b.nHeight; - - return a.name < b.name; - } - - }; -#endif - /** * Type of name entry map. This is public because it is also used * by the unit tests. */ typedef std::map, CKevaData, NameComparator> EntryMap; + typedef std::tuple NamespaceKeyType; + private: /** New or updated names. */ EntryMap entries; - /** Deleted names. */ - std::set deleted; - -#if 0 - /** - * New or updated history stacks. If they are empty, the corresponding - * database entry is deleted instead. - */ - std::map history; -#endif -#if 0 - /** - * Changes to be performed to the expire index. The entry is mapped - * to either "true" (meaning to add it) or "false" (delete). - */ - std::map expireIndex; -#endif + /** Deleted names. */ + std::set deleted; friend class CCacheNameIterator; @@ -421,10 +335,6 @@ public: { entries.clear (); deleted.clear (); -#if 0 - history.clear (); - expireIndex.clear (); -#endif } /** @@ -436,10 +346,7 @@ public: inline bool empty () const { - if (entries.empty () && deleted.empty ()) { -#if 0 - assert (history.empty () && expireIndex.empty ()); -#endif + if (entries.empty() && deleted.empty()) { return true; } @@ -450,11 +357,8 @@ public: inline bool isDeleted (const valtype& nameSpace, const valtype& key) const { -#if 0 + auto name = std::make_tuple(nameSpace, key); return (deleted.count(name) > 0); -#else - return false; -#endif } /* Try to get a name's associated data. This looks only @@ -477,37 +381,12 @@ public: ownership of. */ CNameIterator* iterateNames (CNameIterator* base) const; -#if 0 - /** - * Query for an history entry. - * @param name The name to look up. - * @param res Put the resulting history entry here. - * @return True iff the name was found in the cache. - */ - bool getHistory (const valtype& name, CNameHistory& res) const; - - /** - * Set a name history entry. - * @param name The name to modify. - * @param data The new history entry. - */ - void setHistory (const valtype& name, const CNameHistory& data); -#endif - /* Query the cached changes to the expire index. In particular, for a given height and a given set of names that were indexed to this update height, apply possible changes to the set that are represented by the cached expire index changes. */ void updateNamesForHeight (unsigned nHeight, std::set& names) const; -#if 0 - /* Add an expire-index entry. */ - void addExpireIndex (const valtype& name, unsigned height); - - /* Remove an expire-index entry. */ - void removeExpireIndex (const valtype& name, unsigned height); -#endif - /* Apply all the changes in the passed-in record on top of this one. */ void apply (const CKevaCache& cache); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 467bf5b04..b2c1040e6 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -441,11 +441,13 @@ UniValue getblocktemplate(const JSONRPCRequest& request) if(!g_connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); +#if 0 if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Kevacoin is not connected!"); if (IsInitialBlockDownload()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Kevacoin is downloading blocks..."); +#endif static unsigned int nTransactionsUpdatedLast; diff --git a/src/txdb.cpp b/src/txdb.cpp index 0a3d8c214..972915552 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -348,26 +348,10 @@ void CKevaCache::writeBatch (CDBBatch& batch) const batch.Write(std::make_pair(DB_NAME, name), i->second); } -#if 0 - for (std::set::const_iterator i = deleted.begin(); i != deleted.end(); ++i) { - batch.Erase(std::make_pair (DB_NAME, *i)); + for (std::set::const_iterator i = deleted.begin(); i != deleted.end(); ++i) { + std::pair name = std::make_pair(std::get<0>(*i), std::get<1>(*i)); + batch.Erase(std::make_pair(DB_NAME, name)); } - - assert (fNameHistory || history.empty ()); - for (std::map::const_iterator i = history.begin (); - i != history.end (); ++i) - if (i->second.empty ()) - batch.Erase (std::make_pair (DB_NAME_HISTORY, i->first)); - else - batch.Write (std::make_pair (DB_NAME_HISTORY, i->first), i->second); - - for (std::map::const_iterator i = expireIndex.begin (); - i != expireIndex.end (); ++i) - if (i->second) - batch.Write (std::make_pair (DB_NAME_EXPIRY, i->first)); - else - batch.Erase (std::make_pair (DB_NAME_EXPIRY, i->first)); -#endif } bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) { diff --git a/src/validation.cpp b/src/validation.cpp index c0eaf1ece..61bb08146 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1654,9 +1654,9 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI } // undo keva operations in reverse order - std::vector::const_reverse_iterator nameUndoIter; - for (nameUndoIter = blockUndo.vkevaundo.rbegin (); nameUndoIter != blockUndo.vkevaundo.rend (); ++nameUndoIter) { - nameUndoIter->apply (view); + std::vector::const_reverse_iterator kevaUndoIter; + for (kevaUndoIter = blockUndo.vkevaundo.rbegin(); kevaUndoIter != blockUndo.vkevaundo.rend(); ++kevaUndoIter) { + kevaUndoIter->apply(view); } // move best block pointer to prevout block