Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
Show First 20 Lines • Show All 838 Lines • ▼ Show 20 Lines | |||||
* available to be mined. However, it's more efficient to wait until the reorg | * available to be mined. However, it's more efficient to wait until the reorg | ||||
* is complete and process all still-unconfirmed transactions at that time, | * is complete and process all still-unconfirmed transactions at that time, | ||||
* since we expect most confirmed transactions to (typically) still be | * since we expect most confirmed transactions to (typically) still be | ||||
* confirmed in the new chain, and re-accepting to the memory pool is expensive | * confirmed in the new chain, and re-accepting to the memory pool is expensive | ||||
* (and therefore better to not do in the middle of reorg-processing). | * (and therefore better to not do in the middle of reorg-processing). | ||||
* Instead, store the disconnected transactions (in order!) as we go, remove any | * Instead, store the disconnected transactions (in order!) as we go, remove any | ||||
* that are included in blocks in the new chain, and then process the remaining | * that are included in blocks in the new chain, and then process the remaining | ||||
* still-unconfirmed transactions at the end. | * still-unconfirmed transactions at the end. | ||||
* | |||||
* It also enables efficient reprocessing of current mempool entries, useful | |||||
* when (de)activating forks that result in in-mempool transactions becoming | |||||
* invalid | |||||
*/ | */ | ||||
// multi_index tag names | // multi_index tag names | ||||
struct txid_index {}; | struct txid_index {}; | ||||
struct insertion_order {}; | struct insertion_order {}; | ||||
class DisconnectedBlockTransactions { | class DisconnectedBlockTransactions { | ||||
private: | private: | ||||
typedef boost::multi_index_container< | typedef boost::multi_index_container< | ||||
Show All 34 Lines | size_t DynamicMemoryUsage() const { | ||||
queuedTx.size() + | queuedTx.size() + | ||||
cachedInnerUsage; | cachedInnerUsage; | ||||
} | } | ||||
const indexed_disconnected_transactions &GetQueuedTx() const { | const indexed_disconnected_transactions &GetQueuedTx() const { | ||||
return queuedTx; | return queuedTx; | ||||
} | } | ||||
// Import mempool entries in topological order into queuedTx and clear the | |||||
// mempool. Caller should call updateMempoolForReorg to reprocess these | |||||
// transactions | |||||
void importMempool(CTxMemPool &pool); | |||||
// Add entries for a block while reconstructing the topological ordering so | // Add entries for a block while reconstructing the topological ordering so | ||||
// they can be added back to the mempool simply. | // they can be added back to the mempool simply. | ||||
void addForBlock(const std::vector<CTransactionRef> &vtx); | void addForBlock(const std::vector<CTransactionRef> &vtx); | ||||
// Remove entries based on txid_index, and update memory usage. | // Remove entries based on txid_index, and update memory usage. | ||||
void removeForBlock(const std::vector<CTransactionRef> &vtx) { | void removeForBlock(const std::vector<CTransactionRef> &vtx) { | ||||
// Short-circuit in the common case of a block being added to the tip | // Short-circuit in the common case of a block being added to the tip | ||||
if (queuedTx.empty()) { | if (queuedTx.empty()) { | ||||
Show All 10 Lines | public: | ||||
// Remove an entry by insertion_order index, and update memory usage. | // Remove an entry by insertion_order index, and update memory usage. | ||||
void removeEntry(indexed_disconnected_transactions::index< | void removeEntry(indexed_disconnected_transactions::index< | ||||
insertion_order>::type::iterator entry) { | insertion_order>::type::iterator entry) { | ||||
cachedInnerUsage -= RecursiveDynamicUsage(*entry); | cachedInnerUsage -= RecursiveDynamicUsage(*entry); | ||||
queuedTx.get<insertion_order>().erase(entry); | queuedTx.get<insertion_order>().erase(entry); | ||||
} | } | ||||
bool isEmpty() { return queuedTx.empty(); } | |||||
markblundeberg: unrelated, probably good to leave out for now | |||||
jasonbcoxUnsubmitted Not Done Inline Actionsagreed. no need to include it until it's needed. jasonbcox: agreed. no need to include it until it's needed. | |||||
void clear() { | void clear() { | ||||
cachedInnerUsage = 0; | cachedInnerUsage = 0; | ||||
queuedTx.clear(); | queuedTx.clear(); | ||||
} | } | ||||
/** | /** | ||||
* Make mempool consistent after a reorg, by re-adding or recursively | * Make mempool consistent after a reorg, by re-adding or recursively | ||||
* erasing disconnected block transactions from the mempool, and also | * erasing disconnected block transactions from the mempool, and also | ||||
Show All 14 Lines |
unrelated, probably good to leave out for now