23 int64_t _nTime,
unsigned int _entryHeight,
24 bool _spendsCoinbase, int64_t _sigOpsCost,
LockPoints lp)
44 feeDelta = newFeeDelta;
63 stageEntries = updateIt->GetMemPoolChildrenConst();
65 while (!stageEntries.empty()) {
67 descendants.insert(descendant);
68 stageEntries.erase(descendant);
71 cacheMap::iterator cacheIt = cachedDescendants.find(mapTx.iterator_to(childEntry));
72 if (cacheIt != cachedDescendants.end()) {
75 for (
txiter cacheEntry : cacheIt->second) {
76 descendants.insert(*cacheEntry);
78 }
else if (!descendants.count(childEntry)) {
80 stageEntries.insert(childEntry);
86 int64_t modifySize = 0;
88 int64_t modifyCount = 0;
90 if (!setExclude.count(descendant.GetTx().GetHash())) {
91 modifySize += descendant.GetTxSize();
92 modifyFee += descendant.GetModifiedFee();
94 cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
96 mapTx.modify(mapTx.iterator_to(descendant),
update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()));
113 cacheMap mapMemPoolDescendantsToUpdate;
117 std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
127 if (it == mapTx.end()) {
130 auto iter = mapNextTx.lower_bound(
COutPoint(hash, 0));
135 const auto epoch = GetFreshEpoch();
136 for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
137 const uint256 &childHash = iter->second->GetHash();
138 txiter childIter = mapTx.find(childHash);
139 assert(childIter != mapTx.end());
142 if (!visited(childIter) && !setAlreadyIncluded.count(childHash)) {
143 UpdateChild(it, childIter,
true);
144 UpdateParent(childIter, it,
true);
148 UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
157 if (fSearchForParents) {
161 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
164 staged_ancestors.insert(**piter);
165 if (staged_ancestors.size() + 1 > limitAncestorCount) {
166 errString =
strprintf(
"too many unconfirmed parents [limit: %u]", limitAncestorCount);
174 txiter it = mapTx.iterator_to(entry);
175 staged_ancestors = it->GetMemPoolParentsConst();
178 size_t totalSizeWithAncestors = entry.
GetTxSize();
180 while (!staged_ancestors.empty()) {
182 txiter stageit = mapTx.iterator_to(stage);
184 setAncestors.insert(stageit);
185 staged_ancestors.erase(stage);
186 totalSizeWithAncestors += stageit->
GetTxSize();
188 if (stageit->GetSizeWithDescendants() + entry.
GetTxSize() > limitDescendantSize) {
189 errString =
strprintf(
"exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
191 }
else if (stageit->GetCountWithDescendants() + 1 > limitDescendantCount) {
192 errString =
strprintf(
"too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
194 }
else if (totalSizeWithAncestors > limitAncestorSize) {
195 errString =
strprintf(
"exceeds ancestor size limit [limit: %u]", limitAncestorSize);
201 txiter parent_it = mapTx.iterator_to(parent);
204 if (setAncestors.count(parent_it) == 0) {
205 staged_ancestors.insert(parent);
207 if (staged_ancestors.size() + setAncestors.size() + 1 > limitAncestorCount) {
208 errString =
strprintf(
"too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
222 UpdateChild(mapTx.iterator_to(parent),
it, add);
224 const int64_t updateCount = (add ? 1 : -1);
225 const int64_t updateSize = updateCount * it->GetTxSize();
226 const CAmount updateFee = updateCount * it->GetModifiedFee();
227 for (
txiter ancestorIt : setAncestors) {
234 int64_t updateCount = setAncestors.size();
235 int64_t updateSize = 0;
237 int64_t updateSigOpsCost = 0;
238 for (
txiter ancestorIt : setAncestors) {
239 updateSize += ancestorIt->GetTxSize();
240 updateFee += ancestorIt->GetModifiedFee();
241 updateSigOpsCost += ancestorIt->GetSigOpCost();
250 UpdateParent(mapTx.iterator_to(updateIt),
it,
false);
258 const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
259 if (updateDescendants) {
266 for (
txiter removeIt : entriesToRemove) {
268 CalculateDescendants(removeIt, setDescendants);
269 setDescendants.erase(removeIt);
270 int64_t modifySize = -((int64_t)removeIt->GetTxSize());
271 CAmount modifyFee = -removeIt->GetModifiedFee();
272 int modifySigOps = -removeIt->GetSigOpCost();
273 for (
txiter dit : setDescendants) {
278 for (
txiter removeIt : entriesToRemove) {
301 CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy,
false);
304 UpdateAncestorsOf(
false, removeIt, setAncestors);
309 for (
txiter removeIt : entriesToRemove) {
310 UpdateChildrenForRemoval(removeIt);
335 : m_check_ratio(check_ratio), minerPolicyEstimator(estimator)
343 return mapNextTx.count(outpoint);
361 indexed_transaction_set::iterator newit = mapTx.insert(entry).first;
378 std::set<uint256> setParentTransactions;
379 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
380 mapNextTx.insert(std::make_pair(&tx.
vin[i].prevout, &tx));
381 setParentTransactions.insert(tx.
vin[i].prevout.hash);
391 for (
const auto& pit :
GetIterSet(setParentTransactions)) {
402 newit->vTxHashesIdx = vTxHashes.size() - 1;
419 const uint256 hash = it->GetTx().GetHash();
420 for (
const CTxIn& txin : it->GetTx().vin)
421 mapNextTx.erase(txin.prevout);
425 if (vTxHashes.size() > 1) {
426 vTxHashes[it->vTxHashesIdx] = std::move(vTxHashes.back());
427 vTxHashes[it->vTxHashesIdx].second->vTxHashesIdx = it->vTxHashesIdx;
428 vTxHashes.pop_back();
429 if (vTxHashes.size() * 2 < vTxHashes.capacity())
430 vTxHashes.shrink_to_fit();
451 if (setDescendants.count(entryit) == 0) {
452 stage.insert(entryit);
457 while (!stage.empty()) {
459 setDescendants.insert(it);
464 txiter childiter = mapTx.iterator_to(child);
465 if (!setDescendants.count(childiter)) {
466 stage.insert(childiter);
478 if (origit != mapTx.end()) {
479 txToRemove.insert(origit);
485 for (
unsigned int i = 0; i < origTx.
vout.size(); i++) {
487 if (
it == mapNextTx.end())
489 txiter nextit = mapTx.find(
it->second->GetHash());
490 assert(nextit != mapTx.end());
491 txToRemove.insert(nextit);
507 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
514 txToRemove.insert(
it);
515 }
else if (
it->GetSpendsCoinbase()) {
517 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
518 if (it2 != mapTx.end())
523 txToRemove.insert(
it);
545 if (
it != mapNextTx.end()) {
547 if (txConflict != tx)
562 std::vector<const CTxMemPoolEntry*> entries;
563 for (
const auto& tx : vtx)
567 indexed_transaction_set::iterator i = mapTx.find(hash);
568 if (i != mapTx.end())
569 entries.push_back(&*i);
573 for (
const auto& tx : vtx)
575 txiter it = mapTx.find(tx->GetHash());
576 if (it != mapTx.end()) {
612 UpdateCoins(tx, mempoolDuplicate, std::numeric_limits<int>::max());
622 LogPrint(
BCLog::MEMPOOL,
"Checking mempool with %u transactions and %u inputs\n", (
unsigned int)mapTx.size(), (
unsigned int)mapNextTx.size());
624 uint64_t checkTotal = 0;
625 uint64_t innerUsage = 0;
627 CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins));
630 std::list<const CTxMemPoolEntry*> waitingOnDependants;
631 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
633 checkTotal +=
it->GetTxSize();
634 innerUsage +=
it->DynamicMemoryUsage();
637 bool fDependsWait =
false;
641 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
642 if (it2 != mapTx.end()) {
646 setParentCheck.insert(*it2);
651 auto it3 = mapNextTx.find(txin.
prevout);
652 assert(it3 != mapNextTx.end());
654 assert(it3->second == &tx);
660 assert(setParentCheck.size() ==
it->GetMemPoolParentsConst().size());
661 assert(std::equal(setParentCheck.begin(), setParentCheck.end(),
it->GetMemPoolParentsConst().begin(), comp));
664 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
667 uint64_t nCountCheck = setAncestors.size() + 1;
668 uint64_t nSizeCheck =
it->GetTxSize();
669 CAmount nFeesCheck =
it->GetModifiedFee();
670 int64_t nSigOpCheck =
it->GetSigOpCost();
672 for (
txiter ancestorIt : setAncestors) {
673 nSizeCheck += ancestorIt->GetTxSize();
674 nFeesCheck += ancestorIt->GetModifiedFee();
675 nSigOpCheck += ancestorIt->GetSigOpCost();
678 assert(
it->GetCountWithAncestors() == nCountCheck);
679 assert(
it->GetSizeWithAncestors() == nSizeCheck);
680 assert(
it->GetSigOpCostWithAncestors() == nSigOpCheck);
681 assert(
it->GetModFeesWithAncestors() == nFeesCheck);
685 auto iter = mapNextTx.lower_bound(
COutPoint(
it->GetTx().GetHash(), 0));
686 uint64_t child_sizes = 0;
687 for (; iter != mapNextTx.end() && iter->first->hash ==
it->GetTx().GetHash(); ++iter) {
688 txiter childit = mapTx.find(iter->second->GetHash());
689 assert(childit != mapTx.end());
690 if (setChildrenCheck.insert(*childit).second) {
691 child_sizes += childit->GetTxSize();
694 assert(setChildrenCheck.size() ==
it->GetMemPoolChildrenConst().size());
695 assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(),
it->GetMemPoolChildrenConst().begin(), comp));
698 assert(
it->GetSizeWithDescendants() >= child_sizes +
it->GetTxSize());
701 waitingOnDependants.push_back(&(*
it));
706 unsigned int stepsSinceLastRemove = 0;
707 while (!waitingOnDependants.empty()) {
709 waitingOnDependants.pop_front();
711 waitingOnDependants.push_back(entry);
712 stepsSinceLastRemove++;
713 assert(stepsSinceLastRemove < waitingOnDependants.size());
716 stepsSinceLastRemove = 0;
719 for (
auto it = mapNextTx.cbegin();
it != mapNextTx.cend();
it++) {
721 indexed_transaction_set::const_iterator it2 = mapTx.find(hash);
723 assert(it2 != mapTx.end());
734 indexed_transaction_set::const_iterator i = wtxid ?
get_iter_from_wtxid(hasha) : mapTx.find(hasha);
735 if (i == mapTx.end())
return false;
736 indexed_transaction_set::const_iterator j = wtxid ?
get_iter_from_wtxid(hashb) : mapTx.find(hashb);
737 if (j == mapTx.end())
return true;
738 uint64_t counta = i->GetCountWithAncestors();
739 uint64_t countb = j->GetCountWithAncestors();
740 if (counta == countb) {
743 return counta < countb;
747 class DepthAndScoreComparator
750 bool operator()(
const CTxMemPool::indexed_transaction_set::const_iterator& a,
const CTxMemPool::indexed_transaction_set::const_iterator& b)
752 uint64_t counta = a->GetCountWithAncestors();
753 uint64_t countb = b->GetCountWithAncestors();
754 if (counta == countb) {
757 return counta < countb;
764 std::vector<indexed_transaction_set::const_iterator> iters;
767 iters.reserve(mapTx.size());
769 for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
772 std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
782 vtxid.reserve(mapTx.size());
784 for (
auto it : iters) {
785 vtxid.push_back(
it->GetTx().GetHash());
790 return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
798 std::vector<TxMempoolInfo> ret;
799 ret.reserve(mapTx.size());
800 for (
auto it : iters) {
810 indexed_transaction_set::const_iterator i = mapTx.find(hash);
811 if (i == mapTx.end())
813 return i->GetSharedTx();
820 if (i == mapTx.end())
834 if (it != mapTx.end()) {
838 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
841 for (
txiter ancestorIt : setAncestors) {
847 setDescendants.erase(it);
848 for (
txiter descendantIt : setDescendants) {
860 std::map<uint256, CAmount>::const_iterator pos =
mapDeltas.find(hash);
863 const CAmount &delta = pos->second;
875 const auto it = mapNextTx.find(prevout);
876 return it == mapNextTx.end() ? nullptr :
it->second;
881 auto it = mapTx.find(txid);
882 if (
it != mapTx.end())
return it;
889 for (
const auto& h : hashes) {
891 if (mi) ret.insert(*mi);
898 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
912 if (outpoint.
n < ptx->vout.size()) {
931 if (m_unbroadcast_txids.erase(txid))
933 LogPrint(
BCLog::MEMPOOL,
"Removed %i from set of unbroadcast txns%s\n", txid.
GetHex(), (unchecked ?
" before confirmation that txn was sent out" :
""));
939 UpdateForRemoveFromMempool(stage, updateDescendants);
941 removeUnchecked(
it, reason);
948 indexed_transaction_set::index<entry_time>::type::iterator
it = mapTx.get<
entry_time>().begin();
950 while (it != mapTx.get<
entry_time>().end() && it->GetTime() < time) {
951 toremove.insert(mapTx.project<0>(it));
955 for (
txiter removeit : toremove) {
956 CalculateDescendants(removeit, stage);
965 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
967 CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
968 return addUnchecked(entry, setAncestors, validFeeEstimate);
975 if (add && entry->GetMemPoolChildren().insert(*child).second) {
977 }
else if (!add && entry->GetMemPoolChildren().erase(*child)) {
986 if (add && entry->GetMemPoolParents().insert(*parent).second) {
988 }
else if (!add && entry->GetMemPoolParents().erase(*parent)) {
995 if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
996 return CFeeRate(llround(rollingMinimumFeeRate));
999 if (time > lastRollingFeeUpdate + 10) {
1000 double halflife = ROLLING_FEE_HALFLIFE;
1001 if (DynamicMemoryUsage() < sizelimit / 4)
1003 else if (DynamicMemoryUsage() < sizelimit / 2)
1006 rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
1007 lastRollingFeeUpdate = time;
1010 rollingMinimumFeeRate = 0;
1019 if (rate.
GetFeePerK() > rollingMinimumFeeRate) {
1021 blockSinceLastRollingFeeBump =
false;
1028 unsigned nTxnRemoved = 0;
1030 while (!mapTx.empty() && DynamicMemoryUsage() > sizelimit) {
1031 indexed_transaction_set::index<descendant_score>::type::iterator
it = mapTx.get<
descendant_score>().begin();
1037 CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants());
1039 trackPackageRemoved(removed);
1040 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1043 CalculateDescendants(mapTx.project<0>(it), stage);
1044 nTxnRemoved += stage.size();
1046 std::vector<CTransaction> txn;
1047 if (pvNoSpendsRemaining) {
1048 txn.reserve(stage.size());
1049 for (
txiter iter : stage)
1050 txn.push_back(iter->GetTx());
1053 if (pvNoSpendsRemaining) {
1055 for (
const CTxIn& txin : tx.vin) {
1057 pvNoSpendsRemaining->push_back(txin.
prevout);
1063 if (maxFeeRateRemoved >
CFeeRate(0)) {
1070 std::vector<txiter> candidates;
1072 candidates.push_back(entry);
1073 uint64_t maximum = 0;
1074 while (candidates.size()) {
1075 txiter candidate = candidates.back();
1076 candidates.pop_back();
1077 if (!counted.insert(candidate).second)
continue;
1079 if (parents.size() == 0) {
1080 maximum = std::max(maximum, candidate->GetCountWithDescendants());
1083 candidates.push_back(mapTx.iterator_to(i));
1092 auto it = mapTx.find(txid);
1093 ancestors = descendants = 0;
1094 if (
it != mapTx.end()) {
1095 ancestors =
it->GetCountWithAncestors();
1096 descendants = CalculateDescendantMaximum(
it);
1109 m_is_loaded = loaded;
std::shared_ptr< const CTransaction > CTransactionRef
static int64_t GetTransactionWeight(const CTransaction &tx)
void queryHashes(std::vector< uint256 > &vtxid) const
Information about a mempool transaction.
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight, CAmount &txfee)
Check whether all inputs of this transaction are valid (no double spends and amounts) This does not m...
CAmount nModFeesWithDescendants
... and total fees (all including us)
void UpdateLockPoints(const LockPoints &lp)
Optional< txiter > GetIter(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
std::deque< CInv >::iterator it
#define LogPrint(category,...)
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
std::vector< TxMempoolInfo > infoAll() const
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
bool exists(const GenTxid >xid) const
void UpdateTransactionsFromBlock(const std::vector< uint256 > &vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs
When adding transactions from a disconnected block back to the mempool, new mempool entries may have ...
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
size_t DynamicMemoryUsage() const
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool removeTx(uint256 hash, bool inBlock)
Remove a transaction from the mempool tracking stats.
reverse_range< T > reverse_iterate(T &x)
TxMempoolInfo info(const uint256 &hash) const
Removed in size limiting.
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
const uint256 & GetHash() const
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule) ...
static void LogPrintf(const char *fmt, const Args &... args)
bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb, bool wtxid=false)
std::set< txiter, CompareIteratorByHash > setEntries
const Children & GetMemPoolChildrenConst() const
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
std::atomic< unsigned int > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
uint64_t nCountWithDescendants
number of descendant transactions
int64_t lastRollingFeeUpdate
bool isSpent(const COutPoint &outpoint) const
const std::vector< CTxIn > vin
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
void addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs
const int m_check_ratio
Value n means that 1 times in n we check.
void check(const CCoinsViewCache *pcoins) const
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Update ancestors of hash to add/remove it as a descendant transaction.
int64_t CAmount
Amount in satoshis (Can be negative)
bool blockSinceLastRollingFeeBump
#define AssertLockHeld(cs)
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
Removed for reorganization.
static const uint32_t MEMPOOL_HEIGHT
Fake height value used in Coin to signify they are only in the memory pool (since 0...
int64_t nSigOpCostWithAncestors
const size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Parents
void UpdateFeeDelta(int64_t feeDelta)
bool CheckFinalTx(const CTransaction &tx, int flags)
Transaction validation functions.
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
int GetSpendHeight(const CCoinsViewCache &inputs)
Return the spend height, which is one more than the inputs.GetBestBlock().
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
int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
Expire all transaction (and their dependencies) in the mempool older than time.
An input of a transaction.
const uint256 & GetWitnessHash() const
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
const uint256 & GetHash() const
Removed for conflict with in-block transaction.
void removeUnchecked(txiter entry, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Before calling removeUnchecked for a given transaction, UpdateForRemoveFromMempool must be called on ...
std::map< uint256, CAmount > mapDeltas
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
const std::vector< CTxOut > vout
CMainSignals & GetMainSignals()
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain. ...
CAmount nModFeesWithAncestors
std::string ToString() const
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
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 EXCLUSIVE_LOCKS_REQUIRED(cs)
Try to calculate all in-mempool ancestors of entry.
An outpoint - a combination of a transaction hash and an index n into its vout.
uint64_t nSizeWithDescendants
... and size
void AddTransactionsUpdated(unsigned int n)
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
void ApplyDelta(const uint256 &hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
uint64_t totalTxSize
sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discount...
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
CFeeRate incrementalRelayFee
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
CTxMemPool(CBlockPolicyEstimator *estimator=nullptr, int check_ratio=0)
Create a new CTxMemPool.
const int64_t sigOpCost
Total sigop cost.
EpochGuard(const CTxMemPool &in)
static void CheckInputsAndUpdateCoins(const CTransaction &tx, CCoinsViewCache &mempoolDuplicate, const int64_t spendheight)
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
std::vector< indexed_transaction_set::const_iterator > GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
bool HasNoInputsOf(const CTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Check that none of this transactions inputs are in the mempool, and thus the tx is not dependent on o...
void processBlock(unsigned int nBlockHeight, std::vector< const CTxMemPoolEntry *> &entries)
Process all the transactions that have been included in a block.
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
EpochGuard GetFreshEpoch() const EXCLUSIVE_LOCKS_REQUIRED(cs)
LockPoints lockPoints
Track the height and time at which tx was final.
pool addUnchecked(CTxMemPoolEntry(tx, nFee, nTime, nHeight, spendsCoinbase, sigOpCost, lp))
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
const CTransaction & GetTx() const
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Set ancestor state for an entry.
txiter get_iter_from_wtxid(const uint256 &wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
void ClearPrioritisation(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs)
setEntries GetIterSet(const std::set< uint256 > &hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Translate a set of hashes into a set of pool iterators to avoid repeated lookups. ...
std::string GetHex() const
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Children
uint64_t nCountWithAncestors
Fee rate in satoshis per kilobyte: CAmount / kB.
unsigned int GetTransactionsUpdated() const
const CAmount nFee
Cached to avoid expensive parent-transaction lookups.
static size_t IncrementalDynamicUsage(const std::set< X, Y > &s)
static size_t RecursiveDynamicUsage(const CScript &script)
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
CTransactionRef get(const uint256 &hash) const
void RemoveUnbroadcastTx(const uint256 &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
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 feerate of entry (fee/size) in descending order This is only used for transaction relay...
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
const CTxMemPool & mempool
int64_t GetTime()
Return system time (or mocked time, if set)
void SetIsLoaded(bool loaded)
Sets the current loaded state.
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
void UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude) EXCLUSIVE_LOCKS_REQUIRED(cs)
UpdateForDescendants is used by UpdateTransactionsFromBlock to update the descendants for a single tr...
CBlockPolicyEstimator * minerPolicyEstimator
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
CTxMemPoolEntry(const CTransactionRef &_tx, const CAmount &_nFee, int64_t _nTime, unsigned int _entryHeight, bool spendsCoinbase, int64_t nSigOpsCost, LockPoints lp)
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
A generic txid reference (txid or wtxid).
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
EpochGuard: RAII-style guard for using epoch-based graph traversal algorithms.
std::optional< T > Optional
Substitute for C++17 std::optional DEPRECATED use std::optional in new code.
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants) EXCLUSIVE_LOCKS_REQUIRED(cs)
For each transaction being removed, update ancestors and any direct children.
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight)
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason, uint64_t mempool_sequence)
void GetTransactionAncestry(const uint256 &txid, size_t &ancestors, size_t &descendants) const
Calculate the ancestor and descendant count for the given transaction.
void processTransaction(const CTxMemPoolEntry &entry, bool validFeeEstimate)
Process a transaction accepted to the mempool.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.