Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
Show First 20 Lines • Show All 438 Lines • ▼ Show 20 Lines | public: | ||||
* the mempool is consistent with the new chain tip and fully populated. | * the mempool is consistent with the new chain tip and fully populated. | ||||
*/ | */ | ||||
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; | ||||
typedef std::set<txiter, CompareIteratorById> setEntries; | typedef std::set<txiter, CompareIteratorById> setEntries; | ||||
/// Remove after wellington activates as this will be inaccurate | |||||
uint64_t CalculateDescendantMaximum(txiter entry) const | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | |||||
private: | private: | ||||
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); | ||||
/** | /** | ||||
* Track locally submitted transactions to periodically retry initial | * Track locally submitted transactions to periodically retry initial | ||||
Show All 19 Lines | bool CalculateAncestorsAndCheckLimits( | ||||
uint64_t limitDescendantSize, std::string &errString) const | uint64_t limitDescendantSize, std::string &errString) const | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
public: | public: | ||||
indirectmap<COutPoint, const CTransaction *> mapNextTx GUARDED_BY(cs); | indirectmap<COutPoint, const CTransaction *> mapNextTx GUARDED_BY(cs); | ||||
std::map<TxId, Amount> mapDeltas GUARDED_BY(cs); | std::map<TxId, Amount> mapDeltas GUARDED_BY(cs); | ||||
/** | /** | ||||
* Wellington activation latch. This is latched permanently to true in | |||||
* AcceptToMemoryPool the first time a tx arrives and | |||||
* IsWellingtonActivated() returns true. This should be removed after | |||||
* wellington is checkpointed and its mempool-accept/relay rules become | |||||
* retroactively permanent. | |||||
*/ | |||||
std::atomic<bool> wellingtonLatched{false}; | |||||
/** | |||||
* Create a new CTxMemPool. | * Create a new CTxMemPool. | ||||
* Sanity checks will be off by default for performance, because otherwise | * Sanity checks will be off by default for performance, because otherwise | ||||
* accepting transactions becomes O(N^2) where N is the number of | * accepting transactions becomes O(N^2) where N is the number of | ||||
* transactions in the pool. | * transactions in the pool. | ||||
* | * | ||||
* @param[in] check_ratio is the ratio used to determine how often sanity | * @param[in] check_ratio is the ratio used to determine how often sanity | ||||
* checks will run. | * checks will run. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | public: | ||||
/** | /** | ||||
* Reduce the size of the mempool by expiring and then trimming the mempool. | * Reduce the size of the mempool by expiring and then trimming the mempool. | ||||
*/ | */ | ||||
void LimitSize(CCoinsViewCache &coins_cache, size_t limit, | void LimitSize(CCoinsViewCache &coins_cache, size_t limit, | ||||
std::chrono::seconds age) | std::chrono::seconds age) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs, ::cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs, ::cs_main); | ||||
/** | |||||
* Calculate the ancestor and descendant count for the given transaction. | |||||
* The counts include the transaction itself. | |||||
* When ancestors is non-zero (ie, the transaction itself is in the | |||||
* mempool), ancestorsize and ancestorfees will also be set to the | |||||
* appropriate values. | |||||
* | |||||
* NOTE: Since we are removing the unconf. ancestor limits after wellington, | |||||
* this function's existence is a potential DoS. It should not be | |||||
* called after wellington since it relies on calculating quadratic | |||||
* stats. | |||||
*/ | |||||
void GetTransactionAncestry(const TxId &txid, size_t &ancestors, | |||||
size_t &descendants, | |||||
size_t *ancestorsize = nullptr, | |||||
Amount *ancestorfees = nullptr) const; | |||||
/** @returns true if the mempool is fully loaded */ | /** @returns true if the mempool is fully loaded */ | ||||
bool IsLoaded() const; | bool IsLoaded() const; | ||||
/** Sets the current loaded state */ | /** Sets the current loaded state */ | ||||
void SetIsLoaded(bool loaded); | void SetIsLoaded(bool loaded); | ||||
unsigned long size() const { | unsigned long size() const { | ||||
LOCK(cs); | LOCK(cs); | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
private: | private: | ||||
/** Set ancestor state for an entry */ | /** Set ancestor state for an entry */ | ||||
void UpdateEntryForAncestors(txiter it, const setEntries *setAncestors) | void UpdateEntryForAncestors(txiter it, const setEntries *setAncestors) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
/** | /** | ||||
* Update parents of `it` to add/remove it as a child transaction. | * Update parents of `it` to add/remove it as a child transaction. | ||||
*/ | */ | ||||
void UpdateParentsOf( | void UpdateParentsOf(bool add, txiter it) EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
bool add, txiter it, | |||||
const setEntries *setAncestors = nullptr /* only used pre-wellington */) | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | |||||
/** | /** | ||||
* For each transaction being removed, update ancestors and any direct | * For each transaction being removed, update ancestors and any direct | ||||
* children. If updateDescendants is true, then also update in-mempool | * children. If updateDescendants is true, then also update in-mempool | ||||
* descendants' ancestor state. Note that ancestors are only updated before | * descendants' ancestor state. Note that ancestors are only updated before | ||||
* wellington activation. | * wellington activation. | ||||
*/ | */ | ||||
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, | void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, | ||||
bool updateDescendants) | bool updateDescendants) | ||||
▲ Show 20 Lines • Show All 198 Lines • Show Last 20 Lines |