diff --git a/src/coins.h b/src/coins.h --- a/src/coins.h +++ b/src/coins.h @@ -304,6 +304,9 @@ bool check = false); //! 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 TxId &txid); #endif // BITCOIN_COINS_H diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1396,6 +1396,7 @@ for (const auto &ptx : block.vtx) { const CTransaction &tx = *ptx; const TxId &txid = tx.GetId(); + const bool is_coinbase = tx.IsCoinBase(); // Check that all outputs are available and match the outputs in the // block itself exactly. @@ -1407,7 +1408,9 @@ COutPoint out(txid, o); Coin coin; bool is_spent = view.SpendCoin(out, &coin); - if (!is_spent || tx.vout[o] != coin.GetTxOut()) { + if (!is_spent || tx.vout[o] != coin.GetTxOut() || + uint32_t(pindex->nHeight) != coin.GetHeight() || + is_coinbase != coin.IsCoinBase()) { // transaction output mismatch fClean = false; }