Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | struct LockPoints { | ||||
// As long as the current chain descends from the highest height block | // As long as the current chain descends from the highest height block | ||||
// containing one of the inputs used in the calculation, then the cached | // containing one of the inputs used in the calculation, then the cached | ||||
// values are still valid even after a reorg. | // values are still valid even after a reorg. | ||||
CBlockIndex *maxInputBlock; | CBlockIndex *maxInputBlock; | ||||
LockPoints() : height(0), time(0), maxInputBlock(nullptr) {} | LockPoints() : height(0), time(0), maxInputBlock(nullptr) {} | ||||
}; | }; | ||||
struct CompareIteratorById { | |||||
// SFINAE for T where T is either a pointer type (e.g., a txiter) or a | |||||
// reference_wrapper<T> (e.g. a wrapped CTxMemPoolEntry&) | |||||
template <typename T> | |||||
bool operator()(const std::reference_wrapper<T> &a, | |||||
const std::reference_wrapper<T> &b) const { | |||||
return a.get().GetTx().GetId() < b.get().GetTx().GetId(); | |||||
} | |||||
template <typename T> bool operator()(const T &a, const T &b) const { | |||||
return a->GetTx().GetId() < b->GetTx().GetId(); | |||||
} | |||||
}; | |||||
/** \class CTxMemPoolEntry | /** \class CTxMemPoolEntry | ||||
* | * | ||||
* CTxMemPoolEntry stores data about the corresponding transaction, as well as | * CTxMemPoolEntry stores data about the corresponding transaction, as well as | ||||
* data about all in-mempool transactions that depend on the transaction | * data about all in-mempool transactions that depend on the transaction | ||||
* ("descendant" transactions). | * ("descendant" transactions). | ||||
* | * | ||||
* When a new entry is added to the mempool, we update the descendant state | * When a new entry is added to the mempool, we update the descendant state | ||||
* (nCountWithDescendants, nSizeWithDescendants, and nModFeesWithDescendants) | * (nCountWithDescendants, nSizeWithDescendants, and nModFeesWithDescendants) | ||||
* for all ancestors of the newly added transaction. | * for all ancestors of the newly added transaction. | ||||
*/ | */ | ||||
class CTxMemPoolEntry { | class CTxMemPoolEntry { | ||||
public: | |||||
typedef std::reference_wrapper<const CTxMemPoolEntry> CTxMemPoolEntryRef; | |||||
// two aliases, should the types ever diverge | |||||
typedef std::set<CTxMemPoolEntryRef, CompareIteratorById> Parents; | |||||
typedef std::set<CTxMemPoolEntryRef, CompareIteratorById> Children; | |||||
private: | private: | ||||
const CTransactionRef tx; | const CTransactionRef tx; | ||||
mutable Parents m_parents; | |||||
mutable Children m_children; | |||||
//! Cached to avoid expensive parent-transaction lookups | //! Cached to avoid expensive parent-transaction lookups | ||||
const Amount nFee; | const Amount nFee; | ||||
//! ... and avoid recomputing tx size | //! ... and avoid recomputing tx size | ||||
const size_t nTxSize; | const size_t nTxSize; | ||||
//! ... and total memory usage | //! ... and total memory usage | ||||
const size_t nUsageSize; | const size_t nUsageSize; | ||||
//! Local time when entering the mempool | //! Local time when entering the mempool | ||||
const int64_t nTime; | const int64_t nTime; | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | public: | ||||
uint64_t GetCountWithAncestors() const { return nCountWithAncestors; } | uint64_t GetCountWithAncestors() const { return nCountWithAncestors; } | ||||
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } | uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } | ||||
uint64_t GetVirtualSizeWithAncestors() const; | uint64_t GetVirtualSizeWithAncestors() const; | ||||
Amount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } | Amount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } | ||||
int64_t GetSigOpCountWithAncestors() const { | int64_t GetSigOpCountWithAncestors() const { | ||||
return nSigOpCountWithAncestors; | return nSigOpCountWithAncestors; | ||||
} | } | ||||
const Parents &GetMemPoolParentsConst() const { return m_parents; } | |||||
const Children &GetMemPoolChildrenConst() const { return m_children; } | |||||
Parents &GetMemPoolParents() const { return m_parents; } | |||||
Children &GetMemPoolChildren() const { return m_children; } | |||||
//! Index in mempool's vTxHashes | //! Index in mempool's vTxHashes | ||||
mutable size_t vTxHashesIdx; | mutable size_t vTxHashesIdx; | ||||
//! epoch when last touched, useful for graph algorithms | //! epoch when last touched, useful for graph algorithms | ||||
mutable uint64_t m_epoch; | mutable uint64_t m_epoch; | ||||
}; | }; | ||||
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index. | // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index. | ||||
struct update_descendant_state { | struct update_descendant_state { | ||||
▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | public: | ||||
*/ | */ | ||||
mutable RecursiveMutex cs; | mutable RecursiveMutex cs; | ||||
indexed_transaction_set mapTx GUARDED_BY(cs); | indexed_transaction_set mapTx GUARDED_BY(cs); | ||||
using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator; | using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator; | ||||
//! All tx hashes/entries in mapTx, in random order | //! All tx hashes/entries in mapTx, in random order | ||||
std::vector<std::pair<TxHash, txiter>> vTxHashes GUARDED_BY(cs); | std::vector<std::pair<TxHash, txiter>> vTxHashes GUARDED_BY(cs); | ||||
struct CompareIteratorById { | |||||
bool operator()(const txiter &a, const txiter &b) const { | |||||
return a->GetTx().GetId() < b->GetTx().GetId(); | |||||
} | |||||
}; | |||||
typedef std::set<txiter, CompareIteratorById> setEntries; | typedef std::set<txiter, CompareIteratorById> setEntries; | ||||
const setEntries &GetMemPoolParents(txiter entry) const | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | |||||
const setEntries &GetMemPoolChildren(txiter entry) const | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | |||||
uint64_t CalculateDescendantMaximum(txiter entry) const | uint64_t CalculateDescendantMaximum(txiter entry) const | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
private: | private: | ||||
typedef std::map<txiter, setEntries, CompareIteratorById> cacheMap; | typedef std::map<txiter, setEntries, CompareIteratorById> cacheMap; | ||||
struct TxLinks { | |||||
setEntries parents; | |||||
setEntries children; | |||||
}; | |||||
typedef std::map<txiter, TxLinks, CompareIteratorById> txlinksMap; | |||||
txlinksMap mapLinks; | |||||
void UpdateParent(txiter entry, txiter parent, bool add) | void UpdateParent(txiter entry, txiter parent, bool add) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
void UpdateChild(txiter entry, txiter child, bool add) | void UpdateChild(txiter entry, txiter child, bool add) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
std::vector<indexed_transaction_set::const_iterator> | std::vector<indexed_transaction_set::const_iterator> | ||||
GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs); | GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
▲ Show 20 Lines • Show All 475 Lines • Show Last 20 Lines |