2021-12-30 18:36:57 +01:00
|
|
|
// Copyright (c) 2012-2021 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.
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <coins.h>
|
2013-11-05 02:47:07 +01:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <consensus/consensus.h>
|
2019-03-27 19:17:13 +01:00
|
|
|
#include <logging.h>
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <random.h>
|
2021-09-03 18:38:53 +02:00
|
|
|
#include <util/trace.h>
|
2018-08-24 23:48:23 +02:00
|
|
|
#include <version.h>
|
2014-07-09 17:25:09 +02:00
|
|
|
|
2017-05-31 02:58:54 +02:00
|
|
|
bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return false; }
|
2014-12-15 09:11:16 +01:00
|
|
|
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
|
2017-04-19 18:34:30 +02:00
|
|
|
std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); }
|
2014-08-24 02:08:05 +02:00
|
|
|
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
|
2021-06-16 22:27:20 +02:00
|
|
|
std::unique_ptr<CCoinsViewCursor> CCoinsView::Cursor() const { return nullptr; }
|
2013-11-05 02:47:07 +01:00
|
|
|
|
2017-06-13 21:17:30 +02:00
|
|
|
bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
|
|
|
|
{
|
|
|
|
Coin coin;
|
|
|
|
return GetCoin(outpoint, coin);
|
|
|
|
}
|
2013-11-05 02:47:07 +01:00
|
|
|
|
2014-09-24 03:19:04 +02:00
|
|
|
CCoinsViewBacked::CCoinsViewBacked(CCoinsView *viewIn) : base(viewIn) { }
|
2017-05-31 02:58:54 +02:00
|
|
|
bool CCoinsViewBacked::GetCoin(const COutPoint &outpoint, Coin &coin) const { return base->GetCoin(outpoint, coin); }
|
|
|
|
bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { return base->HaveCoin(outpoint); }
|
2014-07-19 16:42:48 +02:00
|
|
|
uint256 CCoinsViewBacked::GetBestBlock() const { return base->GetBestBlock(); }
|
2017-04-19 18:34:30 +02:00
|
|
|
std::vector<uint256> CCoinsViewBacked::GetHeadBlocks() const { return base->GetHeadBlocks(); }
|
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); }
|
2021-06-16 22:27:20 +02:00
|
|
|
std::unique_ptr<CCoinsViewCursor> CCoinsViewBacked::Cursor() const { return base->Cursor(); }
|
2017-05-13 00:19:19 +02:00
|
|
|
size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
|
2013-11-05 02:47:07 +01:00
|
|
|
|
2017-04-25 20:29:39 +02:00
|
|
|
CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), cachedCoinsUsage(0) {}
|
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;
|
|
|
|
}
|
|
|
|
|
2017-05-31 02:58:54 +02:00
|
|
|
CCoinsMap::iterator CCoinsViewCache::FetchCoin(const COutPoint &outpoint) const {
|
2017-04-25 20:29:39 +02:00
|
|
|
CCoinsMap::iterator it = cacheCoins.find(outpoint);
|
2014-07-09 17:25:09 +02:00
|
|
|
if (it != cacheCoins.end())
|
2013-11-05 02:47:07 +01:00
|
|
|
return it;
|
2017-04-25 20:29:39 +02:00
|
|
|
Coin tmp;
|
2017-05-31 02:58:54 +02:00
|
|
|
if (!base->GetCoin(outpoint, tmp))
|
2013-11-05 02:47:07 +01:00
|
|
|
return cacheCoins.end();
|
2017-04-25 20:29:39 +02:00
|
|
|
CCoinsMap::iterator ret = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::forward_as_tuple(std::move(tmp))).first;
|
2017-05-31 02:58:54 +02:00
|
|
|
if (ret->second.coin.IsSpent()) {
|
2017-04-25 20:29:39 +02:00
|
|
|
// The parent only has an empty entry for this outpoint; we can consider our
|
2014-09-03 09:37:47 +02:00
|
|
|
// version as fresh.
|
|
|
|
ret->second.flags = CCoinsCacheEntry::FRESH;
|
|
|
|
}
|
2017-05-04 09:15:36 +02:00
|
|
|
cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage();
|
2013-11-05 02:47:07 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-05-31 02:58:54 +02:00
|
|
|
bool CCoinsViewCache::GetCoin(const COutPoint &outpoint, Coin &coin) const {
|
|
|
|
CCoinsMap::const_iterator it = FetchCoin(outpoint);
|
2014-09-03 09:37:47 +02:00
|
|
|
if (it != cacheCoins.end()) {
|
2017-05-04 09:15:36 +02:00
|
|
|
coin = it->second.coin;
|
2017-06-13 21:17:30 +02:00
|
|
|
return !coin.IsSpent();
|
2014-09-03 09:37:47 +02:00
|
|
|
}
|
|
|
|
return false;
|
2014-07-19 16:42:48 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 20:29:29 +02:00
|
|
|
void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) {
|
2017-05-31 02:58:54 +02:00
|
|
|
assert(!coin.IsSpent());
|
2017-04-25 20:29:29 +02:00
|
|
|
if (coin.out.scriptPubKey.IsUnspendable()) return;
|
|
|
|
CCoinsMap::iterator it;
|
|
|
|
bool inserted;
|
2017-04-25 20:29:39 +02:00
|
|
|
std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
|
2017-04-25 20:29:29 +02:00
|
|
|
bool fresh = false;
|
|
|
|
if (!inserted) {
|
2017-05-04 09:15:36 +02:00
|
|
|
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
|
2017-04-25 20:29:29 +02:00
|
|
|
}
|
|
|
|
if (!possible_overwrite) {
|
2017-05-31 02:58:54 +02:00
|
|
|
if (!it->second.coin.IsSpent()) {
|
2020-01-30 21:52:36 +01:00
|
|
|
throw std::logic_error("Attempted to overwrite an unspent coin (when possible_overwrite is false)");
|
2017-04-25 20:29:29 +02:00
|
|
|
}
|
2020-01-30 21:52:36 +01:00
|
|
|
// If the coin exists in this cache as a spent coin and is DIRTY, then
|
|
|
|
// its spentness hasn't been flushed to the parent cache. We're
|
|
|
|
// re-adding the coin to this cache now but we can't mark it as FRESH.
|
|
|
|
// If we mark it FRESH and then spend it before the cache is flushed
|
|
|
|
// we would remove it from this cache and would never flush spentness
|
|
|
|
// to the parent cache.
|
|
|
|
//
|
|
|
|
// Re-adding a spent coin can happen in the case of a re-org (the coin
|
|
|
|
// is 'spent' when the block adding it is disconnected and then
|
|
|
|
// re-added when it is also added in a newly connected block).
|
|
|
|
//
|
|
|
|
// If the coin doesn't exist in the current cache, or is spent but not
|
|
|
|
// DIRTY, then it can be marked FRESH.
|
2017-04-25 20:29:39 +02:00
|
|
|
fresh = !(it->second.flags & CCoinsCacheEntry::DIRTY);
|
2017-04-25 20:29:29 +02:00
|
|
|
}
|
2017-05-04 09:15:36 +02:00
|
|
|
it->second.coin = std::move(coin);
|
2017-04-25 20:29:29 +02:00
|
|
|
it->second.flags |= CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0);
|
2017-05-04 09:15:36 +02:00
|
|
|
cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
|
2021-09-03 18:38:53 +02:00
|
|
|
TRACE5(utxocache, add,
|
|
|
|
outpoint.hash.data(),
|
|
|
|
(uint32_t)outpoint.n,
|
|
|
|
(uint32_t)coin.nHeight,
|
|
|
|
(int64_t)coin.out.nValue,
|
|
|
|
(bool)coin.IsCoinBase());
|
2017-04-25 20:29:29 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 19:50:23 +02:00
|
|
|
void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coin) {
|
|
|
|
cachedCoinsUsage += coin.DynamicMemoryUsage();
|
|
|
|
cacheCoins.emplace(
|
|
|
|
std::piecewise_construct,
|
|
|
|
std::forward_as_tuple(std::move(outpoint)),
|
|
|
|
std::forward_as_tuple(std::move(coin), CCoinsCacheEntry::DIRTY));
|
|
|
|
}
|
|
|
|
|
2020-03-23 15:45:34 +01:00
|
|
|
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
|
2017-04-25 20:29:29 +02:00
|
|
|
bool fCoinbase = tx.IsCoinBase();
|
|
|
|
const uint256& txid = tx.GetHash();
|
|
|
|
for (size_t i = 0; i < tx.vout.size(); ++i) {
|
2020-03-23 15:45:34 +01:00
|
|
|
bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
|
|
|
|
// Coinbase transactions can always be overwritten, in order to correctly
|
2017-06-06 15:03:36 +02:00
|
|
|
// deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
|
2017-04-19 18:34:30 +02:00
|
|
|
cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
|
2017-04-25 20:29:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 17:50:47 +02:00
|
|
|
bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
|
2017-05-31 02:58:54 +02:00
|
|
|
CCoinsMap::iterator it = FetchCoin(outpoint);
|
2017-06-05 17:50:47 +02:00
|
|
|
if (it == cacheCoins.end()) return false;
|
2017-05-04 09:15:36 +02:00
|
|
|
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
|
2021-09-03 18:38:53 +02:00
|
|
|
TRACE5(utxocache, spent,
|
|
|
|
outpoint.hash.data(),
|
|
|
|
(uint32_t)outpoint.n,
|
|
|
|
(uint32_t)it->second.coin.nHeight,
|
|
|
|
(int64_t)it->second.coin.out.nValue,
|
|
|
|
(bool)it->second.coin.IsCoinBase());
|
2017-04-25 20:29:39 +02:00
|
|
|
if (moveout) {
|
2017-05-04 09:15:36 +02:00
|
|
|
*moveout = std::move(it->second.coin);
|
2017-04-25 20:29:29 +02:00
|
|
|
}
|
2017-04-25 20:29:39 +02:00
|
|
|
if (it->second.flags & CCoinsCacheEntry::FRESH) {
|
2017-04-25 20:29:29 +02:00
|
|
|
cacheCoins.erase(it);
|
|
|
|
} else {
|
|
|
|
it->second.flags |= CCoinsCacheEntry::DIRTY;
|
2017-05-04 09:15:36 +02:00
|
|
|
it->second.coin.Clear();
|
2014-09-02 21:21:15 +02:00
|
|
|
}
|
2017-06-05 17:50:47 +02:00
|
|
|
return true;
|
2014-07-19 16:42:48 +02:00
|
|
|
}
|
|
|
|
|
2017-04-25 20:29:29 +02:00
|
|
|
static const Coin coinEmpty;
|
|
|
|
|
2017-04-25 20:29:39 +02:00
|
|
|
const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
|
2017-05-31 02:58:54 +02:00
|
|
|
CCoinsMap::const_iterator it = FetchCoin(outpoint);
|
2017-04-25 20:29:39 +02:00
|
|
|
if (it == cacheCoins.end()) {
|
2017-04-25 20:29:29 +02:00
|
|
|
return coinEmpty;
|
|
|
|
} else {
|
2017-05-04 09:15:36 +02:00
|
|
|
return it->second.coin;
|
2017-04-25 20:29:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-31 02:58:54 +02:00
|
|
|
bool CCoinsViewCache::HaveCoin(const COutPoint &outpoint) const {
|
|
|
|
CCoinsMap::const_iterator it = FetchCoin(outpoint);
|
|
|
|
return (it != cacheCoins.end() && !it->second.coin.IsSpent());
|
2017-04-25 20:29:29 +02:00
|
|
|
}
|
|
|
|
|
2017-05-31 02:58:54 +02:00
|
|
|
bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const {
|
2017-04-25 20:29:39 +02:00
|
|
|
CCoinsMap::const_iterator it = cacheCoins.find(outpoint);
|
2017-06-08 22:56:50 +02:00
|
|
|
return (it != cacheCoins.end() && !it->second.coin.IsSpent());
|
2015-10-23 00:49:53 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
2017-09-16 17:47:19 +02:00
|
|
|
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end(); it = mapCoins.erase(it)) {
|
|
|
|
// Ignore non-dirty entries (optimization).
|
|
|
|
if (!(it->second.flags & CCoinsCacheEntry::DIRTY)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CCoinsMap::iterator itUs = cacheCoins.find(it->first);
|
|
|
|
if (itUs == cacheCoins.end()) {
|
2020-01-30 21:52:36 +01:00
|
|
|
// The parent cache does not have an entry, while the child cache does.
|
|
|
|
// We can ignore it if it's both spent and FRESH in the child
|
2017-09-16 17:47:19 +02:00
|
|
|
if (!(it->second.flags & CCoinsCacheEntry::FRESH && it->second.coin.IsSpent())) {
|
2020-01-30 21:52:36 +01:00
|
|
|
// Create the coin in the parent cache, move the data up
|
|
|
|
// and mark it as dirty.
|
2017-09-16 17:47:19 +02:00
|
|
|
CCoinsCacheEntry& entry = cacheCoins[it->first];
|
|
|
|
entry.coin = std::move(it->second.coin);
|
|
|
|
cachedCoinsUsage += entry.coin.DynamicMemoryUsage();
|
|
|
|
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
|
|
|
}
|
2017-09-16 17:47:19 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-01-30 21:52:36 +01:00
|
|
|
// Found the entry in the parent cache
|
2017-09-16 17:47:19 +02:00
|
|
|
if ((it->second.flags & CCoinsCacheEntry::FRESH) && !itUs->second.coin.IsSpent()) {
|
2020-01-30 21:52:36 +01:00
|
|
|
// The coin was marked FRESH in the child cache, but the coin
|
|
|
|
// exists in the parent cache. If this ever happens, it means
|
|
|
|
// the FRESH flag was misapplied and there is a logic error in
|
|
|
|
// the calling code.
|
|
|
|
throw std::logic_error("FRESH flag misapplied to coin that exists in parent cache");
|
2017-09-16 17:47:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((itUs->second.flags & CCoinsCacheEntry::FRESH) && it->second.coin.IsSpent()) {
|
2020-01-30 21:52:36 +01:00
|
|
|
// The grandparent cache does not have an entry, and the coin
|
|
|
|
// has been spent. We can just delete it from the parent cache.
|
2017-09-16 17:47:19 +02:00
|
|
|
cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
|
|
|
|
cacheCoins.erase(itUs);
|
2014-09-03 09:37:47 +02:00
|
|
|
} else {
|
2017-09-16 17:47:19 +02:00
|
|
|
// A normal modification.
|
|
|
|
cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
|
|
|
|
itUs->second.coin = std::move(it->second.coin);
|
|
|
|
cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage();
|
|
|
|
itUs->second.flags |= CCoinsCacheEntry::DIRTY;
|
2020-01-30 21:52:36 +01:00
|
|
|
// NOTE: It isn't safe to mark the coin as FRESH in the parent
|
|
|
|
// cache. If it already existed and was spent in the parent
|
|
|
|
// cache then marking it FRESH would prevent that spentness
|
|
|
|
// from being flushed to the grandparent.
|
2014-09-03 09:37:47 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-24 02:08:05 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2017-04-25 20:29:39 +02:00
|
|
|
void CCoinsViewCache::Uncache(const COutPoint& hash)
|
2015-10-22 02:41:40 +02:00
|
|
|
{
|
|
|
|
CCoinsMap::iterator it = cacheCoins.find(hash);
|
|
|
|
if (it != cacheCoins.end() && it->second.flags == 0) {
|
2017-05-04 09:15:36 +02:00
|
|
|
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
|
2021-09-03 18:38:53 +02:00
|
|
|
TRACE5(utxocache, uncache,
|
|
|
|
hash.hash.data(),
|
|
|
|
(uint32_t)hash.n,
|
|
|
|
(uint32_t)it->second.coin.nHeight,
|
|
|
|
(int64_t)it->second.coin.out.nValue,
|
|
|
|
(bool)it->second.coin.IsCoinBase());
|
2015-10-22 02:41:40 +02:00
|
|
|
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
|
|
|
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++) {
|
2017-05-31 02:58:54 +02:00
|
|
|
if (!HaveCoin(tx.vin[i].prevout)) {
|
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
|
|
|
|
2019-09-16 21:01:12 +02:00
|
|
|
void CCoinsViewCache::ReallocateCache()
|
|
|
|
{
|
|
|
|
// Cache should be empty when we're calling this.
|
|
|
|
assert(cacheCoins.size() == 0);
|
|
|
|
cacheCoins.~CCoinsMap();
|
|
|
|
::new (&cacheCoins) CCoinsMap();
|
|
|
|
}
|
|
|
|
|
2018-06-22 20:27:18 +02:00
|
|
|
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut(), PROTOCOL_VERSION);
|
2017-06-17 02:18:42 +02:00
|
|
|
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;
|
2017-04-25 20:29:29 +02:00
|
|
|
|
2017-04-25 20:29:39 +02:00
|
|
|
const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)
|
2017-04-25 20:29:29 +02:00
|
|
|
{
|
|
|
|
COutPoint iter(txid, 0);
|
|
|
|
while (iter.n < MAX_OUTPUTS_PER_BLOCK) {
|
|
|
|
const Coin& alternate = view.AccessCoin(iter);
|
2017-05-31 02:58:54 +02:00
|
|
|
if (!alternate.IsSpent()) return alternate;
|
2017-04-25 20:29:29 +02:00
|
|
|
++iter.n;
|
|
|
|
}
|
|
|
|
return coinEmpty;
|
|
|
|
}
|
2019-03-27 19:17:13 +01:00
|
|
|
|
|
|
|
bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) const {
|
|
|
|
try {
|
|
|
|
return CCoinsViewBacked::GetCoin(outpoint, coin);
|
|
|
|
} catch(const std::runtime_error& e) {
|
|
|
|
for (auto f : m_err_callbacks) {
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
LogPrintf("Error reading from database: %s\n", e.what());
|
|
|
|
// Starting the shutdown sequence and returning false to the caller would be
|
|
|
|
// interpreted as 'entry not found' (as opposed to unable to read data), and
|
|
|
|
// could lead to invalid interpretation. Just exit immediately, as we can't
|
|
|
|
// continue anyway, and all writes should be atomic.
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
}
|