Browse Source

Provide a flat list of txid/terators to txn in CTxMemPool

0.13
Matt Corallo 9 years ago
parent
commit
811902649d
  1. 14
      src/txmempool.cpp
  2. 5
      src/txmempool.h

14
src/txmempool.cpp

@ -438,6 +438,9 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
totalTxSize += entry.GetTxSize(); totalTxSize += entry.GetTxSize();
minerPolicyEstimator->processTransaction(entry, fCurrentEstimate); minerPolicyEstimator->processTransaction(entry, fCurrentEstimate);
vTxHashes.emplace_back(hash, newit);
newit->vTxHashesIdx = vTxHashes.size() - 1;
return true; return true;
} }
@ -447,6 +450,15 @@ void CTxMemPool::removeUnchecked(txiter it)
BOOST_FOREACH(const CTxIn& txin, it->GetTx().vin) BOOST_FOREACH(const CTxIn& txin, it->GetTx().vin)
mapNextTx.erase(txin.prevout); mapNextTx.erase(txin.prevout);
if (vTxHashes.size() > 1) {
vTxHashes[it->vTxHashesIdx] = std::move(vTxHashes.back());
vTxHashes[it->vTxHashesIdx].second->vTxHashesIdx = it->vTxHashesIdx;
vTxHashes.pop_back();
if (vTxHashes.size() * 2 < vTxHashes.capacity())
vTxHashes.shrink_to_fit();
} else
vTxHashes.clear();
totalTxSize -= it->GetTxSize(); totalTxSize -= it->GetTxSize();
cachedInnerUsage -= it->DynamicMemoryUsage(); cachedInnerUsage -= it->DynamicMemoryUsage();
cachedInnerUsage -= memusage::DynamicUsage(mapLinks[it].parents) + memusage::DynamicUsage(mapLinks[it].children); cachedInnerUsage -= memusage::DynamicUsage(mapLinks[it].parents) + memusage::DynamicUsage(mapLinks[it].children);
@ -965,7 +977,7 @@ bool CCoinsViewMemPool::HaveCoins(const uint256 &txid) const {
size_t CTxMemPool::DynamicMemoryUsage() const { size_t CTxMemPool::DynamicMemoryUsage() const {
LOCK(cs); LOCK(cs);
// Estimate the overhead of mapTx to be 15 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented. // Estimate the overhead of mapTx to be 15 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented.
return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 15 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + memusage::DynamicUsage(mapLinks) + cachedInnerUsage; return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 15 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + memusage::DynamicUsage(mapLinks) + memusage::DynamicUsage(vTxHashes) + cachedInnerUsage;
} }
void CTxMemPool::RemoveStaged(setEntries &stage, bool updateDescendants) { void CTxMemPool::RemoveStaged(setEntries &stage, bool updateDescendants) {

5
src/txmempool.h

@ -150,6 +150,8 @@ public:
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
unsigned int GetSigOpCountWithAncestors() const { return nSigOpCountWithAncestors; } unsigned int GetSigOpCountWithAncestors() const { return nSigOpCountWithAncestors; }
mutable size_t vTxHashesIdx; //!< Index in mempool's vTxHashes
}; };
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index. // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
@ -457,7 +459,10 @@ public:
mutable CCriticalSection cs; mutable CCriticalSection cs;
indexed_transaction_set mapTx; indexed_transaction_set mapTx;
typedef indexed_transaction_set::nth_index<0>::type::iterator txiter; typedef indexed_transaction_set::nth_index<0>::type::iterator txiter;
std::vector<std::pair<uint256, txiter> > vTxHashes; //!< All tx hashes/entries in mapTx, in random order
struct CompareIteratorByHash { struct CompareIteratorByHash {
bool operator()(const txiter &a, const txiter &b) const { bool operator()(const txiter &a, const txiter &b) const {
return a->GetTx().GetHash() < b->GetTx().GetHash(); return a->GetTx().GetHash() < b->GetTx().GetHash();

Loading…
Cancel
Save