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, specially | |||||
jasonbcox: specially -> especially ? | |||||
* useful on reorgs that results 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 current mempool entries in topological order. Caller must clear | |||||
// the mempool and call updateMempoolForReorg to reprocess these | |||||
// transactions | |||||
void importMempool(); | |||||
// 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 40 Lines |
specially -> especially ?