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));
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)) {
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);
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();
258 const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
259 if (updateDescendants) {
266 for (
txiter removeIt : entriesToRemove) {
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) {
309 for (
txiter removeIt : entriesToRemove) {
335 : nTransactionsUpdated(0), minerPolicyEstimator(estimator), m_epoch(0), m_has_epoch_guard(false)
348 return mapNextTx.count(outpoint);
366 indexed_transaction_set::iterator newit = mapTx.insert(entry).first;
383 std::set<uint256> setParentTransactions;
384 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
385 mapNextTx.insert(std::make_pair(&tx.
vin[i].prevout, &tx));
386 setParentTransactions.insert(tx.
vin[i].prevout.hash);
396 for (
const auto& pit :
GetIterSet(setParentTransactions)) {
407 newit->vTxHashesIdx = vTxHashes.size() - 1;
424 const uint256 hash = it->GetTx().GetHash();
425 for (
const CTxIn& txin : it->GetTx().vin)
426 mapNextTx.erase(txin.prevout);
430 if (vTxHashes.size() > 1) {
431 vTxHashes[it->vTxHashesIdx] = std::move(vTxHashes.back());
432 vTxHashes[it->vTxHashesIdx].second->vTxHashesIdx = it->vTxHashesIdx;
433 vTxHashes.pop_back();
434 if (vTxHashes.size() * 2 < vTxHashes.capacity())
435 vTxHashes.shrink_to_fit();
456 if (setDescendants.count(entryit) == 0) {
457 stage.insert(entryit);
462 while (!stage.empty()) {
464 setDescendants.insert(it);
469 txiter childiter = mapTx.iterator_to(child);
470 if (!setDescendants.count(childiter)) {
471 stage.insert(childiter);
483 if (origit != mapTx.end()) {
484 txToRemove.insert(origit);
490 for (
unsigned int i = 0; i < origTx.
vout.size(); i++) {
492 if (
it == mapNextTx.end())
494 txiter nextit = mapTx.find(
it->second->GetHash());
495 assert(nextit != mapTx.end());
496 txToRemove.insert(nextit);
512 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
519 txToRemove.insert(
it);
520 }
else if (
it->GetSpendsCoinbase()) {
522 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
523 if (it2 != mapTx.end())
526 if (nCheckFrequency != 0) assert(!coin.
IsSpent());
528 txToRemove.insert(
it);
550 if (
it != mapNextTx.end()) {
552 if (txConflict != tx)
567 std::vector<const CTxMemPoolEntry*> entries;
568 for (
const auto& tx : vtx)
572 indexed_transaction_set::iterator i = mapTx.find(hash);
573 if (i != mapTx.end())
574 entries.push_back(&*i);
578 for (
const auto& tx : vtx)
580 txiter it = mapTx.find(tx->GetHash());
581 if (it != mapTx.end()) {
616 assert(fCheckResult);
617 UpdateCoins(tx, mempoolDuplicate, std::numeric_limits<int>::max());
623 if (nCheckFrequency == 0)
626 if (
GetRand(std::numeric_limits<uint32_t>::max()) >= nCheckFrequency)
629 LogPrint(
BCLog::MEMPOOL,
"Checking mempool with %u transactions and %u inputs\n", (
unsigned int)mapTx.size(), (
unsigned int)mapNextTx.size());
631 uint64_t checkTotal = 0;
632 uint64_t innerUsage = 0;
634 CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins));
637 std::list<const CTxMemPoolEntry*> waitingOnDependants;
638 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
640 checkTotal +=
it->GetTxSize();
641 innerUsage +=
it->DynamicMemoryUsage();
644 bool fDependsWait =
false;
648 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
649 if (it2 != mapTx.end()) {
653 setParentCheck.insert(*it2);
658 auto it3 = mapNextTx.find(txin.
prevout);
659 assert(it3 != mapNextTx.end());
660 assert(it3->first == &txin.
prevout);
661 assert(it3->second == &tx);
667 assert(setParentCheck.size() ==
it->GetMemPoolParentsConst().size());
668 assert(std::equal(setParentCheck.begin(), setParentCheck.end(),
it->GetMemPoolParentsConst().begin(), comp));
671 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
674 uint64_t nCountCheck = setAncestors.size() + 1;
675 uint64_t nSizeCheck =
it->GetTxSize();
676 CAmount nFeesCheck =
it->GetModifiedFee();
677 int64_t nSigOpCheck =
it->GetSigOpCost();
679 for (
txiter ancestorIt : setAncestors) {
680 nSizeCheck += ancestorIt->GetTxSize();
681 nFeesCheck += ancestorIt->GetModifiedFee();
682 nSigOpCheck += ancestorIt->GetSigOpCost();
685 assert(
it->GetCountWithAncestors() == nCountCheck);
686 assert(
it->GetSizeWithAncestors() == nSizeCheck);
687 assert(
it->GetSigOpCostWithAncestors() == nSigOpCheck);
688 assert(
it->GetModFeesWithAncestors() == nFeesCheck);
692 auto iter = mapNextTx.lower_bound(
COutPoint(
it->GetTx().GetHash(), 0));
693 uint64_t child_sizes = 0;
694 for (; iter != mapNextTx.end() && iter->first->hash ==
it->GetTx().GetHash(); ++iter) {
695 txiter childit = mapTx.find(iter->second->GetHash());
696 assert(childit != mapTx.end());
697 if (setChildrenCheck.insert(*childit).second) {
698 child_sizes += childit->GetTxSize();
701 assert(setChildrenCheck.size() ==
it->GetMemPoolChildrenConst().size());
702 assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(),
it->GetMemPoolChildrenConst().begin(), comp));
705 assert(
it->GetSizeWithDescendants() >= child_sizes +
it->GetTxSize());
708 waitingOnDependants.push_back(&(*
it));
713 unsigned int stepsSinceLastRemove = 0;
714 while (!waitingOnDependants.empty()) {
716 waitingOnDependants.pop_front();
718 waitingOnDependants.push_back(entry);
719 stepsSinceLastRemove++;
720 assert(stepsSinceLastRemove < waitingOnDependants.size());
723 stepsSinceLastRemove = 0;
726 for (
auto it = mapNextTx.cbegin();
it != mapNextTx.cend();
it++) {
728 indexed_transaction_set::const_iterator it2 = mapTx.find(hash);
730 assert(it2 != mapTx.end());
731 assert(&tx ==
it->second);
741 indexed_transaction_set::const_iterator i = wtxid ?
get_iter_from_wtxid(hasha) : mapTx.find(hasha);
742 if (i == mapTx.end())
return false;
743 indexed_transaction_set::const_iterator j = wtxid ?
get_iter_from_wtxid(hashb) : mapTx.find(hashb);
744 if (j == mapTx.end())
return true;
745 uint64_t counta = i->GetCountWithAncestors();
746 uint64_t countb = j->GetCountWithAncestors();
747 if (counta == countb) {
750 return counta < countb;
754 class DepthAndScoreComparator
757 bool operator()(
const CTxMemPool::indexed_transaction_set::const_iterator& a,
const CTxMemPool::indexed_transaction_set::const_iterator& b)
759 uint64_t counta = a->GetCountWithAncestors();
760 uint64_t countb = b->GetCountWithAncestors();
761 if (counta == countb) {
764 return counta < countb;
771 std::vector<indexed_transaction_set::const_iterator> iters;
774 iters.reserve(mapTx.size());
776 for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
779 std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
789 vtxid.reserve(mapTx.size());
791 for (
auto it : iters) {
792 vtxid.push_back(
it->GetTx().GetHash());
797 return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
805 std::vector<TxMempoolInfo> ret;
806 ret.reserve(mapTx.size());
807 for (
auto it : iters) {
817 indexed_transaction_set::const_iterator i = mapTx.find(hash);
818 if (i == mapTx.end())
820 return i->GetSharedTx();
827 if (i == mapTx.end())
841 if (it != mapTx.end()) {
845 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
848 for (
txiter ancestorIt : setAncestors) {
854 setDescendants.erase(it);
855 for (
txiter descendantIt : setDescendants) {
867 std::map<uint256, CAmount>::const_iterator pos =
mapDeltas.find(hash);
870 const CAmount &delta = pos->second;
882 const auto it = mapNextTx.find(prevout);
883 return it == mapNextTx.end() ?
nullptr :
it->second;
888 auto it = mapTx.find(txid);
889 if (
it != mapTx.end())
return it;
896 for (
const auto& h : hashes) {
898 if (mi) ret.insert(*mi);
905 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
919 if (outpoint.
n < ptx->vout.size()) {
938 if (m_unbroadcast_txids.erase(txid))
940 LogPrint(
BCLog::MEMPOOL,
"Removed %i from set of unbroadcast txns%s\n", txid.
GetHex(), (unchecked ?
" before confirmation that txn was sent out" :
""));
955 indexed_transaction_set::index<entry_time>::type::iterator
it = mapTx.get<
entry_time>().begin();
957 while (it != mapTx.get<
entry_time>().end() && it->GetTime() < time) {
958 toremove.insert(mapTx.project<0>(it));
962 for (
txiter removeit : toremove) {
972 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
975 return addUnchecked(entry, setAncestors, validFeeEstimate);
982 if (add && entry->GetMemPoolChildren().insert(*child).second) {
984 }
else if (!add && entry->GetMemPoolChildren().erase(*child)) {
993 if (add && entry->GetMemPoolParents().insert(*parent).second) {
995 }
else if (!add && entry->GetMemPoolParents().erase(*parent)) {
1035 unsigned nTxnRemoved = 0;
1038 indexed_transaction_set::index<descendant_score>::type::iterator
it = mapTx.get<
descendant_score>().begin();
1044 CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants());
1047 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1051 nTxnRemoved += stage.size();
1053 std::vector<CTransaction> txn;
1054 if (pvNoSpendsRemaining) {
1055 txn.reserve(stage.size());
1056 for (
txiter iter : stage)
1057 txn.push_back(iter->GetTx());
1060 if (pvNoSpendsRemaining) {
1062 for (
const CTxIn& txin : tx.vin) {
1064 pvNoSpendsRemaining->push_back(txin.
prevout);
1070 if (maxFeeRateRemoved >
CFeeRate(0)) {
1077 std::vector<txiter> candidates;
1079 candidates.push_back(entry);
1080 uint64_t maximum = 0;
1081 while (candidates.size()) {
1082 txiter candidate = candidates.back();
1083 candidates.pop_back();
1084 if (!counted.insert(candidate).second)
continue;
1086 if (parents.size() == 0) {
1087 maximum = std::max(maximum, candidate->GetCountWithDescendants());
1090 candidates.push_back(mapTx.iterator_to(i));
1099 auto it = mapTx.find(txid);
1100 ancestors = descendants = 0;
1101 if (
it != mapTx.end()) {
1102 ancestors =
it->GetCountWithAncestors();
1116 m_is_loaded = loaded;
1135 pool.m_has_epoch_guard =
false;
std::shared_ptr< const CTransaction > CTransactionRef
static int64_t GetTransactionWeight(const CTransaction &tx)
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
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.
#define LogPrint(category,...)
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
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.
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)
static void LogPrintf(const char *fmt, const Args &...args)
std::string GetHex() const
Removed in size limiting.
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
bool exists(const GenTxid >xid) const
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
CTxMemPool(CBlockPolicyEstimator *estimator=nullptr)
Create a new CTxMemPool.
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule) ...
CTransactionRef get(const uint256 &hash) const
size_t DynamicMemoryUsage() const
bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb, bool wtxid=false)
std::set< txiter, CompareIteratorByHash > setEntries
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
size_t DynamicMemoryUsage() const
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 CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
uint64_t nCountWithDescendants
number of descendant transactions
int64_t lastRollingFeeUpdate
const Children & GetMemPoolChildrenConst() const
const std::vector< CTxIn > vin
std::vector< TxMempoolInfo > infoAll() const
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
std::string ToString() const
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
bool visited(txiter it) const EXCLUSIVE_LOCKS_REQUIRED(cs)
visited marks a CTxMemPoolEntry as having been traversed during the lifetime of the most recently cre...
void addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs
unsigned int GetTransactionsUpdated() const
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
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)
void queryHashes(std::vector< uint256 > &vtxid) const
bool CheckFinalTx(const CTransaction &tx, int flags)
Transaction validation functions.
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
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.
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.
TxMempoolInfo info(const uint256 &hash) const
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Removed for conflict with in-block transaction.
AssertLockHeld(mempool.cs)
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
const std::vector< CTxOut > vout
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
static const unsigned char k1[32]
bool isSpent(const COutPoint &outpoint) const
CMainSignals & GetMainSignals()
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
static const int ROLLING_FEE_HALFLIFE
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain. ...
CAmount nModFeesWithAncestors
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)
const uint256 & GetWitnessHash() const
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.
const uint256 & GetHash() const
const int64_t sigOpCost
Total sigop cost.
void GetTransactionAncestry(const uint256 &txid, size_t &ancestors, size_t &descendants) const
Calculate the ancestor and descendant count for the given transaction.
EpochGuard(const CTxMemPool &in)
static void CheckInputsAndUpdateCoins(const CTransaction &tx, CCoinsViewCache &mempoolDuplicate, const int64_t spendheight)
const CTransaction & GetTx() const
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 ...
void check(const CCoinsViewCache *pcoins) const
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
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...
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.
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
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::set< CTxMemPoolEntryRef, CompareIteratorByHash > Children
uint64_t nCountWithAncestors
Fee rate in satoshis per kilobyte: CAmount / kB.
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.
const uint256 & GetHash() 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.
boost::optional< T > Optional
Substitute for C++17 std::optional.
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)
void processBlock(unsigned int nBlockHeight, std::vector< const CTxMemPoolEntry * > &entries)
Process all the transactions that have been included in a block.
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).
EpochGuard: RAII-style guard for using epoch-based graph traversal algorithms.
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 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.