Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
Show First 20 Lines • Show All 846 Lines • ▼ Show 20 Lines | typedef boost::multi_index_container< | ||||
// sorted by order in the blockchain | // sorted by order in the blockchain | ||||
boost::multi_index::sequenced< | boost::multi_index::sequenced< | ||||
boost::multi_index::tag<insertion_order>>>> | boost::multi_index::tag<insertion_order>>>> | ||||
indexed_disconnected_transactions; | indexed_disconnected_transactions; | ||||
indexed_disconnected_transactions queuedTx; | indexed_disconnected_transactions queuedTx; | ||||
uint64_t cachedInnerUsage = 0; | uint64_t cachedInnerUsage = 0; | ||||
void addTransaction(const CTransactionRef &tx) { | |||||
queuedTx.insert(tx); | |||||
cachedInnerUsage += RecursiveDynamicUsage(tx); | |||||
} | |||||
public: | public: | ||||
// It's almost certainly a logic bug if we don't clear out queuedTx before | // It's almost certainly a logic bug if we don't clear out queuedTx before | ||||
// destruction, as we add to it while disconnecting blocks, and then we | // destruction, as we add to it while disconnecting blocks, and then we | ||||
// need to re-process remaining transactions to ensure mempool consistency. | // need to re-process remaining transactions to ensure mempool consistency. | ||||
// For now, assert() that we've emptied out this object on destruction. | // For now, assert() that we've emptied out this object on destruction. | ||||
// This assert() can always be removed if the reorg-processing code were | // This assert() can always be removed if the reorg-processing code were | ||||
// to be refactored such that this assumption is no longer true (for | // to be refactored such that this assumption is no longer true (for | ||||
// instance if there was some other way we cleaned up the mempool after a | // instance if there was some other way we cleaned up the mempool after a | ||||
// reorg, besides draining this object). | // reorg, besides draining this object). | ||||
~DisconnectedBlockTransactions() { assert(queuedTx.empty()); } | ~DisconnectedBlockTransactions() { assert(queuedTx.empty()); } | ||||
// Estimate the overhead of queuedTx to be 6 pointers + an allocation, as | // Estimate the overhead of queuedTx to be 6 pointers + an allocation, as | ||||
// no exact formula for boost::multi_index_contained is implemented. | // no exact formula for boost::multi_index_contained is implemented. | ||||
size_t DynamicMemoryUsage() const { | size_t DynamicMemoryUsage() const { | ||||
return memusage::MallocUsage(sizeof(CTransactionRef) + | return memusage::MallocUsage(sizeof(CTransactionRef) + | ||||
6 * sizeof(void *)) * | 6 * sizeof(void *)) * | ||||
queuedTx.size() + | queuedTx.size() + | ||||
cachedInnerUsage; | cachedInnerUsage; | ||||
} | } | ||||
const indexed_disconnected_transactions &GetQueuedTx() const { | |||||
return queuedTx; | |||||
} | |||||
// 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); | ||||
void addTransaction(const CTransactionRef &tx) { | |||||
queuedTx.insert(tx); | |||||
cachedInnerUsage += RecursiveDynamicUsage(tx); | |||||
} | |||||
// 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()) { | ||||
return; | return; | ||||
} | } | ||||
for (auto const &tx : vtx) { | for (auto const &tx : vtx) { | ||||
auto it = queuedTx.find(tx->GetId()); | auto it = queuedTx.find(tx->GetId()); | ||||
Show All 36 Lines |