6 #ifndef BITCOIN_TXMEMPOOL_H 7 #define BITCOIN_TXMEMPOOL_H 20 #include "boost/multi_index_container.hpp" 21 #include "boost/multi_index/ordered_index.hpp" 28 return COIN * 144 / 250;
105 int64_t _nTime,
double _entryPriority,
unsigned int _entryHeight,
115 double GetPriority(
unsigned int currentHeight)
const;
219 double f1 = aModFee * bSize;
220 double f2 = aSize * bModFee;
276 bool IsNull()
const {
return (
ptx == NULL &&
n == (uint32_t) -1); }
379 typedef boost::multi_index_container<
381 boost::multi_index::indexed_by<
383 boost::multi_index::ordered_unique<mempoolentry_txid>,
385 boost::multi_index::ordered_non_unique<
386 boost::multi_index::identity<CTxMemPoolEntry>,
390 boost::multi_index::ordered_non_unique<
391 boost::multi_index::identity<CTxMemPoolEntry>,
395 boost::multi_index::ordered_unique<
396 boost::multi_index::identity<CTxMemPoolEntry>,
404 typedef indexed_transaction_set::nth_index<0>::type::iterator
txiter;
407 return a->GetTx().GetHash() < b->GetTx().GetHash();
415 typedef std::map<txiter, setEntries, CompareIteratorByHash>
cacheMap;
422 typedef std::map<txiter, TxLinks, CompareIteratorByHash>
txlinksMap;
425 typedef std::map<CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare>
addressDeltaMap;
431 typedef std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare>
mapSpentIndex;
442 std::map<uint256, std::pair<double, CAmount> >
mapDeltas;
470 std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
477 void remove(
const CTransaction &tx, std::list<CTransaction>& removed,
bool fRecursive =
false);
480 void removeForBlock(
const std::vector<CTransaction>& vtx,
unsigned int nBlockHeight,
481 std::list<CTransaction>& conflicts,
bool fCurrentEstimate =
true);
526 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);
546 void TrimToSize(
size_t sizelimit, std::vector<uint256>* pvNoSpendsRemaining=NULL);
566 return (
mapTx.count(hash) != 0);
613 int maxDescendantsToVisit,
615 const std::set<uint256> &setExclude);
656 if (a.first == b.first)
658 return a.first < b.first;
662 #endif // BITCOIN_TXMEMPOOL_H bool UseDescendantScore(const CTxMemPoolEntry &a)
int64_t lastRollingFeeUpdate
void TrimToSize(size_t sizelimit, std::vector< uint256 > *pvNoSpendsRemaining=NULL)
void removeConflicts(const CTransaction &tx, std::list< CTransaction > &removed)
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove)
std::map< CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare > addressDeltaMap
update_fee_delta(int64_t _feeDelta)
void UpdateFeeDelta(int64_t feeDelta)
unsigned int entryHeight
Priority when entering the mempool.
void setSanityCheck(double dFrequency=1.0)
std::map< uint256, std::vector< CMempoolAddressDeltaKey > > addressDeltaMapInserted
bool GetSpendsCoinbase() const
addressDeltaMapInserted mapAddressInserted
size_t nUsageSize
... and modified size for priority
void queryHashes(std::vector< uint256 > &vtxid)
unsigned int GetHeight() const
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b)
bool ReadFeeEstimates(CAutoFile &filein)
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks=NULL) const
double AllowFreeThreshold()
static const CAmount COIN
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
unsigned int nTransactionsUpdated
Value n means that n times in 2^32 we check.
CInPoint(const CTransaction *ptxIn, uint32_t nIn)
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
bool removeAddressIndex(const uint256 txhash)
double estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks=NULL) const
CAmount nModFeesWithDescendants
... and size
int64_t feeDelta
Legacy sig ops plus P2SH sig op count.
double entryPriority
Local time when entering the mempool.
std::map< COutPoint, CInPoint > mapNextTx
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors)
CFeeRate minReasonableRelayFee
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
void operator()(CTxMemPoolEntry &e)
uint64_t GetCountWithDescendants() const
void UpdateParent(txiter entry, txiter parent, bool add)
void AddTransactionsUpdated(unsigned int n)
indexed_transaction_set mapTx
std::pair< double, CTxMemPool::txiter > TxCoinAgePriority
void UpdateTransactionsFromBlock(const std::vector< uint256 > &hashesToUpdate)
CTxMemPool(const CFeeRate &_minReasonableRelayFee)
uint64_t GetTotalTxSize()
size_t DynamicMemoryUsage() const
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)
unsigned int sigOpCount
keep track of transactions that spend a coinbase
void operator()(CTxMemPoolEntry &e)
std::map< CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare > mapSpentIndex
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
const CAmount & GetFee() const
bool removeSpentIndex(const uint256 txhash)
void UpdateLockPoints(const LockPoints &lp)
bool lookup(uint256 hash, CTransaction &result) const
void ClearPrioritisation(const uint256 hash)
mapSpentIndexInserted mapSpentInserted
void ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta) const
bool getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
bool exists(uint256 hash) const
LockPoints lockPoints
Used for determining the priority of the transaction for mining in a block.
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
bool HasNoInputsOf(const CTransaction &tx) const
result_type operator()(const CTxMemPoolEntry &entry) const
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
bool blockSinceLastRollingFeeBump
uint64_t nSizeWithDescendants
number of descendant transactions
void CalculateDescendants(txiter it, setEntries &setDescendants)
const setEntries & GetMemPoolParents(txiter entry) const
bool operator()(const txiter &a, const txiter &b) const
int64_t nTime
... and total memory usage
void UpdateMinFee(const CFeeRate &_minReasonableRelayFee)
void removeForBlock(const std::vector< CTransaction > &vtx, unsigned int nBlockHeight, std::list< CTransaction > &conflicts, bool fCurrentEstimate=true)
const CTransaction & GetTx() const
size_t DynamicMemoryUsage() const
uint64_t cachedInnerUsage
sum of all mempool tx' byte sizes
addressDeltaMap mapAddress
CTxMemPoolEntry(const CTransaction &_tx, const CAmount &_nFee, int64_t _nTime, double _entryPriority, unsigned int _entryHeight, bool poolHasNoInputsOf, CAmount _inChainInputValue, bool spendsCoinbase, unsigned int nSigOps, LockPoints lp)
... and total fees (all including us)
void UpdateChildrenForRemoval(txiter entry)
static const int ROLLING_FEE_HALFLIFE
void check(const CCoinsViewCache *pcoins) const
CBlockIndex * maxInputBlock
size_t nTxSize
Cached to avoid expensive parent-transaction lookups.
bool AllowFree(double dPriority)
size_t nModSize
... and avoid recomputing tx size
void removeUnchecked(txiter entry)
void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view)
CAmount inChainInputValue
Not dependent on any other txs when it entered the mempool.
std::set< txiter, CompareIteratorByHash > setEntries
void trackPackageRemoved(const CFeeRate &rate)
minimum fee to get into the pool, decreases exponentially
bool operator()(const TxCoinAgePriority &a, const TxCoinAgePriority &b)
size_t DynamicMemoryUsage() const
std::map< uint256, std::pair< double, CAmount > > mapDeltas
CAmount GetModFeesWithDescendants() const
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b)
unsigned int GetSigOpCount() const
bool getAddressIndex(std::vector< std::pair< uint160, int > > &addresses, std::vector< std::pair< CMempoolAddressDeltaKey, CMempoolAddressDelta > > &results)
int64_t GetModifiedFee() const
const setEntries & GetMemPoolChildren(txiter entry) const
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b)
bool HaveCoins(const uint256 &txid) const
uint64_t nCountWithDescendants
Track the height and time at which tx was final.
const uint256 & GetHash() const
void UpdateChild(txiter entry, txiter child, bool add)
double rollingMinimumFeeRate
void addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view)
bool WriteFeeEstimates(CAutoFile &fileout) const
void pruneSpent(const uint256 &hash, CCoins &coins)
CFeeRate GetMinFee(size_t sizelimit) const
bool hadNoDependencies
Chain height when entering the mempool.
CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn)
update_lock_points(const LockPoints &_lp)
double GetPriority(unsigned int currentHeight) const
void PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, const CAmount &nFeeDelta)
std::map< uint256, std::vector< CSpentIndexKey > > mapSpentIndexInserted
bool WasClearAtEntry() const
static const unsigned int MEMPOOL_HEIGHT
boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< mempoolentry_txid >, boost::multi_index::ordered_non_unique< boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByDescendantScore >, boost::multi_index::ordered_non_unique< boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByEntryTime >, boost::multi_index::ordered_unique< boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByScore > > > indexed_transaction_set
CFeeRate estimateFee(int nBlocks) const
CBlockPolicyEstimator * minerPolicyEstimator
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags)
void RemoveStaged(setEntries &stage)
bool spendsCoinbase
Sum of all txin values that are already in blockchain.
bool UpdateForDescendants(txiter updateIt, int maxDescendantsToVisit, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude)
void UpdateState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
uint64_t GetSizeWithDescendants() const
double estimatePriority(int nBlocks) const
bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate=true)
void operator()(CTxMemPoolEntry &e)
unsigned int GetTransactionsUpdated() const
void operator()(CTxMemPoolEntry &e)
const LockPoints & GetLockPoints() const