aboutsummaryrefslogtreecommitdiff
path: root/src/txdb.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-09-03 09:37:47 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-09-23 22:29:43 +0200
commit058b08c147a6d56b57221faa5b6fcdb83b4140b2 (patch)
treec8a44779f36d1c2b7a0fe41287eeddecb4aa4e77 /src/txdb.cpp
parentc9d1a81ce76737a73c9706e074a4fe8440c8277e (diff)
Do not keep fully spent but unwritten CCoins entries cached.
Instead of storing CCoins entries directly in CCoinsMap, store a CCoinsCacheEntry which additionally keeps track of whether a particular entry is: * dirty: potentially different from its parent view. * fresh: the parent view is known to not have a non-pruned version. This allows us to skip non-dirty cache entries when pushing batches of changes up, and to remove CCoins entries about transactions that are fully spent before the parent cache learns about them.
Diffstat (limited to 'src/txdb.cpp')
-rw-r--r--src/txdb.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 3b353ab624..89830ced73 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -45,17 +45,22 @@ uint256 CCoinsViewDB::GetBestBlock() const {
}
bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
- LogPrint("coindb", "Committing %u changed transactions to coin database...\n", (unsigned int)mapCoins.size());
-
CLevelDBBatch batch;
+ size_t count = 0;
+ size_t changed = 0;
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
- BatchWriteCoins(batch, it->first, it->second);
+ if (it->second.flags & CCoinsCacheEntry::DIRTY) {
+ BatchWriteCoins(batch, it->first, it->second.coins);
+ changed++;
+ }
+ count++;
CCoinsMap::iterator itOld = it++;
mapCoins.erase(itOld);
}
if (hashBlock != uint256(0))
BatchWriteHashBestChain(batch, hashBlock);
+ LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
return db.WriteBatch(batch);
}