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) { | |||||
LOCK(pool.cs); | |||||
// 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 | |||||
deadalnix: Put the comment on one line and let clang-format handle them. Put dot at the end of sentence. | |||||
// 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 | |||||
deadalnixUnsubmitted Done Inline ActionsThis is clearly another paragraph from what comes before. Paragraph are separated by an empty line. deadalnix: This is clearly another paragraph from what comes before. Paragraph are separated by an empty… | |||||
std::vector<CTransactionRef> vtx; | |||||
vtx.reserve(pool.mapTx.size()); | |||||
for (const CTxMemPoolEntry &e : pool.mapTx.get<entry_time>()) { | |||||
vtx.push_back(std::move(e.GetSharedTx())); | |||||
deadalnixUnsubmitted Done Inline ActionsSo this is returning by value anyways, so std::move does nothing. deadalnix: So this is returning by value anyways, so std::move does nothing. | |||||
} | |||||
pool.clear(); | |||||
deadalnixUnsubmitted Done Inline ActionsIt doesn't looks like the pool is used after this, so holding the lock on the pool do not seems necessary. deadalnix: It doesn't looks like the pool is used after this, so holding the lock on the pool do not seems… | |||||
// 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 |
Put the comment on one line and let clang-format handle them. Put dot at the end of sentence.