7 #ifndef PIVX_TXMEMPOOL_H
8 #define PIVX_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>
34 static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
87 int64_t _nTime,
unsigned int _entryHeight,
88 bool _spendsCoinbaseOrCoinstake,
unsigned int nSigOps);
91 std::shared_ptr<const CTransaction>
GetSharedTx()
const {
return this->
tx; }
175 return tx->GetHash();
198 double f1 = aModFee * bSize;
199 double f2 = aSize * bModFee;
255 double f1 = aFees * bSize;
256 double f2 = aSize * bFees;
412 typedef boost::multi_index_container<
414 boost::multi_index::indexed_by<
416 boost::multi_index::hashed_unique<mempoolentry_txid, SaltedIdHasher>,
418 boost::multi_index::ordered_non_unique<
419 boost::multi_index::tag<descendant_score>,
420 boost::multi_index::identity<CTxMemPoolEntry>,
424 boost::multi_index::ordered_non_unique<
425 boost::multi_index::tag<entry_time>,
426 boost::multi_index::identity<CTxMemPoolEntry>,
430 boost::multi_index::ordered_unique<
431 boost::multi_index::tag<mining_score>,
432 boost::multi_index::identity<CTxMemPoolEntry>,
436 boost::multi_index::ordered_non_unique<
437 boost::multi_index::tag<ancestor_score>,
438 boost::multi_index::identity<CTxMemPoolEntry>,
474 typedef indexed_transaction_set::nth_index<0>::type::iterator
txiter;
478 return a->GetTx().GetHash() < b->GetTx().GetHash();
487 typedef std::map<txiter, setEntries, CompareIteratorByHash>
cacheMap;
494 typedef std::map<txiter, TxLinks, CompareIteratorByHash>
txlinksMap;
543 void removeForBlock(
const std::vector<CTransactionRef>& vtx,
unsigned int nBlockHeight);
596 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;
615 void TrimToSize(
size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining =
nullptr);
643 return (
mapTx.count(hash) != 0);
650 return (it !=
mapTx.end() && outpoint.
n < it->GetTx().vout.size());
655 std::vector<TxMempoolInfo>
infoAll()
const;
691 const std::set<uint256> &setExclude);
759 typedef boost::multi_index_container<
761 boost::multi_index::indexed_by<
763 boost::multi_index::hashed_unique<
764 boost::multi_index::tag<txid_index>,
769 boost::multi_index::sequenced<
770 boost::multi_index::tag<insertion_order>
807 for (
auto const &tx : vtx) {
808 auto it =
queuedTx.find(tx->GetHash());
817 void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
int64_t CAmount
Amount in PIV (Can be negative)
Non-refcounted RAII wrapper for FILE*.
We want to be able to estimate feerates or priorities that are needed on tx's to be included in a cer...
CCoinsView backed by another CCoinsView.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Abstract view on the open txout dataset.
CCoinsView that brings transactions from a memorypool into view.
bool HaveCoin(const COutPoint &outpoint) const
Just check whether we have data for a given outpoint.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool GetNullifier(const uint256 &nullifier) const
Determine whether a nullifier is spent or not.
CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn)
Fee rate in PIV per kilobyte: CAmount / kB.
A reference to a CKey: the Hash160 of its serialized public key.
An outpoint - a combination of a transaction hash and an index n into its vout.
The basic transaction that is broadcasted on the network and contained in blocks.
const uint256 & GetHash() const
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
void UpdateFeeDelta(int64_t feeDelta)
size_t nTxSize
Cached to avoid expensive parent-transaction lookups.
unsigned int entryHeight
Local time when entering the mempool.
const CTransaction & GetTx() const
int64_t feeDelta
Legacy sig ops plus P2SH sig op count.
unsigned int GetHeight() const
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
size_t nUsageSize
... and avoid recomputing tx size
bool GetSpendsCoinbaseOrCoinstake() const
int64_t nTime
... and checking if it contains shielded spends/outputs
uint64_t GetCountWithDescendants() const
bool HasZerocoins() const
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int modifySigOps)
CAmount nModFeesWithAncestors
unsigned int nSigOpCountWithAncestors
CAmount GetModFeesWithDescendants() const
bool hasZerocoins
... and fee per kB
uint64_t nCountWithDescendants
Used for determining the priority of the transaction for mining in a block.
unsigned int sigOpCount
keep track of transactions that spend a coinbase or a coinstake
unsigned int GetSigOpCount() const
bool m_isShielded
... and checking if it contains zPIV (mints/spends)
std::shared_ptr< const CTransaction > GetSharedTx() const
uint64_t GetSizeWithAncestors() const
uint64_t nSizeWithDescendants
number of descendant transactions
CTxMemPoolEntry(const CTransactionRef &_tx, const CAmount &_nFee, int64_t _nTime, unsigned int _entryHeight, bool _spendsCoinbaseOrCoinstake, unsigned int nSigOps)
size_t DynamicMemoryUsage() const
CAmount nModFeesWithDescendants
... and size
uint64_t nCountWithAncestors
... and total fees (all including us)
unsigned int GetSigOpCountWithAncestors() const
CAmount GetModFeesWithAncestors() const
uint64_t GetSizeWithDescendants() const
uint64_t GetCountWithAncestors() const
CFeeRate feeRate
... and total memory usage
uint64_t nSizeWithAncestors
int64_t GetModifiedFee() const
const CAmount & GetFee() const
bool spendsCoinbaseOrCoinstake
Chain height when entering the mempool.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
bool TransactionWithinChainLimit(const uint256 &txid, size_t chainLimit) const
Returns false if the transaction is in the mempool and not within the chain limit specified.
bool ReadFeeEstimates(CAutoFile &filein)
const setEntries & GetMemPoolChildren(txiter entry) const
void ClearPrioritisation(const uint256 hash)
void removeWithAnchor(const uint256 &invalidRoot)
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors)
Update ancestors of hash to add/remove it as a descendant transaction.
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
unsigned int nTransactionsUpdated
Value n means that n times in 2^32 we check.
std::map< uint256, CTransactionRef > mapSaplingNullifiers
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
CTransactionRef get(const uint256 &hash) const
bool WriteFeeEstimates(CAutoFile &fileout) const
Write/Read estimates to disk.
std::map< CKeyID, uint256 > mapProTxPubKeyIDs
int Expire(int64_t time)
Expire all transaction (and their dependencies) in the mempool older than time.
void getTransactions(std::set< uint256 > &setTxid)
void AddTransactionsUpdated(unsigned int n)
CFeeRate estimateFee(int nBlocks) const
Estimate fee rate needed to get into the next nBlocks.
indirectmap< COutPoint, CTransactionRef > mapNextTx
void removeProTxReferences(const uint256 &proTxHash, MemPoolRemovalReason reason)
void setSanityCheck(double dFrequency=1.0)
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks=nullptr) const
Estimate fee rate needed to get into the next nBlocks If no answer can be given at nBlocks,...
double rollingMinimumFeeRate
void queryHashes(std::vector< uint256 > &vtxid)
std::vector< indexed_transaction_set::const_iterator > GetSortedDepthAndScore() const
void UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude)
UpdateForDescendants is used by UpdateTransactionsFromBlock to update the descendants for a single tr...
void removeUnchecked(txiter entry, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
Before calling removeUnchecked for a given transaction, UpdateForRemoveFromMempool must be called on ...
bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate=true)
size_t DynamicMemoryUsage() const
std::vector< TxMempoolInfo > infoAll() const
void SetIsLoaded(bool loaded)
Sets the current loaded state.
bool exists(const COutPoint &outpoint) const
int64_t lastRollingFeeUpdate
boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< mempoolentry_txid, SaltedIdHasher >, 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 > > > indexed_transaction_set
std::map< uint256, CAmount > mapDeltas
void trackPackageRemoved(const CFeeRate &rate)
minimum fee to get into the pool, decreases exponentially
void checkNullifiers() const
void addUncheckedSpecialTx(const CTransaction &tx)
Special txes.
void removeProTxPubKeyConflicts(const CTransaction &tx, const CKeyID &keyId)
CFeeRate minReasonableRelayFee
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
void removeProTxCollateralConflicts(const CTransaction &tx, const COutPoint &collateralOutpoint)
bool HasNoInputsOf(const CTransaction &tx) const
Check that none of this transactions inputs are in the mempool, and thus the tx is not dependent on o...
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants)
For each transaction being removed, update ancestors and any direct children.
void UpdateTransactionsFromBlock(const std::vector< uint256 > &hashesToUpdate)
When adding transactions from a disconnected block back to the mempool, new mempool entries may have ...
bool existsProviderTxConflict(const CTransaction &tx) const
bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb)
void UpdateChildrenForRemoval(txiter entry)
Sever link between specified transaction and direct children.
void removeProTxConflicts(const CTransaction &tx)
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
Try to calculate all in-mempool ancestors of entry.
bool exists(uint256 hash) const
static const int ROLLING_FEE_HALFLIFE
std::set< txiter, CompareIteratorByHash > setEntries
void removeConflicts(const CTransaction &tx)
void UpdateChild(txiter entry, txiter child, bool add)
uint64_t cachedInnerUsage
sum of all mempool tx' byte sizes
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
void removeUncheckedSpecialTx(const CTransaction &tx)
std::map< CService, uint256 > mapProTxAddresses
void check(const CCoinsViewCache *pcoins) const
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
std::multimap< uint256, uint256 > mapProTxRefs
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
CTxMemPool(const CFeeRate &_minReasonableRelayFee)
Create a new CTxMemPool.
const setEntries & GetMemPoolParents(txiter entry) const
uint64_t totalTxSize
Passed to constructor to avoid dependency on main.
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
Remove a set of transactions from the mempool.
indexed_transaction_set mapTx
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags)
TxMempoolInfo info(const uint256 &hash) const
uint64_t GetTotalTxSize()
unsigned long size() const
std::map< uint256, uint256 > mapProTxBlsPubKeyHashes
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
bool m_is_loaded GUARDED_BY(cs)
bool isSpent(const COutPoint &outpoint)
void UpdateParent(txiter entry, txiter parent, bool add)
void CalculateDescendants(txiter it, setEntries &setDescendants)
Populate setDescendants with all in-mempool descendants of hash.
void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors)
Set ancestor state for an entry.
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight)
Called when a block is connected.
std::map< COutPoint, uint256 > mapProTxCollaterals
bool blockSinceLastRollingFeeBump
void removeProTxSpentCollateralConflicts(const CTransaction &tx)
CBlockPolicyEstimator * minerPolicyEstimator
bool nullifierExists(const uint256 &nullifier) const
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
void ApplyDelta(const uint256 &hash, CAmount &nFeeDelta) const
unsigned int GetTransactionsUpdated() const
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Sort an entry by max(score/size of entry's tx, score/size with all descendants).
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
bool UseDescendantScore(const CTxMemPoolEntry &a) const
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Sort by score of entry ((fee+delta)/size) in descending order.
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
bool operator()(const txiter &a, const txiter &b) const
boost::multi_index_container< CTransactionRef, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::tag< txid_index >, mempoolentry_txid, SaltedIdHasher >, boost::multi_index::sequenced< boost::multi_index::tag< insertion_order > > > > indexed_disconnected_transactions
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
indexed_disconnected_transactions queuedTx
~DisconnectedBlockTransactions()
void removeForBlock(const std::vector< CTransactionRef > &vtx)
uint64_t cachedInnerUsage
size_t DynamicMemoryUsage() const
void addTransaction(const CTransactionRef &tx)
Information about a mempool transaction.
int64_t nFeeDelta
The fee delta.
int64_t nTime
Time the transaction entered the mempool.
CTransactionRef tx
The transaction itself.
CFeeRate feeRate
Feerate of the transaction.
result_type operator()(const CTxMemPoolEntry &entry) const
DisconnectedBlockTransactions During the reorg, it's desirable to re-add previously confirmed transac...
void operator()(CTxMemPoolEntry &e)
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int _modifySigOps)
void operator()(CTxMemPoolEntry &e)
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
update_fee_delta(int64_t _feeDelta)
void operator()(CTxMemPoolEntry &e)
std::shared_ptr< const CTransaction > CTransactionRef
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
@ SIZELIMIT
Expired from mempool.
@ BLOCK
Removed for reorganization.
@ EXPIRY
Manually removed or unknown reason.
@ REPLACED
Removed for conflict with in-block transaction.
@ CONFLICT
Removed for block.
@ REORG
Removed in size limiting.