23 int64_t _nTime,
double _entryPriority,
unsigned int _entryHeight,
25 bool _spendsCoinbase, int64_t _sigOpsCost,
LockPoints lp):
26 tx(_tx), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight),
27 inChainInputValue(_inChainInputValue),
28 spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
32 nUsageSize = RecursiveDynamicUsage(*
tx) + memusage::DynamicUsage(
tx);
88 while (!stageEntries.empty()) {
89 const txiter cit = *stageEntries.begin();
90 setAllDescendants.insert(cit);
91 stageEntries.erase(cit);
93 BOOST_FOREACH(
const txiter childEntry, setChildren) {
94 cacheMap::iterator cacheIt = cachedDescendants.find(childEntry);
95 if (cacheIt != cachedDescendants.end()) {
98 BOOST_FOREACH(
const txiter cacheEntry, cacheIt->second) {
99 setAllDescendants.insert(cacheEntry);
101 }
else if (!setAllDescendants.count(childEntry)) {
103 stageEntries.insert(childEntry);
109 int64_t modifySize = 0;
111 int64_t modifyCount = 0;
112 BOOST_FOREACH(
txiter cit, setAllDescendants) {
113 if (!setExclude.count(cit->GetTx().GetHash())) {
114 modifySize += cit->GetTxSize();
115 modifyFee += cit->GetModifiedFee();
117 cachedDescendants[updateIt].insert(cit);
136 cacheMap mapMemPoolDescendantsToUpdate;
140 std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
147 BOOST_REVERSE_FOREACH(
const uint256 &hash, vHashesToUpdate) {
152 if (it ==
mapTx.end()) {
158 for (; iter !=
mapNextTx.
end() && iter->first->hash == hash; ++iter) {
159 const uint256 &childHash = iter->second->GetHash();
161 assert(childIter !=
mapTx.end());
164 if (setChildren.insert(childIter).second && !setAlreadyIncluded.count(childHash)) {
180 if (fSearchForParents) {
184 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
186 if (piter !=
mapTx.end()) {
187 parentHashes.insert(piter);
188 if (parentHashes.size() + 1 > limitAncestorCount) {
189 errString =
strprintf(
"too many unconfirmed parents [limit: %u]", limitAncestorCount);
201 size_t totalSizeWithAncestors = entry.
GetTxSize();
203 while (!parentHashes.empty()) {
204 txiter stageit = *parentHashes.begin();
206 setAncestors.insert(stageit);
207 parentHashes.erase(stageit);
208 totalSizeWithAncestors += stageit->GetTxSize();
210 if (stageit->GetSizeWithDescendants() + entry.
GetTxSize() > limitDescendantSize) {
211 errString =
strprintf(
"exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
213 }
else if (stageit->GetCountWithDescendants() + 1 > limitDescendantCount) {
214 errString =
strprintf(
"too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
216 }
else if (totalSizeWithAncestors > limitAncestorSize) {
217 errString =
strprintf(
"exceeds ancestor size limit [limit: %u]", limitAncestorSize);
222 BOOST_FOREACH(
const txiter &phash, setMemPoolParents) {
224 if (setAncestors.count(phash) == 0) {
225 parentHashes.insert(phash);
227 if (parentHashes.size() + setAncestors.size() + 1 > limitAncestorCount) {
228 errString =
strprintf(
"too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
241 BOOST_FOREACH(
txiter piter, parentIters) {
244 const int64_t updateCount = (add ? 1 : -1);
245 const int64_t updateSize = updateCount * it->GetTxSize();
246 const CAmount updateFee = updateCount * it->GetModifiedFee();
247 BOOST_FOREACH(
txiter ancestorIt, setAncestors) {
254 int64_t updateCount = setAncestors.size();
255 int64_t updateSize = 0;
257 int64_t updateSigOpsCost = 0;
258 BOOST_FOREACH(
txiter ancestorIt, setAncestors) {
259 updateSize += ancestorIt->GetTxSize();
260 updateFee += ancestorIt->GetModifiedFee();
261 updateSigOpsCost += ancestorIt->GetSigOpCost();
269 BOOST_FOREACH(
txiter updateIt, setMemPoolChildren) {
278 const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
279 if (updateDescendants) {
286 BOOST_FOREACH(
txiter removeIt, entriesToRemove) {
289 setDescendants.erase(removeIt);
290 int64_t modifySize = -((int64_t)removeIt->GetTxSize());
291 CAmount modifyFee = -removeIt->GetModifiedFee();
292 int modifySigOps = -removeIt->GetSigOpCost();
293 BOOST_FOREACH(
txiter dit, setDescendants) {
298 BOOST_FOREACH(
txiter removeIt, entriesToRemove) {
327 BOOST_FOREACH(
txiter removeIt, entriesToRemove) {
353 nTransactionsUpdated(0)
377 while (it !=
mapNextTx.
end() && it->first->hash == hashTx) {
378 coins.
Spend(it->first->n);
402 indexed_transaction_set::iterator newit =
mapTx.insert(entry).first;
408 std::map<uint256, std::pair<double, CAmount> >::const_iterator pos =
mapDeltas.find(hash);
410 const std::pair<double, CAmount> &deltas = pos->second;
422 std::set<uint256> setParentTransactions;
423 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
425 setParentTransactions.insert(tx.
vin[i].prevout.hash);
435 BOOST_FOREACH (
const uint256 &phash, setParentTransactions) {
437 if (pit !=
mapTx.end()) {
449 newit->vTxHashesIdx =
vTxHashes.size() - 1;
457 const uint256 hash = it->GetTx().GetHash();
458 BOOST_FOREACH(
const CTxIn& txin, it->GetTx().vin)
463 vTxHashes[it->vTxHashesIdx].second->vTxHashesIdx = it->vTxHashesIdx;
488 if (setDescendants.count(entryit) == 0) {
489 stage.insert(entryit);
494 while (!stage.empty()) {
495 txiter it = *stage.begin();
496 setDescendants.insert(it);
500 BOOST_FOREACH(
const txiter &childiter, setChildren) {
501 if (!setDescendants.count(childiter)) {
502 stage.insert(childiter);
515 if (origit !=
mapTx.end()) {
516 txToRemove.insert(origit);
522 for (
unsigned int i = 0; i < origTx.
vout.size(); i++) {
527 assert(nextit !=
mapTx.end());
528 txToRemove.insert(nextit);
532 BOOST_FOREACH(
txiter it, txToRemove) {
545 for (indexed_transaction_set::const_iterator it =
mapTx.begin(); it !=
mapTx.end(); it++) {
552 txToRemove.insert(it);
553 }
else if (it->GetSpendsCoinbase()) {
554 BOOST_FOREACH(
const CTxIn& txin, tx.
vin) {
555 indexed_transaction_set::const_iterator it2 =
mapTx.find(txin.
prevout.
hash);
556 if (it2 !=
mapTx.end())
561 if (!coins || (coins->
IsCoinBase() && ((
signed long)nMemPoolHeight) - coins->
nHeight < nCoinbaseMaturity)) {
562 txToRemove.insert(it);
572 for (
txiter it : txToRemove) {
582 BOOST_FOREACH(
const CTxIn &txin, tx.
vin) {
586 if (txConflict != tx)
601 std::vector<const CTxMemPoolEntry*> entries;
602 for (
const auto& tx : vtx)
606 indexed_transaction_set::iterator i =
mapTx.find(hash);
607 if (i !=
mapTx.end())
608 entries.push_back(&*i);
612 for (
const auto& tx : vtx)
615 if (it !=
mapTx.end()) {
654 LogPrint(
"mempool",
"Checking mempool with %u transactions and %u inputs\n", (
unsigned int)
mapTx.size(), (
unsigned int)
mapNextTx.
size());
656 uint64_t checkTotal = 0;
657 uint64_t innerUsage = 0;
664 std::list<const CTxMemPoolEntry*> waitingOnDependants;
665 for (indexed_transaction_set::const_iterator it =
mapTx.begin(); it !=
mapTx.end(); it++) {
667 checkTotal += it->GetTxSize();
668 innerUsage += it->DynamicMemoryUsage();
670 txlinksMap::const_iterator linksiter =
mapLinks.find(it);
671 assert(linksiter !=
mapLinks.end());
672 const TxLinks &links = linksiter->second;
673 innerUsage += memusage::DynamicUsage(links.
parents) + memusage::DynamicUsage(links.
children);
674 bool fDependsWait =
false;
676 int64_t parentSizes = 0;
677 int64_t parentSigOpCost = 0;
678 BOOST_FOREACH(
const CTxIn &txin, tx.
vin) {
680 indexed_transaction_set::const_iterator it2 =
mapTx.find(txin.
prevout.
hash);
681 if (it2 !=
mapTx.end()) {
685 if (setParentCheck.insert(it2).second) {
686 parentSizes += it2->GetTxSize();
687 parentSigOpCost += it2->GetSigOpCost();
696 assert(it3->first == &txin.
prevout);
697 assert(it3->second == &tx);
703 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
706 uint64_t nCountCheck = setAncestors.size() + 1;
707 uint64_t nSizeCheck = it->GetTxSize();
708 CAmount nFeesCheck = it->GetModifiedFee();
709 int64_t nSigOpCheck = it->GetSigOpCost();
711 BOOST_FOREACH(
txiter ancestorIt, setAncestors) {
712 nSizeCheck += ancestorIt->GetTxSize();
713 nFeesCheck += ancestorIt->GetModifiedFee();
714 nSigOpCheck += ancestorIt->GetSigOpCost();
717 assert(it->GetCountWithAncestors() == nCountCheck);
718 assert(it->GetSizeWithAncestors() == nSizeCheck);
719 assert(it->GetSigOpCostWithAncestors() == nSigOpCheck);
720 assert(it->GetModFeesWithAncestors() == nFeesCheck);
725 int64_t childSizes = 0;
726 for (; iter !=
mapNextTx.
end() && iter->first->hash == it->GetTx().GetHash(); ++iter) {
727 txiter childit =
mapTx.find(iter->second->GetHash());
728 assert(childit !=
mapTx.end());
729 if (setChildrenCheck.insert(childit).second) {
730 childSizes += childit->GetTxSize();
736 assert(it->GetSizeWithDescendants() >= childSizes + it->GetTxSize());
739 waitingOnDependants.push_back(&(*it));
744 assert(fCheckResult);
748 unsigned int stepsSinceLastRemove = 0;
749 while (!waitingOnDependants.empty()) {
751 waitingOnDependants.pop_front();
754 waitingOnDependants.push_back(entry);
755 stepsSinceLastRemove++;
756 assert(stepsSinceLastRemove < waitingOnDependants.size());
760 assert(fCheckResult);
762 stepsSinceLastRemove = 0;
766 uint256 hash = it->second->GetHash();
767 indexed_transaction_set::const_iterator it2 =
mapTx.find(hash);
769 assert(it2 !=
mapTx.end());
770 assert(&tx == it->second);
780 indexed_transaction_set::const_iterator i =
mapTx.find(hasha);
781 if (i ==
mapTx.end())
return false;
782 indexed_transaction_set::const_iterator j =
mapTx.find(hashb);
783 if (j ==
mapTx.end())
return true;
784 uint64_t counta = i->GetCountWithAncestors();
785 uint64_t countb = j->GetCountWithAncestors();
786 if (counta == countb) {
789 return counta < countb;
793 class DepthAndScoreComparator
796 bool operator()(
const CTxMemPool::indexed_transaction_set::const_iterator& a,
const CTxMemPool::indexed_transaction_set::const_iterator& b)
798 uint64_t counta = a->GetCountWithAncestors();
799 uint64_t countb = b->GetCountWithAncestors();
800 if (counta == countb) {
803 return counta < countb;
810 std::vector<indexed_transaction_set::const_iterator> iters;
813 iters.reserve(
mapTx.size());
815 for (indexed_transaction_set::iterator mi =
mapTx.begin(); mi !=
mapTx.end(); ++mi) {
818 std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
828 vtxid.reserve(
mapTx.size());
830 for (
auto it : iters) {
831 vtxid.push_back(it->GetTx().GetHash());
835 static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
836 return TxMempoolInfo{it->GetSharedTx(), it->GetTime(),
CFeeRate(it->GetFee(), it->GetTxSize()), it->GetModifiedFee() - it->
GetFee()};
844 std::vector<TxMempoolInfo> ret;
845 ret.reserve(
mapTx.size());
846 for (
auto it : iters) {
847 ret.push_back(GetInfo(it));
856 indexed_transaction_set::const_iterator i =
mapTx.find(hash);
857 if (i ==
mapTx.end())
859 return i->GetSharedTx();
865 indexed_transaction_set::const_iterator i =
mapTx.find(hash);
866 if (i ==
mapTx.end())
898 fileout << CLIENT_VERSION;
901 catch (
const std::exception&) {
902 LogPrintf(
"CTxMemPool::WriteFeeEstimates(): unable to write policy estimator data (non-fatal)\n");
912 int nVersionRequired, nVersionThatWrote;
913 filein >> nVersionRequired >> nVersionThatWrote;
914 if (nVersionRequired > CLIENT_VERSION)
915 return error(
"CTxMemPool::ReadFeeEstimates(): up-version (%d) fee estimate file", nVersionRequired);
919 catch (
const std::exception&) {
920 LogPrintf(
"CTxMemPool::ReadFeeEstimates(): unable to read policy estimator data (non-fatal)\n");
930 std::pair<double, CAmount> &deltas =
mapDeltas[hash];
931 deltas.first += dPriorityDelta;
932 deltas.second += nFeeDelta;
934 if (it !=
mapTx.end()) {
938 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
941 BOOST_FOREACH(
txiter ancestorIt, setAncestors) {
947 setDescendants.erase(it);
948 BOOST_FOREACH(
txiter descendantIt, setDescendants) {
954 LogPrintf(
"PrioritiseTransaction: %s priority += %f, fee += %d\n", strHash, dPriorityDelta,
FormatMoney(nFeeDelta));
960 std::map<uint256, std::pair<double, CAmount> >::const_iterator pos =
mapDeltas.find(hash);
963 const std::pair<double, CAmount> &deltas = pos->second;
964 dPriorityDelta += deltas.first;
965 nFeeDelta += deltas.second;
976 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
990 coins =
CCoins(*ptx, MEMPOOL_HEIGHT);
1009 BOOST_FOREACH(
const txiter& it, stage) {
1016 indexed_transaction_set::index<entry_time>::type::iterator it =
mapTx.get<
entry_time>().begin();
1019 toremove.insert(
mapTx.project<0>(it));
1023 BOOST_FOREACH(
txiter removeit, toremove) {
1027 return stage.size();
1034 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
1037 return addUnchecked(hash, entry, setAncestors, validFeeEstimate);
1043 if (add &&
mapLinks[entry].children.insert(child).second) {
1045 }
else if (!add &&
mapLinks[entry].children.erase(child)) {
1053 if (add &&
mapLinks[entry].parents.insert(parent).second) {
1055 }
else if (!add &&
mapLinks[entry].parents.erase(parent)) {
1062 assert (entry !=
mapTx.end());
1063 txlinksMap::const_iterator it =
mapLinks.find(entry);
1065 return it->second.parents;
1070 assert (entry !=
mapTx.end());
1071 txlinksMap::const_iterator it =
mapLinks.find(entry);
1073 return it->second.children;
1111 unsigned nTxnRemoved = 0;
1114 indexed_transaction_set::index<descendant_score>::type::iterator it =
mapTx.get<
descendant_score>().begin();
1120 CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants());
1123 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1127 nTxnRemoved += stage.size();
1129 std::vector<CTransaction> txn;
1130 if (pvNoSpendsRemaining) {
1131 txn.reserve(stage.size());
1132 BOOST_FOREACH(
txiter iter, stage)
1133 txn.push_back(iter->GetTx());
1136 if (pvNoSpendsRemaining) {
1138 BOOST_FOREACH(
const CTxIn& txin, tx.
vin) {
1143 pvNoSpendsRemaining->push_back(txin.
prevout.
hash);
1149 if (maxFeeRateRemoved >
CFeeRate(0))
1150 LogPrint(
"mempool",
"Removed %u txn, rolling minimum fee bumped to %s\n", nTxnRemoved, maxFeeRateRemoved.
ToString());
1155 auto it =
mapTx.find(txid);
1156 return it ==
mapTx.end() || (it->GetCountWithAncestors() < chainLimit &&
1157 it->GetCountWithDescendants() < chainLimit);
int64_t CAmount
Amount in satoshis (Can be negative)
const CChainParams & Params()
Return the currently selected parameters.
Non-refcounted RAII wrapper for FILE*.
We want to be able to estimate feerates that are needed on tx's to be included in a certain number of...
void Write(CAutoFile &fileout)
Write estimation data to a file.
CFeeRate estimateFee(int confTarget)
Return a feerate estimate.
double estimateSmartPriority(int confTarget, int *answerFoundAtTarget, const CTxMemPool &pool)
Estimate priority needed to get be included in a block within confTarget blocks.
void Read(CAutoFile &filein, int nFileVersion)
Read estimation data from a file.
bool removeTx(uint256 hash)
Remove a transaction from the mempool tracking stats.
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool &pool)
Estimate feerate needed to get be included in a block within confTarget blocks.
double estimatePriority(int confTarget)
Return a priority estimate.
void processTransaction(const CTxMemPoolEntry &entry, bool validFeeEstimate)
Process a transaction accepted to the mempool.
void processBlock(unsigned int nBlockHeight, std::vector< const CTxMemPoolEntry * > &entries)
Process all the transactions that have been included in a block.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const Consensus::Params & GetConsensus(uint32_t nTargetHeight) const
Pruned version of CTransaction: only retains metadata and unspent transaction outputs.
bool Spend(uint32_t nPos)
mark a vout spent
bool IsPruned() const
check whether the entire CCoins is spent note that only !IsPruned() CCoins can be serialized
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
int nHeight
at which height this transaction was included in the active block chain
CCoinsView backed by another CCoinsView.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
const CCoins * AccessCoins(const uint256 &txid) const
Return a pointer to CCoins in the cache, or NULL if not found.
Abstract view on the open txout dataset.
virtual bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
virtual bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
bool HaveCoins(const uint256 &txid) const
Just check whether we have data for a given txid.
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
const CTxMemPool & mempool
Fee rate in satoshis per kilobyte: CAmount / kB.
CAmount GetFee(size_t nBytes) const
Return the fee in satoshis for the given size in bytes.
std::string ToString() const
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
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 std::vector< CTxOut > vout
const uint256 & GetHash() const
uint256 GetWitnessHash() const
const std::vector< CTxIn > vin
An input of a transaction.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
double GetPriority(unsigned int currentHeight) const
Fast calculation of lower bound of current priority as update from entry priority.
void UpdateFeeDelta(int64_t feeDelta)
int64_t nSigOpCostWithAncestors
unsigned int entryHeight
Chain height when entering the mempool.
const CTransaction & GetTx() const
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
size_t nUsageSize
... and total memory usage
void UpdateLockPoints(const LockPoints &lp)
int64_t sigOpCost
Total sigop cost.
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int modifySigOps)
CAmount nModFeesWithAncestors
uint64_t nCountWithDescendants
number of descendant transactions
double entryPriority
Priority when entering the mempool.
CTxMemPoolEntry(const CTransactionRef &_tx, const CAmount &_nFee, int64_t _nTime, double _entryPriority, unsigned int _entryHeight, CAmount _inChainInputValue, bool spendsCoinbase, int64_t nSigOpsCost, LockPoints lp)
CTransactionRef GetSharedTx() const
uint64_t nSizeWithDescendants
... and size
size_t DynamicMemoryUsage() const
CAmount nModFeesWithDescendants
... and total fees (all including us)
uint64_t nCountWithAncestors
LockPoints lockPoints
Track the height and time at which tx was final.
uint64_t nSizeWithAncestors
CAmount inChainInputValue
Sum of all txin values that are already in blockchain.
size_t nModSize
... and modified size for priority
CAmount nFee
Cached to avoid expensive parent-transaction lookups.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
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 PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
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.
double estimatePriority(int nBlocks) const
Estimate priority needed to get into the next nBlocks.
unsigned int nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
bool WriteFeeEstimates(CAutoFile &fileout) const
Write/Read estimates to disk.
int Expire(int64_t time)
Expire all transaction (and their dependencies) in the mempool older than time.
boost::signals2::signal< void(CTransactionRef)> NotifyEntryAdded
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks=NULL) const
Estimate fee rate needed to get into the next nBlocks If no answer can be given at nBlocks,...
uint32_t nCheckFrequency
Value n means that n times in 2^32 we check.
void AddTransactionsUpdated(unsigned int n)
CFeeRate estimateFee(int nBlocks) const
Estimate fee rate needed to get into the next nBlocks.
std::map< uint256, std::pair< double, CAmount > > mapDeltas
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
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 ...
CTransactionRef get(const uint256 &hash) const
bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate=true)
size_t DynamicMemoryUsage() const
std::vector< TxMempoolInfo > infoAll() const
std::vector< std::pair< uint256, txiter > > vTxHashes
All tx witness hashes/entries in mapTx, in random order.
indirectmap< COutPoint, const CTransaction * > mapNextTx
int64_t lastRollingFeeUpdate
void trackPackageRemoved(const CFeeRate &rate)
void TrimToSize(size_t sizelimit, std::vector< uint256 > *pvNoSpendsRemaining=NULL)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
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 CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb)
void UpdateChildrenForRemoval(txiter entry)
Sever link between specified transaction and direct children.
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
void ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta) const
std::set< txiter, CompareIteratorByHash > setEntries
void removeConflicts(const CTransaction &tx)
void UpdateChild(txiter entry, txiter child, bool add)
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
double estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks=NULL) const
Estimate priority needed to get into the next nBlocks If no answer can be given at nBlocks,...
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::map< txiter, setEntries, CompareIteratorByHash > cacheMap
CTxMemPool(const CFeeRate &_minReasonableRelayFee)
Create a new CTxMemPool.
const setEntries & GetMemPoolParents(txiter entry) const
uint64_t totalTxSize
sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discount...
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
boost::signals2::signal< void(CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved
void pruneSpent(const uint256 &hash, CCoins &coins)
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.
bool blockSinceLastRollingFeeBump
CBlockPolicyEstimator * minerPolicyEstimator
unsigned int GetTransactionsUpdated() const
Capture information about block/transaction validation.
Sort by score of entry ((fee+delta)/size) in descending order.
iterator lower_bound(const K &key)
const_iterator cbegin() const
std::pair< iterator, bool > insert(const value_type &value)
iterator find(const K &key)
const_iterator cend() const
size_type erase(const K &key)
bool CheckTxInputs(const CChainParams ¶ms, const CTransaction &tx, CValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight)
Check whether all inputs of this transaction are valid (no double spends and amounts) This does not m...
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
Compute the virtual transaction size (weight reinterpreted as bytes).
CFeeRate incrementalRelayFee
uint64_t GetRand(uint64_t nMax)
uint32_t nCoinbaseMaturity
Information about a mempool transaction.
#define AssertLockHeld(cs)
int64_t GetTransactionWeight(const CTransaction &tx)
Compute the weight of a transaction, as defined by BIP 141.
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.
@ CONFLICT
Removed for block.
@ REORG
Removed in size limiting.
#define LogPrint(category,...)
bool error(const char *fmt, const Args &... args)
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
int64_t GetTime()
GetTimeMicros() and GetTimeMillis() both return the system time, but in different units.
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain.
CTxMemPool mempool(::minRelayTxFee)
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight)
bool CheckFinalTx(const CTransaction &tx, int flags)
Check if transaction will be final in the next block to be created.
bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
Check if transaction will be BIP 68 final in the next block to be created.
int GetSpendHeight(const CCoinsViewCache &inputs)
Return the spend height, which is one more than the inputs.GetBestBlock().