6 #ifndef BITCOIN_TXMEMPOOL_H 7 #define BITCOIN_TXMEMPOOL_H 26 #include <boost/multi_index_container.hpp> 27 #include <boost/multi_index/hashed_index.hpp> 28 #include <boost/multi_index/ordered_index.hpp> 29 #include <boost/multi_index/sequenced_index.hpp> 30 #include <boost/signals2/signal.hpp> 96 int64_t _nTime,
unsigned int _entryHeight,
199 return tx->GetHash();
212 double a_mod_fee, a_size, b_mod_fee, b_size;
218 double f1 = a_mod_fee * b_size;
219 double f2 = a_size * b_mod_fee;
285 double a_mod_fee, a_size, b_mod_fee, b_size;
291 double f1 = a_mod_fee * b_size;
292 double f2 = a_size * b_mod_fee;
295 return a.GetTx().GetHash() < b.GetTx().GetHash();
301 template <
typename T>
306 double f1 = (double)a.GetModifiedFee() * a.GetSizeWithAncestors();
307 double f2 = (double)a.GetModFeesWithAncestors() * a.GetTxSize();
310 mod_fee = a.GetModFeesWithAncestors();
311 size = a.GetSizeWithAncestors();
313 mod_fee = a.GetModifiedFee();
314 size = a.GetTxSize();
465 typedef boost::multi_index_container<
467 boost::multi_index::indexed_by<
469 boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
471 boost::multi_index::ordered_non_unique<
472 boost::multi_index::tag<descendant_score>,
473 boost::multi_index::identity<CTxMemPoolEntry>,
477 boost::multi_index::ordered_non_unique<
478 boost::multi_index::tag<entry_time>,
479 boost::multi_index::identity<CTxMemPoolEntry>,
483 boost::multi_index::ordered_non_unique<
484 boost::multi_index::tag<ancestor_score>,
485 boost::multi_index::identity<CTxMemPoolEntry>,
521 using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
522 std::vector<std::pair<uint256, txiter>> vTxHashes
GUARDED_BY(
cs);
526 return a->GetTx().GetHash() < b->GetTx().GetHash();
535 typedef std::map<txiter, setEntries, CompareIteratorByHash>
cacheMap;
542 typedef std::map<txiter, TxLinks, CompareIteratorByHash>
txlinksMap;
565 void setSanityCheck(
double dFrequency = 1.0) {
LOCK(
cs); nCheckFrequency = static_cast<uint32_t>(dFrequency * 4294967295.0); }
690 return (mapTx.count(hash) != 0);
695 std::vector<TxMempoolInfo>
infoAll()
const;
783 typedef boost::multi_index_container<
785 boost::multi_index::indexed_by<
787 boost::multi_index::hashed_unique<
788 boost::multi_index::tag<txid_index>,
793 boost::multi_index::sequenced<
794 boost::multi_index::tag<insertion_order>
831 for (
auto const &tx : vtx) {
841 void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
854 #endif // BITCOIN_TXMEMPOOL_H Definition: txmempool.h:322
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
int64_t lastRollingFeeUpdate
Definition: txmempool.h:453
uint64_t GetCountWithAncestors() const
Definition: txmempool.h:128
int64_t GetSigOpCostWithAncestors() const
Definition: txmempool.h:131
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: thread_annotations.h:13
const uint64_t k1
Definition: txmempool.h:361
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Definition: siphash.cpp:94
update_fee_delta(int64_t _feeDelta)
Definition: txmempool.h:170
void UpdateFeeDelta(int64_t feeDelta)
Definition: txmempool.cpp:38
CAmount nModFeesWithAncestors
Definition: txmempool.h:91
size_t vTxHashesIdx
Index in mempool's vTxHashes.
Definition: txmempool.h:133
Definition: txmempool.h:266
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:247
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Definition: txmempool.cpp:890
boost::signals2::signal< void(CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved
Definition: txmempool.h:700
uint64_t cachedInnerUsage
Definition: txmempool.h:810
int height
Definition: txmempool.h:43
int64_t modifyCount
Definition: txmempool.h:149
void setSanityCheck(double dFrequency=1.0)
Definition: txmempool.h:565
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:779
int64_t modifySize
Definition: txmempool.h:162
bool GetSpendsCoinbase() const
Definition: txmempool.h:126
Definition: txmempool.h:189
unsigned int GetHeight() const
Definition: txmempool.h:106
Definition: txmempool.h:329
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:857
size_t GetTxWeight() const
Definition: txmempool.h:104
Definition: txmempool.h:38
void addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:936
size_t GetTxSize() const
Definition: txmempool.cpp:50
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:544
const uint64_t k0
Definition: txmempool.h:361
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
Definition: txmempool.cpp:305
setEntries parents
Definition: txmempool.h:538
CTransactionRef GetSharedTx() const
Definition: txmempool.h:101
void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:225
Manually removed or unknown reason.
uint64_t totalTxSize
sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discount...
Definition: txmempool.h:450
uint32_t nCheckFrequency GUARDED_BY(cs)
Value n means that n times in 2^32 we check.
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
Definition: txmempool.h:535
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:573
bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb)
Definition: txmempool.cpp:717
std::map< uint256, CAmount > mapDeltas
Definition: txmempool.h:552
Definition: txmempool.h:537
Removed in size limiting.
Definition: txmempool.h:178
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:255
void UpdateTransactionsFromBlock(const std::vector< uint256 > &vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:105
uint64_t GetSizeWithAncestors() const
Definition: txmempool.h:129
CAmount nModFeesWithDescendants
... and total fees (all including us)
Definition: txmempool.h:86
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
Definition: txmempool.h:78
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:434
int64_t nTime
Definition: txmempool.h:335
int64_t feeDelta
Definition: txmempool.h:175
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Definition: txmempool.cpp:811
Definition: txmempool.h:753
const setEntries & GetMemPoolChildren(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:973
const setEntries & GetMemPoolParents(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:965
LockPoints()
Definition: txmempool.h:50
Definition: txmempool.h:321
std::vector< indexed_transaction_set::const_iterator > GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:748
Definition: txmempool.h:357
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:143
SaltedTxidHasher()
Definition: txmempool.cpp:1100
MemPoolRemovalReason
Definition: txmempool.h:347
uint64_t GetCountWithDescendants() const
Definition: txmempool.h:122
void UpdateParent(txiter entry, txiter parent, bool add)
Definition: txmempool.cpp:955
void removeUnchecked(txiter entry, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:403
void AddTransactionsUpdated(unsigned int n)
Definition: txmempool.cpp:347
Definition: txmempool.h:168
boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< mempoolentry_txid, SaltedTxidHasher >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< descendant_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByDescendantScore >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< entry_time >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByEntryTime >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ancestor_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByAncestorFee > > > indexed_transaction_set
Definition: txmempool.h:489
Definition: txmempool.h:67
boost::optional< txiter > GetIter(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:863
void queryHashes(std::vector< uint256 > &vtxid) const
Definition: txmempool.cpp:762
CAmount modifyFee
Definition: txmempool.h:148
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:182
void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
Definition: txmempool.h:302
Definition: txmempool.h:207
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
Definition: txmempool.h:139
const CAmount & GetFee() const
Definition: txmempool.h:102
CTransactionRef tx
Definition: txmempool.h:332
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
Definition: txmempool.cpp:314
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:521
void UpdateLockPoints(const LockPoints &lp)
Definition: txmempool.cpp:45
int64_t modifyCount
Definition: txmempool.h:164
int64_t nSigOpCostWithAncestors
Definition: txmempool.h:92
void ClearPrioritisation(const uint256 hash)
Definition: txmempool.cpp:851
Definition: txmempool.h:152
int64_t CAmount
Definition: amount.h:12
CTransactionRef get(const uint256 &hash) const
Definition: txmempool.cpp:793
Removed for reorganization.
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: txmempool.h:79
static const uint32_t MEMPOOL_HEIGHT
Definition: txmempool.h:36
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
Definition: txmempool.h:542
int Expire(int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:920
result_type operator()(const CTxMemPoolEntry &entry) const
Definition: txmempool.h:192
bool blockSinceLastRollingFeeBump
Definition: txmempool.h:454
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:888
uint64_t nSizeWithDescendants
... and size
Definition: txmempool.h:85
bool operator()(const txiter &a, const txiter &b) const
Definition: txmempool.h:525
Definition: transaction.h:270
Definition: transaction.h:18
unsigned int uint32_t
Definition: stdint.h:21
void removeForBlock(const std::vector< CTransactionRef > &vtx)
Definition: txmempool.h:825
#define LOCK(cs)
Definition: sync.h:182
const CTransaction & GetTx() const
Definition: txmempool.h:100
Removed for conflict with in-block transaction.
Definition: txmempool.h:779
~DisconnectedBlockTransactions()
Definition: txmempool.h:807
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:906
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Definition: txmempool.h:451
unsigned long long uint64_t
Definition: stdint.h:22
void clear()
Definition: txmempool.cpp:586
void clear()
Definition: txmempool.h:847
Definition: txmempool.h:782
CCriticalSection cs_main
Definition: validation.cpp:100
static const int ROLLING_FEE_HALFLIFE
Definition: txmempool.h:463
void check(const CCoinsViewCache *pcoins) const
Definition: txmempool.cpp:601
indexed_disconnected_transactions queuedTx
Definition: txmempool.h:809
CBlockIndex * maxInputBlock
Definition: txmempool.h:48
void GetTransactionAncestry(const uint256 &txid, size_t &ancestors, size_t &descendants) const
Definition: txmempool.cpp:1078
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:457
const CTxMemPool & mempool
Definition: txmempool.h:756
void addTransaction(const CTransactionRef &tx)
Definition: txmempool.h:818
void SetIsLoaded(bool loaded)
Definition: txmempool.cpp:1094
size_t operator()(const uint256 &txid) const
Definition: txmempool.h:366
uint64_t nCountWithAncestors
Definition: txmempool.h:89
Definition: txmempool.h:780
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:524
bool exists(const uint256 &hash) const
Definition: txmempool.h:687
CFeeRate feeRate
Definition: txmempool.h:338
const CTransactionRef tx
Definition: txmempool.h:70
uint256 result_type
Definition: txmempool.h:191
int64_t time
Definition: txmempool.h:44
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:529
static size_t MallocUsage(size_t alloc)
Definition: memusage.h:48
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:269
bool m_is_loaded GUARDED_BY(cs)
Definition: txmempool.h:459
const size_t nUsageSize
... and total memory usage
Definition: txmempool.h:73
setEntries GetIterSet(const std::set< uint256 > &hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:870
int64_t GetTime() const
Definition: txmempool.h:105
txlinksMap mapLinks
Definition: txmempool.h:543
size_t DynamicMemoryUsage() const
Definition: txmempool.h:109
int flags
Definition: bitcoin-tx.cpp:507
CAmount GetModFeesWithDescendants() const
Definition: txmempool.h:124
const CAmount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: txmempool.h:71
Definition: txmempool.h:524
Definition: txmempool.h:320
Definition: uint256.h:121
Definition: indirectmap.h:22
int64_t GetModifiedFee() const
Definition: txmempool.h:108
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:210
size_t DynamicMemoryUsage() const
Definition: txmempool.h:814
Definition: txmempool.h:443
bool HasNoInputsOf(const CTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:880
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:158
uint32_t f2(uint32_t x, uint32_t y, uint32_t z)
Definition: ripemd160.cpp:18
boost::signals2::signal< void(CTransactionRef)> NotifyEntryAdded
Definition: txmempool.h:699
void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
Definition: txmempool.h:228
uint64_t nCountWithDescendants
number of descendant transactions
Definition: txmempool.h:84
void UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:58
const LockPoints & lp
Definition: txmempool.h:185
const uint256 & GetHash() const
Definition: transaction.h:322
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:1013
void UpdateChild(txiter entry, txiter child, bool add)
Definition: txmempool.cpp:945
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost)
Definition: txmempool.h:154
boost::multi_index_container< CTransactionRef, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::tag< txid_index >, mempoolentry_txid, SaltedTxidHasher >, boost::multi_index::sequenced< boost::multi_index::tag< insertion_order > > > > indexed_disconnected_transactions
Definition: txmempool.h:797
int64_t nFeeDelta
Definition: txmempool.h:341
setEntries children
Definition: txmempool.h:539
int64_t GetSigOpCost() const
Definition: txmempool.h:107
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:912
bool IsLoaded() const
Definition: txmempool.cpp:1088
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
Definition: txmempool.h:455
const unsigned int entryHeight
Chain height when entering the mempool.
Definition: txmempool.h:75
CAmount GetModFeesWithAncestors() const
Definition: txmempool.h:130
uint64_t GetTotalTxSize() const
Definition: txmempool.h:681
CFeeRate GetMinFee(size_t sizelimit) const
Definition: txmempool.cpp:981
Definition: txmempool.h:252
const int64_t sigOpCost
Total sigop cost.
Definition: txmempool.h:77
void cs_main
Definition: txmempool.h:574
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:487
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
signed long long int64_t
Definition: stdint.h:18
bool operator()(const T &a, const T &b) const
Definition: txmempool.h:283
update_lock_points(const LockPoints &_lp)
Definition: txmempool.h:180
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
Definition: txmempool.h:841
unsigned long size() const
Definition: txmempool.h:675
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:239
CTxMemPoolEntry(const CTransactionRef &_tx, const CAmount &_nFee, int64_t _nTime, unsigned int _entryHeight, bool spendsCoinbase, int64_t nSigOpsCost, LockPoints lp)
Definition: txmempool.cpp:20
int64_t modifySize
Definition: txmempool.h:147
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:148
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:210
const size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
Definition: txmempool.h:72
CBlockPolicyEstimator * minerPolicyEstimator
Definition: txmempool.h:448
auto it
Definition: validation.cpp:360
uint32_t f1(uint32_t x, uint32_t y, uint32_t z)
Definition: ripemd160.cpp:17
bool isSpent(const COutPoint &outpoint) const
Definition: txmempool.cpp:336
uint64_t GetSizeWithDescendants() const
Definition: txmempool.h:123
const int64_t nTime
Local time when entering the mempool.
Definition: txmempool.h:74
const bool spendsCoinbase
keep track of transactions that spend a coinbase
Definition: txmempool.h:76
Definition: txmempool.h:279
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:1056
int64_t modifySigOpsCost
Definition: txmempool.h:165
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:342
void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const
Definition: txmempool.cpp:841
CAmount modifyFee
Definition: txmempool.h:163
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:172
RecursiveMutex cs
Definition: txmempool.h:518
Definition: txmempool.h:137
TxMempoolInfo info(const uint256 &hash) const
Definition: txmempool.cpp:802
const LockPoints & GetLockPoints() const
Definition: txmempool.h:110
LockPoints lp
Definition: mempool_eviction.cpp:18
uint64_t nSizeWithAncestors
Definition: txmempool.h:90
std::atomic< unsigned int > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:447
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:1005