Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.cpp
Show First 20 Lines • Show All 574 Lines • ▼ Show 20 Lines | void CTxMemPool::removeForReorg(const Config &config, | ||||
// Remove transactions spending a coinbase which are now immature and | // Remove transactions spending a coinbase which are now immature and | ||||
// no-longer-final transactions. | // no-longer-final transactions. | ||||
AssertLockHeld(cs); | AssertLockHeld(cs); | ||||
setEntries txToRemove; | setEntries txToRemove; | ||||
for (indexed_transaction_set::const_iterator it = mapTx.begin(); | for (indexed_transaction_set::const_iterator it = mapTx.begin(); | ||||
it != mapTx.end(); it++) { | it != mapTx.end(); it++) { | ||||
const CTransaction &tx = it->GetTx(); | const CTransaction &tx = it->GetTx(); | ||||
LockPoints lp = it->GetLockPoints(); | LockPoints lp = it->GetLockPoints(); | ||||
assert(std::addressof(::ChainstateActive()) == | |||||
std::addressof(active_chainstate)); | |||||
bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp); | bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp); | ||||
TxValidationState state; | TxValidationState state; | ||||
if (!ContextualCheckTransactionForCurrentBlock( | if (!ContextualCheckTransactionForCurrentBlock( | ||||
active_chainstate.m_chain.Tip(), | active_chainstate.m_chain.Tip(), | ||||
config.GetChainParams().GetConsensus(), tx, state, flags) || | config.GetChainParams().GetConsensus(), tx, state, flags) || | ||||
!CheckSequenceLocks(active_chainstate, *this, tx, flags, &lp, | !CheckSequenceLocks(active_chainstate, *this, tx, flags, &lp, | ||||
validLP)) { | validLP)) { | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | void CTxMemPool::check(CChainState &active_chainstate) const { | ||||
LogPrint(BCLog::MEMPOOL, | LogPrint(BCLog::MEMPOOL, | ||||
"Checking mempool with %u transactions and %u inputs\n", | "Checking mempool with %u transactions and %u inputs\n", | ||||
(unsigned int)mapTx.size(), (unsigned int)mapNextTx.size()); | (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size()); | ||||
uint64_t checkTotal = 0; | uint64_t checkTotal = 0; | ||||
uint64_t innerUsage = 0; | uint64_t innerUsage = 0; | ||||
CCoinsViewCache &active_coins_tip = active_chainstate.CoinsTip(); | CCoinsViewCache &active_coins_tip = active_chainstate.CoinsTip(); | ||||
// TODO: REVIEW-ONLY, REMOVE IN FUTURE COMMIT | |||||
assert(std::addressof(::ChainstateActive().CoinsTip()) == | |||||
std::addressof(active_coins_tip)); | |||||
CCoinsViewCache mempoolDuplicate( | CCoinsViewCache mempoolDuplicate( | ||||
const_cast<CCoinsViewCache *>(&active_coins_tip)); | const_cast<CCoinsViewCache *>(&active_coins_tip)); | ||||
const int64_t spendheight = active_chainstate.m_chain.Height() + 1; | const int64_t spendheight = active_chainstate.m_chain.Height() + 1; | ||||
// TODO: REVIEW-ONLY, REMOVE IN FUTURE COMMIT | |||||
assert(g_chainman.m_blockman.GetSpendHeight(mempoolDuplicate) == | |||||
spendheight); | |||||
std::list<const CTxMemPoolEntry *> waitingOnDependants; | std::list<const CTxMemPoolEntry *> waitingOnDependants; | ||||
for (indexed_transaction_set::const_iterator it = mapTx.begin(); | for (indexed_transaction_set::const_iterator it = mapTx.begin(); | ||||
it != mapTx.end(); it++) { | it != mapTx.end(); it++) { | ||||
unsigned int i = 0; | unsigned int i = 0; | ||||
checkTotal += it->GetTxSize(); | checkTotal += it->GetTxSize(); | ||||
innerUsage += it->DynamicMemoryUsage(); | innerUsage += it->DynamicMemoryUsage(); | ||||
const CTransaction &tx = it->GetTx(); | const CTransaction &tx = it->GetTx(); | ||||
▲ Show 20 Lines • Show All 384 Lines • ▼ Show 20 Lines | void CTxMemPool::LimitSize(CCoinsViewCache &coins_cache, size_t limit, | ||||
int expired = Expire(GetTime<std::chrono::seconds>() - age); | int expired = Expire(GetTime<std::chrono::seconds>() - age); | ||||
if (expired != 0) { | if (expired != 0) { | ||||
LogPrint(BCLog::MEMPOOL, | LogPrint(BCLog::MEMPOOL, | ||||
"Expired %i transactions from the memory pool\n", expired); | "Expired %i transactions from the memory pool\n", expired); | ||||
} | } | ||||
std::vector<COutPoint> vNoSpendsRemaining; | std::vector<COutPoint> vNoSpendsRemaining; | ||||
TrimToSize(limit, &vNoSpendsRemaining); | TrimToSize(limit, &vNoSpendsRemaining); | ||||
assert(std::addressof(::ChainstateActive().CoinsTip()) == | |||||
std::addressof(coins_cache)); | |||||
for (const COutPoint &removed : vNoSpendsRemaining) { | for (const COutPoint &removed : vNoSpendsRemaining) { | ||||
coins_cache.Uncache(removed); | coins_cache.Uncache(removed); | ||||
} | } | ||||
} | } | ||||
void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry) { | void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry) { | ||||
setEntries setAncestors; | setEntries setAncestors; | ||||
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max(); | uint64_t nNoLimit = std::numeric_limits<uint64_t>::max(); | ||||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | void DisconnectedBlockTransactions::importMempool(CTxMemPool &pool) { | ||||
} | } | ||||
} | } | ||||
void DisconnectedBlockTransactions::updateMempoolForReorg( | void DisconnectedBlockTransactions::updateMempoolForReorg( | ||||
const Config &config, CChainState &active_chainstate, bool fAddToMempool, | const Config &config, CChainState &active_chainstate, bool fAddToMempool, | ||||
CTxMemPool &pool) { | CTxMemPool &pool) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
AssertLockHeld(pool.cs); | AssertLockHeld(pool.cs); | ||||
assert(std::addressof(::ChainstateActive()) == | |||||
std::addressof(active_chainstate)); | |||||
std::vector<TxId> txidsUpdate; | std::vector<TxId> txidsUpdate; | ||||
// disconnectpool's insertion_order index sorts the entries from oldest to | // disconnectpool's insertion_order index sorts the entries from oldest to | ||||
// newest, but the oldest entry will be the last tx from the latest mined | // newest, but the oldest entry will be the last tx from the latest mined | ||||
// block that was disconnected. | // block that was disconnected. | ||||
// Iterate disconnectpool in reverse, so that we add transactions back to | // Iterate disconnectpool in reverse, so that we add transactions back to | ||||
// the mempool starting with the earliest transaction that had been | // the mempool starting with the earliest transaction that had been | ||||
// previously seen in a block. | // previously seen in a block. | ||||
Show All 35 Lines |