Skip to content

Commit 13870b5

Browse files
committed
Replace CCoins-based CTxMemPool::pruneSpent with isSpent
1 parent 05293f3 commit 13870b5

File tree

4 files changed

+5
-14
lines changed

4 files changed

+5
-14
lines changed

src/rest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
513513
uint256 hash = vOutPoints[i].hash;
514514
bool hit = false;
515515
if (view.GetCoins(hash, coins)) {
516-
mempool.pruneSpent(hash, coins);
517-
if (coins.IsAvailable(vOutPoints[i].n)) {
516+
if (coins.IsAvailable(vOutPoints[i].n) && !mempool.isSpent(vOutPoints[i])) {
518517
hit = true;
519518
// Safe to index into vout here because IsAvailable checked if it's off the end of the array, or if
520519
// n is valid but points to an already spent output (IsNull).

src/rpc/blockchain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,8 @@ UniValue gettxout(const JSONRPCRequest& request)
973973
if (fMempool) {
974974
LOCK(mempool.cs);
975975
CCoinsViewMemPool view(pcoinsTip, mempool);
976-
if (!view.GetCoins(hash, coins))
976+
if (!view.GetCoins(hash, coins) || mempool.isSpent(COutPoint(hash, n))) // TODO: this should be done by the CCoinsViewMemPool
977977
return NullUniValue;
978-
mempool.pruneSpent(hash, coins); // TODO: this should be done by the CCoinsViewMemPool
979978
} else {
980979
if (!pcoinsTip->GetCoins(hash, coins))
981980
return NullUniValue;

src/txmempool.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,10 @@ CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator) :
343343
nCheckFrequency = 0;
344344
}
345345

346-
void CTxMemPool::pruneSpent(const uint256 &hashTx, CCoins &coins)
346+
bool CTxMemPool::isSpent(const COutPoint& outpoint)
347347
{
348348
LOCK(cs);
349-
350-
auto it = mapNextTx.lower_bound(COutPoint(hashTx, 0));
351-
352-
// iterate over all COutPoints in mapNextTx whose hash equals the provided hashTx
353-
while (it != mapNextTx.end() && it->first->hash == hashTx) {
354-
coins.Spend(it->first->n); // and remove those outputs from coins
355-
it++;
356-
}
349+
return mapNextTx.count(outpoint);
357350
}
358351

359352
unsigned int CTxMemPool::GetTransactionsUpdated() const

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ class CTxMemPool
509509
void _clear(); //lock free
510510
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
511511
void queryHashes(std::vector<uint256>& vtxid);
512-
void pruneSpent(const uint256& hash, CCoins &coins);
512+
bool isSpent(const COutPoint& outpoint);
513513
unsigned int GetTransactionsUpdated() const;
514514
void AddTransactionsUpdated(unsigned int n);
515515
/**

0 commit comments

Comments
 (0)