Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.cpp
Show First 20 Lines • Show All 1,315 Lines • ▼ Show 20 Lines | 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(); | ||||
g_mempool.removeRecursive(**it, MemPoolRemovalReason::REORG); | g_mempool.removeRecursive(**it, MemPoolRemovalReason::REORG); | ||||
removeEntry(it); | removeEntry(it); | ||||
} | } | ||||
} | } | ||||
void DisconnectedBlockTransactions::importMempool(CTxMemPool &pool) { | |||||
// addForBlock's algorithm sorts a vector of transactions back into | |||||
// topological order. We use it in a separate object to create a valid | |||||
// ordering of all mempool transactions, which we then splice in front of | |||||
// the current queuedTx. This results in a valid sequence of transactions to | |||||
// be reprocessed in updateMempoolForReorg. | |||||
// We create vtx in order of the entry_time index to facilitate for | |||||
// addForBlocks (which iterates in reverse order), as vtx probably end in | |||||
// the correct ordering for queuedTx. | |||||
std::vector<CTransactionRef> vtx; | |||||
{ | |||||
LOCK(pool.cs); | |||||
vtx.reserve(pool.mapTx.size()); | |||||
for (const CTxMemPoolEntry &e : pool.mapTx.get<entry_time>()) { | |||||
vtx.push_back(e.GetSharedTx()); | |||||
} | |||||
pool.clear(); | |||||
} | |||||
// Use addForBlocks to sort the transactions and then splice them in front | |||||
// of queuedTx | |||||
DisconnectedBlockTransactions orderedTxnPool; | |||||
orderedTxnPool.addForBlock(vtx); | |||||
cachedInnerUsage += orderedTxnPool.cachedInnerUsage; | |||||
queuedTx.get<insertion_order>().splice( | |||||
queuedTx.get<insertion_order>().begin(), | |||||
orderedTxnPool.queuedTx.get<insertion_order>()); | |||||
// We limit memory usage because we can't know if more blocks will be | |||||
// disconnected | |||||
while (DynamicMemoryUsage() > MAX_DISCONNECTED_TX_POOL_SIZE) { | |||||
// Drop the earliest entry which, by definition, has no children | |||||
removeEntry(queuedTx.get<insertion_order>().begin()); | |||||
} | |||||
} | |||||
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. | ||||
Show All 37 Lines |