7 #ifndef RAVEN_TXMEMPOOL_H 8 #define RAVEN_TXMEMPOOL_H 27 #include <boost/multi_index_container.hpp> 28 #include <boost/multi_index/hashed_index.hpp> 29 #include <boost/multi_index/ordered_index.hpp> 30 #include <boost/multi_index/sequenced_index.hpp> 31 #include <boost/signals2/signal.hpp> 37 static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
51 LockPoints() : height(0), time(0), maxInputBlock(nullptr) { }
97 int64_t _nTime,
unsigned int _entryHeight,
104 size_t GetTxSize()
const;
114 void UpdateDescendantState(int64_t modifySize,
CAmount modifyFee, int64_t modifyCount);
116 void UpdateAncestorState(int64_t modifySize,
CAmount modifyFee, int64_t modifyCount,
int modifySigOps);
119 void UpdateFeeDelta(int64_t feeDelta);
141 modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
156 modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
200 return tx->GetHash();
213 bool fUseADescendants = UseDescendantScore(a);
214 bool fUseBDescendants = UseDescendantScore(b);
223 double f1 = aModFee * bSize;
224 double f2 = aSize * bModFee;
280 double f1 = aFees * bSize;
281 double f2 = aSize * bFees;
334 const uint64_t k0,
k1;
430 void trackPackageRemoved(
const CFeeRate& rate);
434 static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12;
436 typedef boost::multi_index_container<
438 boost::multi_index::indexed_by<
440 boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
442 boost::multi_index::ordered_non_unique<
443 boost::multi_index::tag<descendant_score>,
444 boost::multi_index::identity<CTxMemPoolEntry>,
448 boost::multi_index::ordered_non_unique<
449 boost::multi_index::tag<entry_time>,
450 boost::multi_index::identity<CTxMemPoolEntry>,
454 boost::multi_index::ordered_unique<
455 boost::multi_index::tag<mining_score>,
456 boost::multi_index::identity<CTxMemPoolEntry>,
460 boost::multi_index::ordered_non_unique<
461 boost::multi_index::tag<ancestor_score>,
462 boost::multi_index::identity<CTxMemPoolEntry>,
491 typedef indexed_transaction_set::nth_index<0>::type::iterator
txiter;
496 return a->GetTx().GetHash() < b->GetTx().GetHash();
501 const setEntries & GetMemPoolParents(txiter entry)
const;
502 const setEntries & GetMemPoolChildren(txiter entry)
const;
504 typedef std::map<txiter, setEntries, CompareIteratorByHash>
cacheMap;
511 typedef std::map<txiter, TxLinks, CompareIteratorByHash>
txlinksMap;
514 typedef std::map<CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare>
addressDeltaMap;
520 typedef std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare>
mapSpentIndex;
526 void UpdateParent(txiter entry, txiter parent,
bool add);
527 void UpdateChild(txiter entry, txiter child,
bool add);
529 std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore()
const;
546 void setSanityCheck(
double dFrequency = 1.0) { nCheckFrequency =
static_cast<uint32_t
>(dFrequency * 4294967295.0); }
552 bool addUnchecked(
const uint256& hash,
const CTxMemPoolEntry &entry,
bool validFeeEstimate =
true);
553 bool addUnchecked(
const uint256& hash,
const CTxMemPoolEntry &entry, setEntries &setAncestors,
bool validFeeEstimate =
true);
555 void addAddressIndex(
const CTxMemPoolEntry &entry,
const CCoinsViewCache &view);
556 bool getAddressIndex(std::vector<std::pair<uint160, int> > &addresses, std::string assetName,
557 std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
558 bool getAddressIndex(std::vector<std::pair<uint160, int> > &addresses,
559 std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
560 bool removeAddressIndex(
const uint256 txhash);
562 void addSpentIndex(
const CTxMemPoolEntry &entry,
const CCoinsViewCache &view);
564 bool removeSpentIndex(
const uint256 txhash);
569 void removeForBlock(
const std::vector<CTransactionRef>& vtx,
unsigned int nBlockHeight,
ConnectedBlockAssetData& connectedBlockData );
570 void removeForBlock(
const std::vector<CTransactionRef>& vtx,
unsigned int nBlockHeight);
574 bool CompareDepthAndScore(
const uint256& hasha,
const uint256& hashb);
575 void queryHashes(std::vector<uint256>& vtxid);
577 unsigned int GetTransactionsUpdated()
const;
578 void AddTransactionsUpdated(
unsigned int n);
586 void PrioritiseTransaction(
const uint256& hash,
const CAmount& nFeeDelta);
588 void ClearPrioritisation(
const uint256 hash);
609 void UpdateTransactionsFromBlock(
const std::vector<uint256> &vHashesToUpdate);
621 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;
626 void CalculateDescendants(txiter it, setEntries &setDescendants);
634 CFeeRate GetMinFee(
size_t sizelimit)
const;
640 void TrimToSize(
size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining=
nullptr);
643 int Expire(int64_t
time);
646 bool TransactionWithinChainLimit(
const uint256& txid,
size_t chainLimit)
const;
663 return (mapTx.count(hash) != 0);
668 std::vector<TxMempoolInfo> infoAll()
const;
670 size_t DynamicMemoryUsage()
const;
689 void UpdateForDescendants(txiter updateIt,
690 cacheMap &cachedDescendants,
691 const std::set<uint256> &setExclude);
693 void UpdateAncestorsOf(
bool add, txiter hash, setEntries &setAncestors);
695 void UpdateEntryForAncestors(txiter it,
const setEntries &setAncestors);
699 void UpdateForRemoveFromMempool(
const setEntries &entriesToRemove,
bool updateDescendants);
701 void UpdateChildrenForRemoval(txiter entry);
732 bool GetCoin(
const COutPoint &outpoint,
Coin &coin)
const override;
755 typedef boost::multi_index_container<
757 boost::multi_index::indexed_by<
759 boost::multi_index::hashed_unique<
760 boost::multi_index::tag<txid_index>,
765 boost::multi_index::sequenced<
766 boost::multi_index::tag<insertion_order>
782 uint64_t cachedInnerUsage = 0;
787 return memusage::MallocUsage(
sizeof(CTransactionRef) + 6 *
sizeof(
void*)) * queuedTx.size() + cachedInnerUsage;
793 cachedInnerUsage += RecursiveDynamicUsage(tx);
800 if (queuedTx.empty()) {
803 for (
auto const &tx : vtx) {
804 auto it = queuedTx.find(tx->GetHash());
805 if (it != queuedTx.end()) {
806 cachedInnerUsage -= RecursiveDynamicUsage(*it);
813 void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
815 cachedInnerUsage -= RecursiveDynamicUsage(*entry);
821 cachedInnerUsage = 0;
835 #endif // RAVEN_TXMEMPOOL_H addressDeltaMapInserted mapAddressInserted
CAmount GetModFeesWithAncestors() const
size_t vTxHashesIdx
Index in mempool's vTxHashes.
Information about a mempool transaction.
update_fee_delta(int64_t _feeDelta)
uint64_t GetSizeWithAncestors() const
CAmount nModFeesWithDescendants
... and total fees (all including us)
void UpdateLockPoints(const LockPoints &lp)
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
std::set< CAssetCacheNewAsset > newAssetsToAdd
size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
std::map< uint256, std::set< std::string > > mapHashQualifiersChanged
addressDeltaMap mapAddress
~DisconnectedBlockTransactions()
size_t GetTxWeight() const
boost::signals2::signal< void(CTransactionRef)> NotifyEntryAdded
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
std::map< uint256, std::set< std::string > > mapHashVerifierChanged
std::map< uint256, std::set< std::string > > mapHashMarkedGlobalFrozen
std::set< CAssetCacheRestrictedGlobal > newGlobalRestrictionsToAdd
CAmount GetModFeesWithDescendants() const
uint64_t GetTotalTxSize() const
bool operator()(const txiter &a, const txiter &b) const
uint64_t GetSizeWithDescendants() const
std::set< CAssetCacheRestrictedAddress > newAddressRestrictionsToAdd
std::set< txiter, CompareIteratorByHash > setEntries
void addTransaction(const CTransactionRef &tx)
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
bool GetSpendsCoinbase() const
int64_t sigOpCost
Total sigop cost.
std::shared_ptr< const CTransaction > CTransactionRef
uint64_t nCountWithDescendants
number of descendant transactions
int64_t lastRollingFeeUpdate
CAmount nFee
Cached to avoid expensive parent-transaction lookups.
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 corbies (Can be negative)
std::map< CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare > mapSpentIndex
bool blockSinceLastRollingFeeBump
std::map< uint256, std::vector< CSpentIndexKey > > mapSpentIndexInserted
Removed in size limiting.
indexed_disconnected_transactions queuedTx
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)
std::map< uint256, std::string > mapHashToAsset
size_t nUsageSize
... and total memory usage
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.
size_t DynamicMemoryUsage() const
unsigned int GetHeight() const
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...
const uint256 & GetHash() const
const CAmount & GetFee() const
DisconnectedBlockTransactions.
CTransactionRef GetSharedTx() const
Removed for reorganization.
std::map< uint256, CAmount > mapDeltas
std::map< std::string, std::set< uint256 > > mapAssetVerifierChanged
std::map< std::string, std::set< uint256 > > mapAddressesQualifiersChanged
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).
bool exists(uint256 hash) const
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
uint64_t GetCountWithDescendants() 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
std::map< std::pair< std::string, std::string >, std::set< uint256 > > mapAddressesMarkedFrozen
Restricted assets maps.
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
int64_t GetSigOpCostWithAncestors() const
uint64_t GetCountWithAncestors() const
int64_t nTime
Time the transaction entered the mempool.
bool spendsCoinbase
keep track of transactions that spend a coinbase
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
std::map< uint256, std::set< std::pair< std::string, std::string > > > mapHashToAddressMarkedFrozen
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
std::map< std::string, uint256 > mapAssetToHash
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.
std::set< CAssetCacheQualifierAddress > newQualifiersToAdd
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
const CTransaction & GetTx() const
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 > > > indexed_transaction_set
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost)
int64_t GetModifiedFee() const
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
uint64_t nCountWithAncestors
std::map< uint256, std::vector< CMempoolAddressDeltaKey > > addressDeltaMapInserted
Fee rate in satoshis per kilobyte: CAmount / kB.
int64_t GetSigOpCost() const
size_t operator()(const uint256 &txid) const
std::set< CAssetCacheRestrictedVerifiers > newVerifiersToAdd
update_lock_points(const LockPoints &_lp)
boost::signals2::signal< void(CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved
mapSpentIndexInserted mapSpentInserted
std::map< std::string, std::set< uint256 > > mapAssetMarkedGlobalFrozen
size_t DynamicMemoryUsage() const
CFeeRate feeRate
Feerate of the transaction.
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
const LockPoints & GetLockPoints() const
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Sort by score of entry ((fee+delta)/size) in descending order.
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.
bool UseDescendantScore(const CTxMemPoolEntry &a) const
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
std::map< CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare > addressDeltaMap
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
unsigned int entryHeight
Chain height when entering the mempool.