Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.cpp
Show First 20 Lines • Show All 1,061 Lines • ▼ Show 20 Lines | bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const { | ||||
return true; | return true; | ||||
} | } | ||||
CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView *baseIn, | CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView *baseIn, | ||||
const CTxMemPool &mempoolIn) | const CTxMemPool &mempoolIn) | ||||
: CCoinsViewBacked(baseIn), mempool(mempoolIn) {} | : CCoinsViewBacked(baseIn), mempool(mempoolIn) {} | ||||
bool CCoinsViewMemPool::GetCoin(const COutPoint &outpoint, Coin &coin) const { | bool CCoinsViewMemPool::GetCoin(const COutPoint &outpoint, Coin &coin) const { | ||||
// Check to see if the inputs are made available by another tx in the | |||||
// package. These Coins would not be available in the underlying CoinsView. | |||||
if (auto it = m_temp_added.find(outpoint); it != m_temp_added.end()) { | |||||
coin = it->second; | |||||
return true; | |||||
} | |||||
// If an entry in the mempool exists, always return that one, as it's | // If an entry in the mempool exists, always return that one, as it's | ||||
// guaranteed to never conflict with the underlying cache, and it cannot | // guaranteed to never conflict with the underlying cache, and it cannot | ||||
// have pruned entries (as it contains full) transactions. First checking | // have pruned entries (as it contains full) transactions. First checking | ||||
// the underlying cache risks returning a pruned entry instead. | // the underlying cache risks returning a pruned entry instead. | ||||
CTransactionRef ptx = mempool.get(outpoint.GetTxId()); | CTransactionRef ptx = mempool.get(outpoint.GetTxId()); | ||||
if (ptx) { | if (ptx) { | ||||
if (outpoint.GetN() < ptx->vout.size()) { | if (outpoint.GetN() < ptx->vout.size()) { | ||||
coin = Coin(ptx->vout[outpoint.GetN()], MEMPOOL_HEIGHT, false); | coin = Coin(ptx->vout[outpoint.GetN()], MEMPOOL_HEIGHT, false); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
return base->GetCoin(outpoint, coin); | return base->GetCoin(outpoint, coin); | ||||
} | } | ||||
void CCoinsViewMemPool::PackageAddTransaction(const CTransactionRef &tx) { | |||||
for (unsigned int n = 0; n < tx->vout.size(); ++n) { | |||||
Fabien: uint32_t | |||||
m_temp_added.emplace(COutPoint(tx->GetId(), n), | |||||
Coin(tx->vout[n], MEMPOOL_HEIGHT, false)); | |||||
} | |||||
} | |||||
size_t CTxMemPool::DynamicMemoryUsage() const { | size_t CTxMemPool::DynamicMemoryUsage() const { | ||||
LOCK(cs); | LOCK(cs); | ||||
// Estimate the overhead of mapTx to be 12 pointers + an allocation, as no | // Estimate the overhead of mapTx to be 12 pointers + an allocation, as no | ||||
// exact formula for boost::multi_index_contained is implemented. | // exact formula for boost::multi_index_contained is implemented. | ||||
return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + | return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + | ||||
12 * sizeof(void *)) * | 12 * sizeof(void *)) * | ||||
mapTx.size() + | mapTx.size() + | ||||
memusage::DynamicUsage(mapNextTx) + | memusage::DynamicUsage(mapNextTx) + | ||||
▲ Show 20 Lines • Show All 363 Lines • Show Last 20 Lines |
uint32_t