Replace CCoins-based CTxMemPool::pruneSpent with isSpent

This commit is contained in:
Pieter Wuille 2017-04-25 11:29:37 -07:00
parent 05293f3cb7
commit 13870b56fc
4 changed files with 5 additions and 14 deletions

View file

@ -513,8 +513,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
uint256 hash = vOutPoints[i].hash; uint256 hash = vOutPoints[i].hash;
bool hit = false; bool hit = false;
if (view.GetCoins(hash, coins)) { if (view.GetCoins(hash, coins)) {
mempool.pruneSpent(hash, coins); if (coins.IsAvailable(vOutPoints[i].n) && !mempool.isSpent(vOutPoints[i])) {
if (coins.IsAvailable(vOutPoints[i].n)) {
hit = true; hit = true;
// Safe to index into vout here because IsAvailable checked if it's off the end of the array, or if // 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). // n is valid but points to an already spent output (IsNull).

View file

@ -973,9 +973,8 @@ UniValue gettxout(const JSONRPCRequest& request)
if (fMempool) { if (fMempool) {
LOCK(mempool.cs); LOCK(mempool.cs);
CCoinsViewMemPool view(pcoinsTip, mempool); 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; return NullUniValue;
mempool.pruneSpent(hash, coins); // TODO: this should be done by the CCoinsViewMemPool
} else { } else {
if (!pcoinsTip->GetCoins(hash, coins)) if (!pcoinsTip->GetCoins(hash, coins))
return NullUniValue; return NullUniValue;

View file

@ -343,17 +343,10 @@ CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator) :
nCheckFrequency = 0; nCheckFrequency = 0;
} }
void CTxMemPool::pruneSpent(const uint256 &hashTx, CCoins &coins) bool CTxMemPool::isSpent(const COutPoint& outpoint)
{ {
LOCK(cs); LOCK(cs);
return mapNextTx.count(outpoint);
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++;
}
} }
unsigned int CTxMemPool::GetTransactionsUpdated() const unsigned int CTxMemPool::GetTransactionsUpdated() const

View file

@ -509,7 +509,7 @@ public:
void _clear(); //lock free void _clear(); //lock free
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb); bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
void queryHashes(std::vector<uint256>& vtxid); void queryHashes(std::vector<uint256>& vtxid);
void pruneSpent(const uint256& hash, CCoins &coins); bool isSpent(const COutPoint& outpoint);
unsigned int GetTransactionsUpdated() const; unsigned int GetTransactionsUpdated() const;
void AddTransactionsUpdated(unsigned int n); void AddTransactionsUpdated(unsigned int n);
/** /**