aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2017-06-05 11:50:47 -0400
committerMatt Corallo <git@bluematt.me>2017-06-09 13:10:05 -0400
commit3533fb4d33ecc94a789cb5d4489da22a68fb2168 (patch)
treed4210584798f80828e4a133bb3d72944cf6a414a /src
parentec1271f2bea52d43bd24fb93d32d24168f8c6a74 (diff)
Return a bool in SpendCoin to restore pre-per-utxo assert semantics
Since its free to do so, assert that Spends succeeded when we expect them to.
Diffstat (limited to 'src')
-rw-r--r--src/coins.cpp5
-rw-r--r--src/coins.h2
-rw-r--r--src/validation.cpp7
3 files changed, 8 insertions, 6 deletions
diff --git a/src/coins.cpp b/src/coins.cpp
index 5b7c562678..b75bd27577 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -91,9 +91,9 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight) {
}
}
-void CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
+bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
CCoinsMap::iterator it = FetchCoin(outpoint);
- if (it == cacheCoins.end()) return;
+ if (it == cacheCoins.end()) return false;
cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
if (moveout) {
*moveout = std::move(it->second.coin);
@@ -104,6 +104,7 @@ void CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout) {
it->second.flags |= CCoinsCacheEntry::DIRTY;
it->second.coin.Clear();
}
+ return true;
}
static const Coin coinEmpty;
diff --git a/src/coins.h b/src/coins.h
index 476db8f37c..4a0eaadc82 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -238,7 +238,7 @@ public:
* If no unspent output exists for the passed outpoint, this call
* has no effect.
*/
- void SpendCoin(const COutPoint &outpoint, Coin* moveto = nullptr);
+ bool SpendCoin(const COutPoint &outpoint, Coin* moveto = nullptr);
/**
* Push the modifications applied to this cache to its base.
diff --git a/src/validation.cpp b/src/validation.cpp
index de65839eef..c708a476de 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1118,7 +1118,8 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund
txundo.vprevout.reserve(tx.vin.size());
BOOST_FOREACH(const CTxIn &txin, tx.vin) {
txundo.vprevout.emplace_back();
- inputs.SpendCoin(txin.prevout, &txundo.vprevout.back());
+ bool is_spent = inputs.SpendCoin(txin.prevout, &txundo.vprevout.back());
+ assert(is_spent);
}
}
// add outputs
@@ -1358,8 +1359,8 @@ static DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex*
if (!tx.vout[o].scriptPubKey.IsUnspendable()) {
COutPoint out(hash, o);
Coin coin;
- view.SpendCoin(out, &coin);
- if (tx.vout[o] != coin.out) {
+ bool is_spent = view.SpendCoin(out, &coin);
+ if (!is_spent || tx.vout[o] != coin.out) {
fClean = false; // transaction output mismatch
}
}