diff options
author | Matt Corallo <git@bluematt.me> | 2014-11-11 21:06:15 -0800 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2014-12-08 14:05:42 -0800 |
commit | b7b4318f3a65d6e55d44bff5da1091ec0b3a26d2 (patch) | |
tree | 725f34ae07e2c8c203b696f98240a0575f808653 /src/txmempool.cpp | |
parent | 723d12c098456e7682e641076e76468a9fb0cec0 (diff) |
Make CTxMemPool::check more thourough by using CheckInputs
Diffstat (limited to 'src/txmempool.cpp')
-rw-r--r-- | src/txmempool.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp index ff04a8ad9a..6ecd64636b 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -6,7 +6,7 @@ #include "txmempool.h" #include "clientversion.h" -#include "main.h" // for COINBASE_MATURITY +#include "main.h" #include "streams.h" #include "util.h" #include "utilmoneystr.h" @@ -539,17 +539,22 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const uint64_t checkTotal = 0; + CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins)); + LOCK(cs); + list<const CTxMemPoolEntry*> waitingOnDependants; for (std::map<uint256, CTxMemPoolEntry>::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { unsigned int i = 0; checkTotal += it->second.GetTxSize(); const CTransaction& tx = it->second.GetTx(); + bool fDependsWait = false; BOOST_FOREACH(const CTxIn &txin, tx.vin) { // Check that every mempool transaction's inputs refer to available coins, or other mempool tx's. std::map<uint256, CTxMemPoolEntry>::const_iterator it2 = mapTx.find(txin.prevout.hash); if (it2 != mapTx.end()) { const CTransaction& tx2 = it2->second.GetTx(); assert(tx2.vout.size() > txin.prevout.n && !tx2.vout[txin.prevout.n].IsNull()); + fDependsWait = true; } else { const CCoins* coins = pcoins->AccessCoins(txin.prevout.hash); assert(coins && coins->IsAvailable(txin.prevout.n)); @@ -561,6 +566,29 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const assert(it3->second.n == i); i++; } + if (fDependsWait) + waitingOnDependants.push_back(&it->second); + else { + CValidationState state; CTxUndo undo; + assert(CheckInputs(tx, state, mempoolDuplicate, false, 0, false, NULL)); + UpdateCoins(tx, state, mempoolDuplicate, undo, 1000000); + } + } + unsigned int stepsSinceLastRemove = 0; + while (!waitingOnDependants.empty()) { + const CTxMemPoolEntry* entry = waitingOnDependants.front(); + waitingOnDependants.pop_front(); + CValidationState state; + if (!mempoolDuplicate.HaveInputs(entry->GetTx())) { + waitingOnDependants.push_back(entry); + stepsSinceLastRemove++; + assert(stepsSinceLastRemove < waitingOnDependants.size()); + } else { + assert(CheckInputs(entry->GetTx(), state, mempoolDuplicate, false, 0, false, NULL)); + CTxUndo undo; + UpdateCoins(entry->GetTx(), state, mempoolDuplicate, undo, 1000000); + stepsSinceLastRemove = 0; + } } for (std::map<COutPoint, CInPoint>::const_iterator it = mapNextTx.begin(); it != mapNextTx.end(); it++) { uint256 hash = it->second.ptx->GetHash(); |