2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2012-2015 The Bitcoin Core developers
|
2014-10-31 01:43:19 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-05 02:47:07 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "coins.h"
|
|
|
|
|
2015-05-04 01:31:11 +02:00
|
|
|
#include "memusage.h"
|
2014-07-09 17:25:09 +02:00
|
|
|
#include "random.h"
|
|
|
|
|
2013-11-05 02:47:07 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2014-10-31 01:43:19 +01:00
|
|
|
/**
|
|
|
|
* calculate number of bytes for the bitmask, and its number of non-zero bytes
|
|
|
|
* each bit in the bitmask represents the availability of one output, but the
|
|
|
|
* availabilities of the first two outputs are encoded separately
|
|
|
|
*/
|
2013-11-05 02:47:07 +01:00
|
|
|
void CCoins::CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) const {
|
|
|
|
unsigned int nLastUsedByte = 0;
|
|
|
|
for (unsigned int b = 0; 2+b*8 < vout.size(); b++) {
|
|
|
|
bool fZero = true;
|
|
|
|
for (unsigned int i = 0; i < 8 && 2+b*8+i < vout.size(); i++) {
|
|
|
|
if (!vout[2+b*8+i].IsNull()) {
|
|
|
|
fZero = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!fZero) {
|
|
|
|
nLastUsedByte = b + 1;
|
|
|
|
nNonzeroBytes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nBytes += nLastUsedByte;
|
|
|
|
}
|
|
|
|
|
2014-10-19 02:57:02 +02:00
|
|
|
bool CCoins::Spend(uint32_t nPos)
|
|
|
|
{
|
|
|
|
if (nPos >= vout.size() || vout[nPos].IsNull())
|
2013-11-05 02:47:07 +01:00
|
|
|
return false;
|
2014-10-19 02:57:02 +02:00
|
|
|
vout[nPos].SetNull();
|
2013-11-05 02:47:07 +01:00
|
|
|
Cleanup();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-19 16:42:48 +02:00
|
|
|
bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; }
|
|
|
|
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
|
2014-12-15 09:11:16 +01:00
|
|
|
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
|
2014-08-24 02:08:05 +02:00
|
|
|
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
|
2016-04-15 16:36:39 +02:00
|
|
|
CCoinsViewCursor *CCoinsView::Cursor() const { return 0; }
|
2013-11-05 02:47:07 +01:00
|
|
|
|
|
|
|
|
2014-09-24 03:19:04 +02:00
|
|
|
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
|
2014-07-19 16:42:48 +02:00
|
|
|
bool CCoinsViewBacked::GetCoins(const uint256 &txid, CCoins &coins) const { return base->GetCoins(txid, coins); }
|
|
|
|
bool CCoinsViewBacked::HaveCoins(const uint256 &txid) const { return base->HaveCoins(txid); }
|
|
|
|
uint256 CCoinsViewBacked::GetBestBlock() const { return base->GetBestBlock(); }
|
2013-11-05 02:47:07 +01:00
|
|
|
void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
|
2014-08-24 02:08:05 +02:00
|
|
|
bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); }
|
2016-04-15 16:36:39 +02:00
|
|
|
CCoinsViewCursor *CCoinsViewBacked::Cursor() const { return base->Cursor(); }
|
2013-11-05 02:47:07 +01:00
|
|
|
|
2017-10-12 10:13:48 +02:00
|
|
|
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
|
2014-07-09 17:25:09 +02:00
|
|
|
|
2015-05-04 01:31:11 +02:00
|
|
|
CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), hasModifier(false), cachedCoinsUsage(0) { }
|
2013-11-05 02:47:07 +01:00
|
|
|
|
2014-09-03 09:01:24 +02:00
|
|
|
CCoinsViewCache::~CCoinsViewCache()
|
|
|
|
{
|
|
|
|
assert(!hasModifier);
|
2013-11-05 02:47:07 +01:00
|
|
|
}
|
|
|
|
|
2015-05-04 01:31:11 +02:00
|
|
|
size_t CCoinsViewCache::DynamicMemoryUsage() const {
|
|
|
|
return memusage::DynamicUsage(cacheCoins) + cachedCoinsUsage;
|
|
|
|
}
|
|
|
|
|
2014-09-03 09:01:24 +02:00
|
|
|
CCoinsMap::const_iterator CCoinsViewCache::FetchCoins(const uint256 &txid) const {
|
2014-07-09 17:25:09 +02:00
|
|
|
CCoinsMap::iterator it = cacheCoins.find(txid);
|
|
|
|
if (it != cacheCoins.end())
|
2013-11-05 02:47:07 +01:00
|
|
|
return it;
|
|
|
|
CCoins tmp;
|
2014-09-03 09:37:47 +02:00
|
|
|
if (!base->GetCoins(txid, tmp))
|
2013-11-05 02:47:07 +01:00
|
|
|
return cacheCoins.end();
|
2014-09-03 09:37:47 +02:00
|
|
|
CCoinsMap::iterator ret = cacheCoins.insert(std::make_pair(txid, CCoinsCacheEntry())).first;
|
|
|
|
tmp.swap(ret->second.coins);
|
|
|
|
if (ret->second.coins.IsPruned()) {
|
|
|
|
// The parent only has an empty entry for this txid; we can consider our
|
|
|
|
// version as fresh.
|
|
|
|
ret->second.flags = CCoinsCacheEntry::FRESH;
|
|
|
|
}
|
2015-07-17 19:46:18 +02:00
|
|
|
cachedCoinsUsage += ret->second.coins.DynamicMemoryUsage();
|
2013-11-05 02:47:07 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-09-03 09:37:47 +02:00
|
|
|
bool CCoinsViewCache::GetCoins(const uint256 &txid, CCoins &coins) const {
|
|
|
|
CCoinsMap::const_iterator it = FetchCoins(txid);
|
|
|
|
if (it != cacheCoins.end()) {
|
|
|
|
coins = it->second.coins;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-07-19 16:42:48 +02:00
|
|
|
}
|
|
|
|
|
2014-09-03 09:01:24 +02:00
|
|
|
CCoinsModifier CCoinsViewCache::ModifyCoins(const uint256 &txid) {
|
|
|
|
assert(!hasModifier);
|
2014-09-03 09:37:47 +02:00
|
|
|
std::pair<CCoinsMap::iterator, bool> ret = cacheCoins.insert(std::make_pair(txid, CCoinsCacheEntry()));
|
2015-05-04 01:31:11 +02:00
|
|
|
size_t cachedCoinUsage = 0;
|
2014-09-03 09:01:24 +02:00
|
|
|
if (ret.second) {
|
2014-09-03 09:37:47 +02:00
|
|
|
if (!base->GetCoins(txid, ret.first->second.coins)) {
|
|
|
|
// The parent view does not have this entry; mark it as fresh.
|
|
|
|
ret.first->second.coins.Clear();
|
|
|
|
ret.first->second.flags = CCoinsCacheEntry::FRESH;
|
|
|
|
} else if (ret.first->second.coins.IsPruned()) {
|
|
|
|
// The parent view only has a pruned entry for this; mark it as fresh.
|
|
|
|
ret.first->second.flags = CCoinsCacheEntry::FRESH;
|
|
|
|
}
|
2015-05-04 01:31:11 +02:00
|
|
|
} else {
|
2015-07-17 19:46:18 +02:00
|
|
|
cachedCoinUsage = ret.first->second.coins.DynamicMemoryUsage();
|
2014-09-03 09:01:24 +02:00
|
|
|
}
|
2014-09-03 09:37:47 +02:00
|
|
|
// Assume that whenever ModifyCoins is called, the entry will be modified.
|
|
|
|
ret.first->second.flags |= CCoinsCacheEntry::DIRTY;
|
2015-05-04 01:31:11 +02:00
|
|
|
return CCoinsModifier(*this, ret.first, cachedCoinUsage);
|
2013-11-05 02:47:07 +01:00
|
|
|
}
|
|
|
|
|
2017-01-04 20:56:05 +01:00
|
|
|
/* ModifyNewCoins allows for faster coin modification when creating the new
|
|
|
|
* outputs from a transaction. It assumes that BIP 30 (no duplicate txids)
|
|
|
|
* applies and has already been tested for (or the test is not required due to
|
|
|
|
* BIP 34, height in coinbase). If we can assume BIP 30 then we know that any
|
|
|
|
* non-coinbase transaction we are adding to the UTXO must not already exist in
|
|
|
|
* the utxo unless it is fully spent. Thus we can check only if it exists DIRTY
|
|
|
|
* at the current level of the cache, in which case it is not safe to mark it
|
|
|
|
* FRESH (b/c then its spentness still needs to flushed). If it's not dirty and
|
|
|
|
* doesn't exist or is pruned in the current cache, we know it either doesn't
|
|
|
|
* exist or is pruned in parent caches, which is the definition of FRESH. The
|
|
|
|
* exception to this is the two historical violations of BIP 30 in the chain,
|
|
|
|
* both of which were coinbases. We do not mark these fresh so we we can ensure
|
|
|
|
* that they will still be properly overwritten when spent.
|
|
|
|
*/
|
2016-01-22 14:15:45 +01:00
|
|
|
CCoinsModifier CCoinsViewCache::ModifyNewCoins(const uint256 &txid, bool coinbase) {
|
2015-11-03 03:27:15 +01:00
|
|
|
assert(!hasModifier);
|
|
|
|
std::pair<CCoinsMap::iterator, bool> ret = cacheCoins.insert(std::make_pair(txid, CCoinsCacheEntry()));
|
2016-01-22 14:15:45 +01:00
|
|
|
if (!coinbase) {
|
2017-01-04 20:56:05 +01:00
|
|
|
// New coins must not already exist.
|
|
|
|
if (!ret.first->second.coins.IsPruned())
|
|
|
|
throw std::logic_error("ModifyNewCoins should not find pre-existing coins on a non-coinbase unless they are pruned!");
|
|
|
|
|
|
|
|
if (!(ret.first->second.flags & CCoinsCacheEntry::DIRTY)) {
|
|
|
|
// If the coin is known to be pruned (have no unspent outputs) in
|
|
|
|
// the current view and the cache entry is not dirty, we know the
|
|
|
|
// coin also must be pruned in the parent view as well, so it is safe
|
|
|
|
// to mark this fresh.
|
|
|
|
ret.first->second.flags |= CCoinsCacheEntry::FRESH;
|
|
|
|
}
|
2016-01-22 14:15:45 +01:00
|
|
|
}
|
2017-01-04 20:56:05 +01:00
|
|
|
ret.first->second.coins.Clear();
|
2015-11-03 03:27:15 +01:00
|
|
|
ret.first->second.flags |= CCoinsCacheEntry::DIRTY;
|
|
|
|
return CCoinsModifier(*this, ret.first, 0);
|
|
|
|
}
|
|
|
|
|
2014-09-02 21:21:15 +02:00
|
|
|
const CCoins* CCoinsViewCache::AccessCoins(const uint256 &txid) const {
|
|
|
|
CCoinsMap::const_iterator it = FetchCoins(txid);
|
|
|
|
if (it == cacheCoins.end()) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2014-09-03 09:37:47 +02:00
|
|
|
return &it->second.coins;
|
2014-09-02 21:21:15 +02:00
|
|
|
}
|
2014-07-19 16:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCoinsViewCache::HaveCoins(const uint256 &txid) const {
|
|
|
|
CCoinsMap::const_iterator it = FetchCoins(txid);
|
2014-07-10 17:35:22 +02:00
|
|
|
// We're using vtx.empty() instead of IsPruned here for performance reasons,
|
2014-10-31 01:43:19 +01:00
|
|
|
// as we only care about the case where a transaction was replaced entirely
|
2014-07-10 17:35:22 +02:00
|
|
|
// in a reorganization (which wipes vout entirely, as opposed to spending
|
|
|
|
// which just cleans individual outputs).
|
2014-09-03 09:37:47 +02:00
|
|
|
return (it != cacheCoins.end() && !it->second.coins.vout.empty());
|
2013-11-05 02:47:07 +01:00
|
|
|
}
|
|
|
|
|
2015-10-23 00:49:53 +02:00
|
|
|
bool CCoinsViewCache::HaveCoinsInCache(const uint256 &txid) const {
|
|
|
|
CCoinsMap::const_iterator it = cacheCoins.find(txid);
|
|
|
|
return it != cacheCoins.end();
|
|
|
|
}
|
|
|
|
|
2014-07-19 16:42:48 +02:00
|
|
|
uint256 CCoinsViewCache::GetBestBlock() const {
|
2014-12-15 09:11:16 +01:00
|
|
|
if (hashBlock.IsNull())
|
2013-11-05 02:47:07 +01:00
|
|
|
hashBlock = base->GetBestBlock();
|
|
|
|
return hashBlock;
|
|
|
|
}
|
|
|
|
|
2014-09-03 09:25:32 +02:00
|
|
|
void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
|
2013-11-05 02:47:07 +01:00
|
|
|
hashBlock = hashBlockIn;
|
|
|
|
}
|
|
|
|
|
2014-08-24 02:08:05 +02:00
|
|
|
bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn) {
|
2014-09-03 09:01:24 +02:00
|
|
|
assert(!hasModifier);
|
2014-08-24 02:08:05 +02:00
|
|
|
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
|
2014-09-03 09:37:47 +02:00
|
|
|
if (it->second.flags & CCoinsCacheEntry::DIRTY) { // Ignore non-dirty entries (optimization).
|
|
|
|
CCoinsMap::iterator itUs = cacheCoins.find(it->first);
|
|
|
|
if (itUs == cacheCoins.end()) {
|
2015-03-26 18:52:10 +01:00
|
|
|
// The parent cache does not have an entry, while the child does
|
|
|
|
// We can ignore it if it's both FRESH and pruned in the child
|
|
|
|
if (!(it->second.flags & CCoinsCacheEntry::FRESH && it->second.coins.IsPruned())) {
|
|
|
|
// Otherwise we will need to create it in the parent
|
|
|
|
// and move the data up and mark it as dirty
|
2014-09-03 09:37:47 +02:00
|
|
|
CCoinsCacheEntry& entry = cacheCoins[it->first];
|
|
|
|
entry.coins.swap(it->second.coins);
|
2015-07-17 19:46:18 +02:00
|
|
|
cachedCoinsUsage += entry.coins.DynamicMemoryUsage();
|
2015-03-26 18:52:10 +01:00
|
|
|
entry.flags = CCoinsCacheEntry::DIRTY;
|
|
|
|
// We can mark it FRESH in the parent if it was FRESH in the child
|
|
|
|
// Otherwise it might have just been flushed from the parent's cache
|
|
|
|
// and already exist in the grandparent
|
|
|
|
if (it->second.flags & CCoinsCacheEntry::FRESH)
|
|
|
|
entry.flags |= CCoinsCacheEntry::FRESH;
|
2014-09-03 09:37:47 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-26 18:52:10 +01:00
|
|
|
// Found the entry in the parent cache
|
2014-09-03 09:37:47 +02:00
|
|
|
if ((itUs->second.flags & CCoinsCacheEntry::FRESH) && it->second.coins.IsPruned()) {
|
|
|
|
// The grandparent does not have an entry, and the child is
|
|
|
|
// modified and being pruned. This means we can just delete
|
|
|
|
// it from the parent.
|
2015-07-17 19:46:18 +02:00
|
|
|
cachedCoinsUsage -= itUs->second.coins.DynamicMemoryUsage();
|
2014-09-03 09:37:47 +02:00
|
|
|
cacheCoins.erase(itUs);
|
|
|
|
} else {
|
|
|
|
// A normal modification.
|
2015-07-17 19:46:18 +02:00
|
|
|
cachedCoinsUsage -= itUs->second.coins.DynamicMemoryUsage();
|
2014-09-03 09:37:47 +02:00
|
|
|
itUs->second.coins.swap(it->second.coins);
|
2015-07-17 19:46:18 +02:00
|
|
|
cachedCoinsUsage += itUs->second.coins.DynamicMemoryUsage();
|
2014-09-03 09:37:47 +02:00
|
|
|
itUs->second.flags |= CCoinsCacheEntry::DIRTY;
|
2017-01-04 20:56:05 +01:00
|
|
|
// NOTE: It is possible the child has a FRESH flag here in
|
|
|
|
// the event the entry we found in the parent is pruned. But
|
|
|
|
// we must not copy that FRESH flag to the parent as that
|
|
|
|
// pruned state likely still needs to be communicated to the
|
|
|
|
// grandparent.
|
2014-09-03 09:37:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-24 02:08:05 +02:00
|
|
|
CCoinsMap::iterator itOld = it++;
|
|
|
|
mapCoins.erase(itOld);
|
|
|
|
}
|
2013-11-05 02:47:07 +01:00
|
|
|
hashBlock = hashBlockIn;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCoinsViewCache::Flush() {
|
|
|
|
bool fOk = base->BatchWrite(cacheCoins, hashBlock);
|
2014-08-24 02:08:05 +02:00
|
|
|
cacheCoins.clear();
|
2015-05-04 01:31:11 +02:00
|
|
|
cachedCoinsUsage = 0;
|
2013-11-05 02:47:07 +01:00
|
|
|
return fOk;
|
|
|
|
}
|
|
|
|
|
2015-10-22 02:41:40 +02:00
|
|
|
void CCoinsViewCache::Uncache(const uint256& hash)
|
|
|
|
{
|
|
|
|
CCoinsMap::iterator it = cacheCoins.find(hash);
|
|
|
|
if (it != cacheCoins.end() && it->second.flags == 0) {
|
|
|
|
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
|
|
|
|
cacheCoins.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-19 16:42:48 +02:00
|
|
|
unsigned int CCoinsViewCache::GetCacheSize() const {
|
2013-11-05 02:47:07 +01:00
|
|
|
return cacheCoins.size();
|
|
|
|
}
|
|
|
|
|
2014-07-19 16:42:48 +02:00
|
|
|
const CTxOut &CCoinsViewCache::GetOutputFor(const CTxIn& input) const
|
2013-11-05 02:47:07 +01:00
|
|
|
{
|
2014-09-02 21:21:15 +02:00
|
|
|
const CCoins* coins = AccessCoins(input.prevout.hash);
|
|
|
|
assert(coins && coins->IsAvailable(input.prevout.n));
|
|
|
|
return coins->vout[input.prevout.n];
|
2013-11-05 02:47:07 +01:00
|
|
|
}
|
|
|
|
|
2014-04-23 00:46:19 +02:00
|
|
|
CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
|
2013-11-05 02:47:07 +01:00
|
|
|
{
|
|
|
|
if (tx.IsCoinBase())
|
|
|
|
return 0;
|
|
|
|
|
2014-04-23 00:46:19 +02:00
|
|
|
CAmount nResult = 0;
|
2013-11-05 02:47:07 +01:00
|
|
|
for (unsigned int i = 0; i < tx.vin.size(); i++)
|
|
|
|
nResult += GetOutputFor(tx.vin[i]).nValue;
|
|
|
|
|
|
|
|
return nResult;
|
|
|
|
}
|
|
|
|
|
2014-07-19 16:42:48 +02:00
|
|
|
bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
|
2013-11-05 02:47:07 +01:00
|
|
|
{
|
|
|
|
if (!tx.IsCoinBase()) {
|
|
|
|
for (unsigned int i = 0; i < tx.vin.size(); i++) {
|
|
|
|
const COutPoint &prevout = tx.vin[i].prevout;
|
2014-09-02 21:21:15 +02:00
|
|
|
const CCoins* coins = AccessCoins(prevout.hash);
|
|
|
|
if (!coins || !coins->IsAvailable(prevout.n)) {
|
2013-11-05 02:47:07 +01:00
|
|
|
return false;
|
2014-09-02 21:21:15 +02:00
|
|
|
}
|
2013-11-05 02:47:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-11 08:35:14 +01:00
|
|
|
|
2015-11-13 16:05:21 +01:00
|
|
|
double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight, CAmount &inChainInputValue) const
|
2013-11-11 08:35:14 +01:00
|
|
|
{
|
2015-11-13 16:05:21 +01:00
|
|
|
inChainInputValue = 0;
|
2013-11-11 08:35:14 +01:00
|
|
|
if (tx.IsCoinBase())
|
|
|
|
return 0.0;
|
|
|
|
double dResult = 0.0;
|
|
|
|
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
|
|
|
{
|
2014-09-02 21:21:15 +02:00
|
|
|
const CCoins* coins = AccessCoins(txin.prevout.hash);
|
|
|
|
assert(coins);
|
|
|
|
if (!coins->IsAvailable(txin.prevout.n)) continue;
|
2015-11-13 16:05:21 +01:00
|
|
|
if (coins->nHeight <= nHeight) {
|
2014-09-02 21:21:15 +02:00
|
|
|
dResult += coins->vout[txin.prevout.n].nValue * (nHeight-coins->nHeight);
|
2015-11-13 16:05:21 +01:00
|
|
|
inChainInputValue += coins->vout[txin.prevout.n].nValue;
|
2013-11-11 08:35:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return tx.ComputePriority(dResult);
|
|
|
|
}
|
2014-09-03 09:01:24 +02:00
|
|
|
|
2015-05-04 01:31:11 +02:00
|
|
|
CCoinsModifier::CCoinsModifier(CCoinsViewCache& cache_, CCoinsMap::iterator it_, size_t usage) : cache(cache_), it(it_), cachedCoinUsage(usage) {
|
2015-01-04 17:15:02 +01:00
|
|
|
assert(!cache.hasModifier);
|
|
|
|
cache.hasModifier = true;
|
|
|
|
}
|
2014-09-03 09:01:24 +02:00
|
|
|
|
2014-09-03 09:37:47 +02:00
|
|
|
CCoinsModifier::~CCoinsModifier()
|
|
|
|
{
|
2014-09-03 09:01:24 +02:00
|
|
|
assert(cache.hasModifier);
|
|
|
|
cache.hasModifier = false;
|
2014-09-03 09:37:47 +02:00
|
|
|
it->second.coins.Cleanup();
|
2015-05-04 01:31:11 +02:00
|
|
|
cache.cachedCoinsUsage -= cachedCoinUsage; // Subtract the old usage
|
2014-09-03 09:37:47 +02:00
|
|
|
if ((it->second.flags & CCoinsCacheEntry::FRESH) && it->second.coins.IsPruned()) {
|
|
|
|
cache.cacheCoins.erase(it);
|
2015-05-04 01:31:11 +02:00
|
|
|
} else {
|
|
|
|
// If the coin still exists after the modification, add the new usage
|
2015-07-17 19:46:18 +02:00
|
|
|
cache.cachedCoinsUsage += it->second.coins.DynamicMemoryUsage();
|
2014-09-03 09:37:47 +02:00
|
|
|
}
|
2014-09-03 09:01:24 +02:00
|
|
|
}
|
2016-04-15 16:36:39 +02:00
|
|
|
|
|
|
|
CCoinsViewCursor::~CCoinsViewCursor()
|
|
|
|
{
|
|
|
|
}
|