diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-04-25 11:29:37 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-06-01 12:43:16 -0700 |
commit | 13870b56fcd0bfacedce3ae42a3de3d5e9dc7bc1 (patch) | |
tree | 874be8e8f747c15d337df1f7b5b94875aac8fb68 | |
parent | 05293f3cb75ad08ca23cba8e795e27d4d5e4d690 (diff) |
Replace CCoins-based CTxMemPool::pruneSpent with isSpent
-rw-r--r-- | src/rest.cpp | 3 | ||||
-rw-r--r-- | src/rpc/blockchain.cpp | 3 | ||||
-rw-r--r-- | src/txmempool.cpp | 11 | ||||
-rw-r--r-- | src/txmempool.h | 2 |
4 files changed, 5 insertions, 14 deletions
diff --git a/src/rest.cpp b/src/rest.cpp index 9c291fe0a9..4a71010094 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -513,8 +513,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) uint256 hash = vOutPoints[i].hash; bool hit = false; if (view.GetCoins(hash, coins)) { - mempool.pruneSpent(hash, coins); - if (coins.IsAvailable(vOutPoints[i].n)) { + if (coins.IsAvailable(vOutPoints[i].n) && !mempool.isSpent(vOutPoints[i])) { hit = true; // Safe to index into vout here because IsAvailable checked if it's off the end of the array, or if // n is valid but points to an already spent output (IsNull). diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index e59b9b86bb..94e42a8644 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -973,9 +973,8 @@ UniValue gettxout(const JSONRPCRequest& request) if (fMempool) { LOCK(mempool.cs); CCoinsViewMemPool view(pcoinsTip, mempool); - if (!view.GetCoins(hash, coins)) + if (!view.GetCoins(hash, coins) || mempool.isSpent(COutPoint(hash, n))) // TODO: this should be done by the CCoinsViewMemPool return NullUniValue; - mempool.pruneSpent(hash, coins); // TODO: this should be done by the CCoinsViewMemPool } else { if (!pcoinsTip->GetCoins(hash, coins)) return NullUniValue; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 33df0536d0..51b93e92ba 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -343,17 +343,10 @@ CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator) : nCheckFrequency = 0; } -void CTxMemPool::pruneSpent(const uint256 &hashTx, CCoins &coins) +bool CTxMemPool::isSpent(const COutPoint& outpoint) { LOCK(cs); - - auto it = mapNextTx.lower_bound(COutPoint(hashTx, 0)); - - // iterate over all COutPoints in mapNextTx whose hash equals the provided hashTx - while (it != mapNextTx.end() && it->first->hash == hashTx) { - coins.Spend(it->first->n); // and remove those outputs from coins - it++; - } + return mapNextTx.count(outpoint); } unsigned int CTxMemPool::GetTransactionsUpdated() const diff --git a/src/txmempool.h b/src/txmempool.h index a91eb5be54..6547f64f74 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -509,7 +509,7 @@ public: void _clear(); //lock free bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb); void queryHashes(std::vector<uint256>& vtxid); - void pruneSpent(const uint256& hash, CCoins &coins); + bool isSpent(const COutPoint& outpoint); unsigned int GetTransactionsUpdated() const; void AddTransactionsUpdated(unsigned int n); /** |