From 3c8a9aefff3a600bef3da63c560f62af9e5582d6 Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Thu, 8 Jun 2017 12:08:32 -0400 Subject: [PATCH 1/2] Add belt-and-suspenders in DisconnectBlock These extra variables were previously checked before the move to per-txout database. --- src/validation.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index eb6ea42b6..baf76e5ba 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1364,6 +1364,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* for (int i = block.vtx.size() - 1; i >= 0; i--) { const CTransaction &tx = *(block.vtx[i]); uint256 hash = tx.GetHash(); + bool is_coinbase = tx.IsCoinBase(); // Check that all outputs are available and match the outputs in the block itself // exactly. @@ -1372,7 +1373,7 @@ static DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* COutPoint out(hash, o); Coin coin; bool is_spent = view.SpendCoin(out, &coin); - if (!is_spent || tx.vout[o] != coin.out) { + if (!is_spent || tx.vout[o] != coin.out || pindex->nHeight != coin.nHeight || is_coinbase != coin.fCoinBase) { fClean = false; // transaction output mismatch } } From 21d4afa12fbf1e7f59b629060c9e10db213fe07a Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Thu, 8 Jun 2017 12:15:04 -0400 Subject: [PATCH 2/2] Comment clarifications in coins.cpp --- src/coins.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coins.h b/src/coins.h index 077545a55..7c1d6da2b 100644 --- a/src/coins.h +++ b/src/coins.h @@ -297,6 +297,9 @@ private: void AddCoins(CCoinsViewCache& cache, const CTransaction& tx, int nHeight); //! Utility function to find any unspent output with a given txid. +// This function can be quite expensive because in the event of a transaction +// which is not found in the cache, it can cause up to MAX_OUTPUTS_PER_BLOCK +// lookups to database, so it should be used with care. const Coin& AccessByTxid(const CCoinsViewCache& cache, const uint256& txid); #endif // BITCOIN_COINS_H