Merge pull request #4834
7c70438Get rid of the dummy CCoinsViewCache constructor arg (Pieter Wuille)ed27e53Add coins_tests with a large randomized CCoinViewCache test. (Pieter Wuille)058b08cDo not keep fully spent but unwritten CCoins entries cached. (Pieter Wuille)c9d1a81Get rid of CCoinsView's SetCoins and SetBestBlock. (Pieter Wuille)f28aec0Use ModifyCoins instead of mutable GetCoins. (Pieter Wuille)
This commit is contained in:
23
src/txdb.cpp
23
src/txdb.cpp
@@ -33,12 +33,6 @@ bool CCoinsViewDB::GetCoins(const uint256 &txid, CCoins &coins) const {
|
||||
return db.Read(make_pair('c', txid), coins);
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::SetCoins(const uint256 &txid, const CCoins &coins) {
|
||||
CLevelDBBatch batch;
|
||||
BatchWriteCoins(batch, txid, coins);
|
||||
return db.WriteBatch(batch);
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::HaveCoins(const uint256 &txid) const {
|
||||
return db.Exists(make_pair('c', txid));
|
||||
}
|
||||
@@ -50,24 +44,23 @@ uint256 CCoinsViewDB::GetBestBlock() const {
|
||||
return hashBestChain;
|
||||
}
|
||||
|
||||
bool CCoinsViewDB::SetBestBlock(const uint256 &hashBlock) {
|
||||
CLevelDBBatch batch;
|
||||
BatchWriteHashBestChain(batch, hashBlock);
|
||||
return db.WriteBatch(batch);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user