Browse Source

Replace CCoins-based CTxMemPool::pruneSpent with isSpent

0.15
Pieter Wuille 7 years ago
parent
commit
13870b56fc
  1. 3
      src/rest.cpp
  2. 3
      src/rpc/blockchain.cpp
  3. 11
      src/txmempool.cpp
  4. 2
      src/txmempool.h

3
src/rest.cpp

@ -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).

3
src/rpc/blockchain.cpp

@ -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;

11
src/txmempool.cpp

@ -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

2
src/txmempool.h

@ -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);
/** /**

Loading…
Cancel
Save