Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.cpp
Show First 20 Lines • Show All 1,346 Lines • ▼ Show 20 Lines | for (const auto &tx : boost::adaptors::reverse(vtx)) { | ||||
} | } | ||||
} | } | ||||
// Keep the size under control. | // Keep the size under control. | ||||
while (DynamicMemoryUsage() > MAX_DISCONNECTED_TX_POOL_SIZE) { | while (DynamicMemoryUsage() > MAX_DISCONNECTED_TX_POOL_SIZE) { | ||||
// Drop the earliest entry, and remove its children from the | // Drop the earliest entry, and remove its children from the | ||||
// mempool. | // mempool. | ||||
auto it = queuedTx.get<insertion_order>().begin(); | auto it = queuedTx.get<insertion_order>().begin(); | ||||
mempool.removeRecursive(**it, MemPoolRemovalReason::REORG); | g_mempool.removeRecursive(**it, MemPoolRemovalReason::REORG); | ||||
removeEntry(it); | removeEntry(it); | ||||
} | } | ||||
} | } | ||||
void DisconnectedBlockTransactions::updateMempoolForReorg(const Config &config, | void DisconnectedBlockTransactions::updateMempoolForReorg(const Config &config, | ||||
bool fAddToMempool) { | bool fAddToMempool) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
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. | ||||
for (const CTransactionRef &tx : | for (const CTransactionRef &tx : | ||||
boost::adaptors::reverse(queuedTx.get<insertion_order>())) { | boost::adaptors::reverse(queuedTx.get<insertion_order>())) { | ||||
// ignore validation errors in resurrected transactions | // ignore validation errors in resurrected transactions | ||||
CValidationState stateDummy; | CValidationState stateDummy; | ||||
if (!fAddToMempool || tx->IsCoinBase() || | if (!fAddToMempool || tx->IsCoinBase() || | ||||
!AcceptToMemoryPool(config, mempool, stateDummy, tx, false, nullptr, | !AcceptToMemoryPool(config, g_mempool, stateDummy, tx, false, | ||||
true)) { | nullptr, true)) { | ||||
// If the transaction doesn't make it in to the mempool, remove any | // If the transaction doesn't make it in to the mempool, remove any | ||||
// transactions that depend on it (which would now be orphans). | // transactions that depend on it (which would now be orphans). | ||||
mempool.removeRecursive(*tx, MemPoolRemovalReason::REORG); | g_mempool.removeRecursive(*tx, MemPoolRemovalReason::REORG); | ||||
} else if (mempool.exists(tx->GetId())) { | } else if (g_mempool.exists(tx->GetId())) { | ||||
txidsUpdate.push_back(tx->GetId()); | txidsUpdate.push_back(tx->GetId()); | ||||
} | } | ||||
} | } | ||||
queuedTx.clear(); | queuedTx.clear(); | ||||
// AcceptToMemoryPool/addUnchecked all assume that new mempool entries have | // AcceptToMemoryPool/addUnchecked all assume that new mempool entries have | ||||
// no in-mempool children, which is generally not true when adding | // no in-mempool children, which is generally not true when adding | ||||
// previously-confirmed transactions back to the mempool. | // previously-confirmed transactions back to the mempool. | ||||
// UpdateTransactionsFromBlock finds descendants of any transactions in the | // UpdateTransactionsFromBlock finds descendants of any transactions in the | ||||
// disconnectpool that were added back and cleans up the mempool state. | // disconnectpool that were added back and cleans up the mempool state. | ||||
mempool.UpdateTransactionsFromBlock(txidsUpdate); | g_mempool.UpdateTransactionsFromBlock(txidsUpdate); | ||||
// We also need to remove any now-immature transactions | // We also need to remove any now-immature transactions | ||||
mempool.removeForReorg(config, pcoinsTip.get(), | g_mempool.removeForReorg(config, pcoinsTip.get(), | ||||
chainActive.Tip()->nHeight + 1, | chainActive.Tip()->nHeight + 1, | ||||
STANDARD_LOCKTIME_VERIFY_FLAGS); | STANDARD_LOCKTIME_VERIFY_FLAGS); | ||||
// Re-limit mempool size, in case we added any transactions | // Re-limit mempool size, in case we added any transactions | ||||
mempool.LimitSize( | g_mempool.LimitSize( | ||||
gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, | gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, | ||||
gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); | gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); | ||||
} | } |