From 3a8e1d0cf43ae3d3eae2943dc8d0fd085cb31e3d Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 28 Aug 2017 14:02:27 +0100 Subject: [PATCH] Refactor Zcash changes to CCoinsViewDB To match upstream changes. --- src/txdb.cpp | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 3ca19a356..297777781 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -31,29 +31,6 @@ static const char DB_REINDEX_FLAG = 'R'; static const char DB_LAST_BLOCK = 'l'; -void static BatchWriteAnchor(CLevelDBBatch &batch, - const uint256 &croot, - const ZCIncrementalMerkleTree &tree, - const bool &entered) -{ - if (!entered) - batch.Erase(make_pair(DB_ANCHOR, croot)); - else { - batch.Write(make_pair(DB_ANCHOR, croot), tree); - } -} - -void static BatchWriteNullifier(CLevelDBBatch &batch, const uint256 &nf, const bool &entered) { - if (!entered) - batch.Erase(make_pair(DB_NULLIFIER, nf)); - else - batch.Write(make_pair(DB_NULLIFIER, nf), true); -} - -void static BatchWriteHashBestAnchor(CLevelDBBatch &batch, const uint256 &hash) { - batch.Write(DB_BEST_ANCHOR, hash); -} - CCoinsViewDB::CCoinsViewDB(std::string dbName, size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / dbName, nCacheSize, fMemory, fWipe) { } @@ -126,7 +103,11 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, for (CAnchorsMap::iterator it = mapAnchors.begin(); it != mapAnchors.end();) { if (it->second.flags & CAnchorsCacheEntry::DIRTY) { - BatchWriteAnchor(batch, it->first, it->second.tree, it->second.entered); + if (!it->second.entered) + batch.Erase(make_pair(DB_ANCHOR, it->first)); + else { + batch.Write(make_pair(DB_ANCHOR, it->first), it->second.tree); + } // TODO: changed++? } CAnchorsMap::iterator itOld = it++; @@ -135,7 +116,10 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, for (CNullifiersMap::iterator it = mapNullifiers.begin(); it != mapNullifiers.end();) { if (it->second.flags & CNullifiersCacheEntry::DIRTY) { - BatchWriteNullifier(batch, it->first, it->second.entered); + if (!it->second.entered) + batch.Erase(make_pair(DB_NULLIFIER, it->first)); + else + batch.Write(make_pair(DB_NULLIFIER, it->first), true); // TODO: changed++? } CNullifiersMap::iterator itOld = it++; @@ -145,7 +129,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, if (!hashBlock.IsNull()) batch.Write(DB_BEST_BLOCK, hashBlock); if (!hashAnchor.IsNull()) - BatchWriteHashBestAnchor(batch, hashAnchor); + batch.Write(DB_BEST_ANCHOR, hashAnchor); LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count); return db.WriteBatch(batch);