6 #ifndef FABCOIN_TXMEMPOOL_H 7 #define FABCOIN_TXMEMPOOL_H 24 #include <boost/multi_index_container.hpp> 25 #include <boost/multi_index/ordered_index.hpp> 26 #include <boost/multi_index/hashed_index.hpp> 27 #include <boost/multi_index/sequenced_index.hpp> 29 #include <boost/signals2/signal.hpp> 34 static const uint32_t MEMPOOL_HEIGHT = 0x0FFFFFFF;
96 int64_t _nTime,
unsigned int _entryHeight,
105 size_t GetTxSize()
const;
116 void UpdateDescendantState(int64_t modifySize,
CAmount modifyFee, int64_t modifyCount);
118 void UpdateAncestorState(int64_t modifySize,
CAmount modifyFee, int64_t modifyCount,
int modifySigOps);
121 void UpdateFeeDelta(int64_t feeDelta);
143 modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
158 modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
202 return tx->GetHash();
215 bool fUseADescendants = UseDescendantScore(a);
216 bool fUseBDescendants = UseDescendantScore(b);
225 double f1 = aModFee * bSize;
226 double f2 = aSize * bModFee;
282 double f1 = aFees * bSize;
283 double f2 = aSize * bFees;
302 if(fAHasCreateOrCall || fBHasCreateOrCall) {
304 if(fAHasCreateOrCall != fBHasCreateOrCall) {
305 return fAHasCreateOrCall ?
false :
true;
479 void trackPackageRemoved(
const CFeeRate& rate);
483 static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12;
485 typedef boost::multi_index_container<
487 boost::multi_index::indexed_by<
489 boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
491 boost::multi_index::ordered_non_unique<
492 boost::multi_index::tag<descendant_score>,
493 boost::multi_index::identity<CTxMemPoolEntry>,
497 boost::multi_index::ordered_non_unique<
498 boost::multi_index::tag<entry_time>,
499 boost::multi_index::identity<CTxMemPoolEntry>,
503 boost::multi_index::ordered_unique<
504 boost::multi_index::tag<mining_score>,
505 boost::multi_index::identity<CTxMemPoolEntry>,
509 boost::multi_index::ordered_non_unique<
510 boost::multi_index::tag<ancestor_score>,
511 boost::multi_index::identity<CTxMemPoolEntry>,
515 boost::multi_index::ordered_non_unique<
516 boost::multi_index::tag<ancestor_score_or_gas_price>,
517 boost::multi_index::identity<CTxMemPoolEntry>,
526 typedef indexed_transaction_set::nth_index<0>::type::iterator
txiter;
531 return a->GetTx().GetHash() < b->GetTx().GetHash();
536 const setEntries & GetMemPoolParents(txiter entry)
const;
537 const setEntries & GetMemPoolChildren(txiter entry)
const;
539 typedef std::map<txiter, setEntries, CompareIteratorByHash>
cacheMap;
546 typedef std::map<txiter, TxLinks, CompareIteratorByHash>
txlinksMap;
549 void UpdateParent(txiter entry, txiter parent,
bool add);
550 void UpdateChild(txiter entry, txiter child,
bool add);
552 std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore()
const;
569 void setSanityCheck(
double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967295.0; }
575 bool addUnchecked(
const uint256& hash,
const CTxMemPoolEntry &entry,
bool validFeeEstimate =
true);
576 bool addUnchecked(
const uint256& hash,
const CTxMemPoolEntry &entry, setEntries &setAncestors,
bool validFeeEstimate =
true);
579 void removeForReorg(
const CCoinsViewCache *pcoins,
unsigned int nMemPoolHeight,
int flags);
581 void removeForBlock(
const std::vector<CTransactionRef>& vtx,
unsigned int nBlockHeight);
585 bool CompareDepthAndScore(
const uint256& hasha,
const uint256& hashb);
586 void queryHashes(std::vector<uint256>& vtxid);
588 unsigned int GetTransactionsUpdated()
const;
589 void AddTransactionsUpdated(
unsigned int n);
597 void PrioritiseTransaction(
const uint256& hash,
const CAmount& nFeeDelta);
599 void ClearPrioritisation(
const uint256 hash);
620 void UpdateTransactionsFromBlock(
const std::vector<uint256> &vHashesToUpdate);
632 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;
637 void CalculateDescendants(txiter it, setEntries &setDescendants);
645 CFeeRate GetMinFee(
size_t sizelimit)
const;
651 void TrimToSize(
size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining=
nullptr);
654 int Expire(int64_t
time);
657 bool TransactionWithinChainLimit(
const uint256& txid,
size_t chainLimit)
const;
674 return (mapTx.count(hash) != 0);
680 auto it = mapTx.find(outpoint.
hash);
681 return (it != mapTx.end() && outpoint.
n < it->GetTx().vout.size());
686 std::vector<TxMempoolInfo> infoAll()
const;
688 size_t DynamicMemoryUsage()
const;
707 void UpdateForDescendants(txiter updateIt,
708 cacheMap &cachedDescendants,
709 const std::set<uint256> &setExclude);
711 void UpdateAncestorsOf(
bool add, txiter hash, setEntries &setAncestors);
713 void UpdateEntryForAncestors(txiter it,
const setEntries &setAncestors);
717 void UpdateForRemoveFromMempool(
const setEntries &entriesToRemove,
bool updateDescendants);
719 void UpdateChildrenForRemoval(txiter entry);
750 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
751 bool HaveCoin(
const COutPoint &outpoint)
const override;
774 typedef boost::multi_index_container<
776 boost::multi_index::indexed_by<
778 boost::multi_index::hashed_unique<
779 boost::multi_index::tag<txid_index>,
784 boost::multi_index::sequenced<
785 boost::multi_index::tag<insertion_order>
801 uint64_t cachedInnerUsage = 0;
806 return memusage::MallocUsage(
sizeof(CTransactionRef) + 6 *
sizeof(
void*)) * queuedTx.size() + cachedInnerUsage;
812 cachedInnerUsage += RecursiveDynamicUsage(tx);
819 if (queuedTx.empty()) {
822 for (
auto const &tx : vtx) {
823 auto it = queuedTx.find(tx->GetHash());
824 if (it != queuedTx.end()) {
825 cachedInnerUsage -= RecursiveDynamicUsage(*it);
832 void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
834 cachedInnerUsage -= RecursiveDynamicUsage(*entry);
840 cachedInnerUsage = 0;
845 #endif // FABCOIN_TXMEMPOOL_H
size_t vTxHashesIdx
Index in mempool's vTxHashes.
const CAmount & GetMinGasPrice() const
Information about a mempool transaction.
CAmount GetModFeesWithAncestors() const
update_fee_delta(int64_t _feeDelta)
CAmount nModFeesWithDescendants
... and total fees (all including us)
void UpdateLockPoints(const LockPoints &lp)
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
unsigned int GetHeight() const
size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
bool exists(const COutPoint &outpoint) const
uint64_t GetCountWithAncestors() const
uint64_t GetCountWithDescendants() const
~DisconnectedBlockTransactions()
boost::signals2::signal< void(CTransactionRef)> NotifyEntryAdded
size_t GetTxWeight() const
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
size_t DynamicMemoryUsage() const
uint64_t GetTotalTxSize()
std::set< txiter, CompareIteratorByHash > setEntries
void addTransaction(const CTransactionRef &tx)
assert(len-trim+(2 *lenIndices)<=WIDTH)
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
int64_t sigOpCost
Total sigop cost.
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
std::shared_ptr< const CTransaction > CTransactionRef
uint64_t nCountWithDescendants
number of descendant transactions
int64_t lastRollingFeeUpdate
const LockPoints & GetLockPoints() const
CAmount nFee
Cached to avoid expensive parent-transaction lookups.
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
int64_t nFeeDelta
The fee delta.
indirectmap< COutPoint, const CTransaction * > mapNextTx
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
CTransactionRef tx
The transaction itself.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
indexed_transaction_set mapTx
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
int64_t CAmount
Amount in lius (Can be negative)
uint64_t GetSizeWithDescendants() const
bool blockSinceLastRollingFeeBump
Removed in size limiting.
indexed_disconnected_transactions queuedTx
const CAmount & GetFee() const
int64_t nSigOpCostWithAncestors
void setSanityCheck(double dFrequency=1.0)
std::vector< std::pair< uint256, txiter > > vTxHashes
All tx witness hashes/entries in mapTx, in random order.
void UpdateFeeDelta(int64_t feeDelta)
size_t nUsageSize
... and total memory usage
CTransactionRef GetSharedTx() const
uint64_t nSizeWithAncestors
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
Abstract view on the open txout dataset.
void removeForBlock(const std::vector< CTransactionRef > &vtx)
We want to be able to estimate feerates that are needed on tx's to be included in a certain number of...
DisconnectedBlockTransactions.
CAmount nMinGasPrice
The minimum gas price among the contract outputs of the tx.
size_t DynamicMemoryUsage() const
CAmount GetModFeesWithDescendants() const
Removed for reorganization.
std::map< uint256, CAmount > mapDeltas
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_unique< boost::multi_index::tag< mining_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByScore >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ancestor_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByAncestorFee >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ancestor_score_or_gas_price >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByAncestorFeeOrGasPrice > > > indexed_transaction_set
int64_t GetSigOpCost() const
bool GetSpendsCoinbase() const
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Sort an entry by max(score/size of entry's tx, score/size with all descendants).
CAmount nModFeesWithAncestors
unsigned int nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int modifySigOps)
Manually removed or unknown reason.
int64_t nTime
Local time when entering the mempool.
An outpoint - a combination of a transaction hash and an index n into its vout.
uint64_t nSizeWithDescendants
... and size
bool UseDescendantScore(const CTxMemPoolEntry &a) const
uint64_t GetSizeWithAncestors() const
uint64_t totalTxSize
sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discount...
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
bool exists(uint256 hash) const
int64_t nTime
Time the transaction entered the mempool.
bool spendsCoinbase
keep track of transactions that spend a coinbase
const CTransaction & GetTx() const
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
int64_t GetModifiedFee() const
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
The block chain is a tree shaped structure starting with the genesis block at the root...
LockPoints lockPoints
Track the height and time at which tx was final.
uint32_t nCheckFrequency
Value n means that n times in 2^32 we check.
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost)
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
bool HasCreateOrCall() const
uint64_t nCountWithAncestors
Fee rate in liu per kilobyte: CAmount / kB.
update_lock_points(const LockPoints &_lp)
const uint256 & GetHash() const
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
int64_t GetSigOpCostWithAncestors() const
boost::signals2::signal< void(CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved
CFeeRate feeRate
Feerate of the transaction.
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Sort by score of entry ((fee+delta)/size) in descending order.
size_t operator()(const uint256 &txid) const
const CTxMemPool & mempool
Removed for conflict with in-block transaction.
CBlockPolicyEstimator * minerPolicyEstimator
CBlockIndex * maxInputBlock
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
CCoinsView that brings transactions from a memorypool into view.
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
bool operator()(const txiter &a, const txiter &b) const
unsigned int entryHeight
Chain height when entering the mempool.