Refactor leveldbwrapper

Was "Add chainstate obfuscation to avoid spurious antivirus detection"

Zcash: Extracted the refactor, omitting the chainstate obfuscation.
This commit is contained in:
James O'Beirne
2015-09-07 15:22:23 -07:00
committed by Jack Grigg
parent 3055fd5508
commit 0d81464be7
5 changed files with 74 additions and 14 deletions

View File

@@ -50,17 +50,6 @@ void static BatchWriteNullifier(CLevelDBBatch &batch, const uint256 &nf, const b
batch.Write(make_pair(DB_NULLIFIER, nf), true);
}
void static BatchWriteCoins(CLevelDBBatch &batch, const uint256 &hash, const CCoins &coins) {
if (coins.IsPruned())
batch.Erase(make_pair(DB_COINS, hash));
else
batch.Write(make_pair(DB_COINS, hash), coins);
}
void static BatchWriteHashBestChain(CLevelDBBatch &batch, const uint256 &hash) {
batch.Write(DB_BEST_BLOCK, hash);
}
void static BatchWriteHashBestAnchor(CLevelDBBatch &batch, const uint256 &hash) {
batch.Write(DB_BEST_ANCHOR, hash);
}
@@ -68,7 +57,8 @@ void static BatchWriteHashBestAnchor(CLevelDBBatch &batch, const uint256 &hash)
CCoinsViewDB::CCoinsViewDB(std::string dbName, size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / dbName, nCacheSize, fMemory, fWipe) {
}
CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe) {
CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe)
{
}
@@ -123,7 +113,10 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
size_t changed = 0;
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
if (it->second.flags & CCoinsCacheEntry::DIRTY) {
BatchWriteCoins(batch, it->first, it->second.coins);
if (it->second.coins.IsPruned())
batch.Erase(make_pair(DB_COINS, it->first));
else
batch.Write(make_pair(DB_COINS, it->first), it->second.coins);
changed++;
}
count++;
@@ -150,7 +143,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
}
if (!hashBlock.IsNull())
BatchWriteHashBestChain(batch, hashBlock);
batch.Write(DB_BEST_BLOCK, hashBlock);
if (!hashAnchor.IsNull())
BatchWriteHashBestAnchor(batch, hashAnchor);