25 int64_t _nTime,
unsigned int _entryHeight,
26 bool _spendsCoinbase, int64_t _sigOpsCost,
LockPoints lp)
65 stageEntries = updateIt->GetMemPoolChildrenConst();
67 while (!stageEntries.empty()) {
69 descendants.insert(descendant);
70 stageEntries.erase(descendant);
73 cacheMap::iterator cacheIt = cachedDescendants.find(mapTx.iterator_to(childEntry));
74 if (cacheIt != cachedDescendants.end()) {
77 for (
txiter cacheEntry : cacheIt->second) {
78 descendants.insert(*cacheEntry);
80 }
else if (!descendants.count(childEntry)) {
82 stageEntries.insert(childEntry);
88 int64_t modifySize = 0;
90 int64_t modifyCount = 0;
92 if (!setExclude.count(descendant.GetTx().GetHash())) {
93 modifySize += descendant.GetTxSize();
94 modifyFee += descendant.GetModifiedFee();
96 cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
98 mapTx.modify(mapTx.iterator_to(descendant),
update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()));
115 cacheMap mapMemPoolDescendantsToUpdate;
119 std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
129 if (
it == mapTx.end()) {
132 auto iter = mapNextTx.lower_bound(
COutPoint(hash, 0));
138 for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
139 const uint256 &childHash = iter->second->GetHash();
140 txiter childIter = mapTx.find(childHash);
141 assert(childIter != mapTx.end());
144 if (!
visited(childIter) && !setAlreadyIncluded.count(childHash)) {
159 if (fSearchForParents) {
163 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
164 std::optional<txiter> piter =
GetIter(tx.
vin[i].prevout.hash);
166 staged_ancestors.insert(**piter);
167 if (staged_ancestors.size() + 1 > limitAncestorCount) {
168 errString =
strprintf(
"too many unconfirmed parents [limit: %u]", limitAncestorCount);
176 txiter it = mapTx.iterator_to(entry);
177 staged_ancestors =
it->GetMemPoolParentsConst();
180 size_t totalSizeWithAncestors = entry.
GetTxSize();
182 while (!staged_ancestors.empty()) {
184 txiter stageit = mapTx.iterator_to(stage);
186 setAncestors.insert(stageit);
187 staged_ancestors.erase(stage);
188 totalSizeWithAncestors += stageit->
GetTxSize();
190 if (stageit->GetSizeWithDescendants() + entry.
GetTxSize() > limitDescendantSize) {
191 errString =
strprintf(
"exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
193 }
else if (stageit->GetCountWithDescendants() + 1 > limitDescendantCount) {
194 errString =
strprintf(
"too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
196 }
else if (totalSizeWithAncestors > limitAncestorSize) {
197 errString =
strprintf(
"exceeds ancestor size limit [limit: %u]", limitAncestorSize);
203 txiter parent_it = mapTx.iterator_to(parent);
206 if (setAncestors.count(parent_it) == 0) {
207 staged_ancestors.insert(parent);
209 if (staged_ancestors.size() + setAncestors.size() + 1 > limitAncestorCount) {
210 errString =
strprintf(
"too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
226 const int64_t updateCount = (add ? 1 : -1);
227 const int64_t updateSize = updateCount *
it->GetTxSize();
228 const CAmount updateFee = updateCount *
it->GetModifiedFee();
229 for (
txiter ancestorIt : setAncestors) {
236 int64_t updateCount = setAncestors.size();
237 int64_t updateSize = 0;
239 int64_t updateSigOpsCost = 0;
240 for (
txiter ancestorIt : setAncestors) {
241 updateSize += ancestorIt->GetTxSize();
242 updateFee += ancestorIt->GetModifiedFee();
243 updateSigOpsCost += ancestorIt->GetSigOpCost();
260 const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
261 if (updateDescendants) {
268 for (
txiter removeIt : entriesToRemove) {
271 setDescendants.erase(removeIt);
272 int64_t modifySize = -((int64_t)removeIt->GetTxSize());
273 CAmount modifyFee = -removeIt->GetModifiedFee();
274 int modifySigOps = -removeIt->GetSigOpCost();
275 for (
txiter dit : setDescendants) {
280 for (
txiter removeIt : entriesToRemove) {
311 for (
txiter removeIt : entriesToRemove) {
337 : m_check_ratio(check_ratio), minerPolicyEstimator(estimator)
345 return mapNextTx.count(outpoint);
363 indexed_transaction_set::iterator newit = mapTx.insert(entry).first;
380 std::set<uint256> setParentTransactions;
381 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
382 mapNextTx.insert(std::make_pair(&tx.
vin[i].prevout, &tx));
383 setParentTransactions.insert(tx.
vin[i].prevout.hash);
393 for (
const auto& pit :
GetIterSet(setParentTransactions)) {
401 m_total_fee += entry.
GetFee();
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();
439 totalTxSize -=
it->GetTxSize();
440 m_total_fee -=
it->GetFee();
441 cachedInnerUsage -=
it->DynamicMemoryUsage();
457 if (setDescendants.count(entryit) == 0) {
458 stage.insert(entryit);
463 while (!stage.empty()) {
465 setDescendants.insert(
it);
470 txiter childiter = mapTx.iterator_to(child);
471 if (!setDescendants.count(childiter)) {
472 stage.insert(childiter);
484 if (origit != mapTx.end()) {
485 txToRemove.insert(origit);
491 for (
unsigned int i = 0; i < origTx.
vout.size(); i++) {
493 if (
it == mapNextTx.end())
495 txiter nextit = mapTx.find(
it->second->GetHash());
496 assert(nextit != mapTx.end());
497 txToRemove.insert(nextit);
513 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
522 txToRemove.insert(
it);
523 }
else if (
it->GetSpendsCoinbase()) {
524 for (
const CTxIn& txin : tx.vin) {
525 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
526 if (it2 != mapTx.end())
532 txToRemove.insert(
it);
554 if (
it != mapNextTx.end()) {
556 if (txConflict != tx)
571 std::vector<const CTxMemPoolEntry*> entries;
572 for (
const auto& tx : vtx)
576 indexed_transaction_set::iterator i = mapTx.find(hash);
577 if (i != mapTx.end())
578 entries.push_back(&*i);
582 for (
const auto& tx : vtx)
585 if (
it != mapTx.end()) {
593 lastRollingFeeUpdate =
GetTime();
594 blockSinceLastRollingFeeBump =
true;
603 cachedInnerUsage = 0;
604 lastRollingFeeUpdate =
GetTime();
605 blockSinceLastRollingFeeBump =
false;
606 rollingMinimumFeeRate = 0;
622 UpdateCoins(tx, mempoolDuplicate, std::numeric_limits<int>::max());
625 void CTxMemPool::check(
CChainState& active_chainstate)
const 633 LogPrint(
BCLog::MEMPOOL,
"Checking mempool with %u transactions and %u inputs\n", (
unsigned int)mapTx.size(), (
unsigned int)mapNextTx.size());
635 uint64_t checkTotal = 0;
637 uint64_t innerUsage = 0;
640 CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
641 const int64_t spendheight = active_chainstate.
m_chain.
Height() + 1;
643 std::list<const CTxMemPoolEntry*> waitingOnDependants;
644 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
646 checkTotal +=
it->GetTxSize();
647 check_total_fee +=
it->GetFee();
648 innerUsage +=
it->DynamicMemoryUsage();
651 bool fDependsWait =
false;
655 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
656 if (it2 != mapTx.end()) {
660 setParentCheck.insert(*it2);
665 auto it3 = mapNextTx.find(txin.
prevout);
666 assert(it3 != mapNextTx.end());
668 assert(it3->second == &tx);
674 assert(setParentCheck.size() ==
it->GetMemPoolParentsConst().size());
675 assert(std::equal(setParentCheck.begin(), setParentCheck.end(),
it->GetMemPoolParentsConst().begin(), comp));
678 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
681 uint64_t nCountCheck = setAncestors.size() + 1;
682 uint64_t nSizeCheck =
it->GetTxSize();
683 CAmount nFeesCheck =
it->GetModifiedFee();
684 int64_t nSigOpCheck =
it->GetSigOpCost();
686 for (
txiter ancestorIt : setAncestors) {
687 nSizeCheck += ancestorIt->GetTxSize();
688 nFeesCheck += ancestorIt->GetModifiedFee();
689 nSigOpCheck += ancestorIt->GetSigOpCost();
692 assert(
it->GetCountWithAncestors() == nCountCheck);
693 assert(
it->GetSizeWithAncestors() == nSizeCheck);
694 assert(
it->GetSigOpCostWithAncestors() == nSigOpCheck);
695 assert(
it->GetModFeesWithAncestors() == nFeesCheck);
699 auto iter = mapNextTx.lower_bound(
COutPoint(
it->GetTx().GetHash(), 0));
700 uint64_t child_sizes = 0;
701 for (; iter != mapNextTx.end() && iter->first->hash ==
it->GetTx().GetHash(); ++iter) {
702 txiter childit = mapTx.find(iter->second->GetHash());
703 assert(childit != mapTx.end());
704 if (setChildrenCheck.insert(*childit).second) {
705 child_sizes += childit->GetTxSize();
708 assert(setChildrenCheck.size() ==
it->GetMemPoolChildrenConst().size());
709 assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(),
it->GetMemPoolChildrenConst().begin(), comp));
712 assert(
it->GetSizeWithDescendants() >= child_sizes +
it->GetTxSize());
715 waitingOnDependants.push_back(&(*
it));
720 unsigned int stepsSinceLastRemove = 0;
721 while (!waitingOnDependants.empty()) {
723 waitingOnDependants.pop_front();
724 if (!mempoolDuplicate.HaveInputs(entry->
GetTx())) {
725 waitingOnDependants.push_back(entry);
726 stepsSinceLastRemove++;
727 assert(stepsSinceLastRemove < waitingOnDependants.size());
730 stepsSinceLastRemove = 0;
733 for (
auto it = mapNextTx.cbegin();
it != mapNextTx.cend();
it++) {
735 indexed_transaction_set::const_iterator it2 = mapTx.find(hash);
737 assert(it2 != mapTx.end());
741 assert(totalTxSize == checkTotal);
742 assert(m_total_fee == check_total_fee);
743 assert(innerUsage == cachedInnerUsage);
749 indexed_transaction_set::const_iterator i = wtxid ?
get_iter_from_wtxid(hasha) : mapTx.find(hasha);
750 if (i == mapTx.end())
return false;
751 indexed_transaction_set::const_iterator j = wtxid ?
get_iter_from_wtxid(hashb) : mapTx.find(hashb);
752 if (j == mapTx.end())
return true;
753 uint64_t counta = i->GetCountWithAncestors();
754 uint64_t countb = j->GetCountWithAncestors();
755 if (counta == countb) {
758 return counta < countb;
762 class DepthAndScoreComparator
765 bool operator()(
const CTxMemPool::indexed_transaction_set::const_iterator& a,
const CTxMemPool::indexed_transaction_set::const_iterator& b)
767 uint64_t counta = a->GetCountWithAncestors();
768 uint64_t countb = b->GetCountWithAncestors();
769 if (counta == countb) {
772 return counta < countb;
779 std::vector<indexed_transaction_set::const_iterator> iters;
782 iters.reserve(mapTx.size());
784 for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
787 std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
797 vtxid.reserve(mapTx.size());
799 for (
auto it : iters) {
800 vtxid.push_back(
it->GetTx().GetHash());
805 return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
813 std::vector<TxMempoolInfo> ret;
814 ret.reserve(mapTx.size());
815 for (
auto it : iters) {
825 indexed_transaction_set::const_iterator i = mapTx.find(hash);
826 if (i == mapTx.end())
828 return i->GetSharedTx();
835 if (i == mapTx.end())
846 CAmount &delta = mapDeltas[hash];
849 if (
it != mapTx.end()) {
853 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
856 for (
txiter ancestorIt : setAncestors) {
862 setDescendants.erase(
it);
863 for (
txiter descendantIt : setDescendants) {
875 std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
876 if (pos == mapDeltas.end())
878 const CAmount &delta = pos->second;
885 mapDeltas.erase(hash);
890 const auto it = mapNextTx.find(prevout);
891 return it == mapNextTx.end() ? nullptr :
it->second;
896 auto it = mapTx.find(txid);
897 if (
it != mapTx.end())
return it;
904 for (
const auto& h : hashes) {
906 if (mi) ret.insert(*mi);
913 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
934 if (outpoint.
n < ptx->vout.size()) {
946 for (
unsigned int n = 0; n < tx->vout.size(); ++n) {
960 if (m_unbroadcast_txids.erase(txid))
962 LogPrint(
BCLog::MEMPOOL,
"Removed %i from set of unbroadcast txns%s\n", txid.
GetHex(), (unchecked ?
" before confirmation that txn was sent out" :
""));
977 indexed_transaction_set::index<entry_time>::type::iterator
it = mapTx.get<
entry_time>().begin();
979 while (
it != mapTx.get<
entry_time>().end() &&
it->GetTime() < time) {
980 toremove.insert(mapTx.project<0>(
it));
984 for (
txiter removeit : toremove) {
994 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
997 return addUnchecked(entry, setAncestors, validFeeEstimate);
1004 if (add && entry->GetMemPoolChildren().insert(*child).second) {
1006 }
else if (!add && entry->GetMemPoolChildren().erase(*child)) {
1015 if (add && entry->GetMemPoolParents().insert(*parent).second) {
1017 }
else if (!add && entry->GetMemPoolParents().erase(*parent)) {
1024 if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
1025 return CFeeRate(llround(rollingMinimumFeeRate));
1028 if (time > lastRollingFeeUpdate + 10) {
1035 rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
1036 lastRollingFeeUpdate = time;
1039 rollingMinimumFeeRate = 0;
1048 if (rate.
GetFeePerK() > rollingMinimumFeeRate) {
1050 blockSinceLastRollingFeeBump =
false;
1057 unsigned nTxnRemoved = 0;
1060 indexed_transaction_set::index<descendant_score>::type::iterator
it = mapTx.get<
descendant_score>().begin();
1066 CFeeRate removed(
it->GetModFeesWithDescendants(),
it->GetSizeWithDescendants());
1069 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1073 nTxnRemoved += stage.size();
1075 std::vector<CTransaction> txn;
1076 if (pvNoSpendsRemaining) {
1077 txn.reserve(stage.size());
1078 for (
txiter iter : stage)
1079 txn.push_back(iter->GetTx());
1082 if (pvNoSpendsRemaining) {
1086 pvNoSpendsRemaining->push_back(txin.
prevout);
1092 if (maxFeeRateRemoved >
CFeeRate(0)) {
1099 std::vector<txiter> candidates;
1101 candidates.push_back(entry);
1102 uint64_t maximum = 0;
1103 while (candidates.size()) {
1104 txiter candidate = candidates.back();
1105 candidates.pop_back();
1106 if (!counted.insert(candidate).second)
continue;
1108 if (parents.size() == 0) {
1109 maximum = std::max(maximum, candidate->GetCountWithDescendants());
1112 candidates.push_back(mapTx.iterator_to(i));
1121 auto it = mapTx.find(txid);
1122 ancestors = descendants = 0;
1123 if (
it != mapTx.end()) {
1124 ancestors =
it->GetCountWithAncestors();
1138 m_is_loaded = loaded;
std::shared_ptr< const CTransaction > CTransactionRef
static int64_t GetTransactionWeight(const CTransaction &tx)
void queryHashes(std::vector< uint256 > &vtxid) const
bool IsSpent() const
Either this coin never existed (see e.g.
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)
CChain m_chain
The current chain of blockheaders we consult and build on.
#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)
int Height() const
Return the maximal height in the chain.
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) ...
CChainState stores and provides an API to update our local knowledge of the current best chain...
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)
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
uint64_t nCountWithDescendants
number of descendant transactions
void removeForReorg(CChainState &active_chainstate, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs
#define WITH_FRESH_EPOCH(epoch)
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 check(CChainState &active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED(void addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
const int m_check_ratio
Value n means that 1 times in n we check.
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)
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)
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
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
const CAmount & GetFee() 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::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
const std::vector< CTxOut > vout
CMainSignals & GetMainSignals()
static const int ROLLING_FEE_HALFLIFE
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 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.
bool CheckSequenceLocks(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
Check if transaction will be BIP68 final in the next block to be created on top of tip...
CTxMemPool(CBlockPolicyEstimator *estimator=nullptr, int check_ratio=0)
Create a new CTxMemPool.
const int64_t sigOpCost
Total sigop cost.
std::optional< txiter > GetIter(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
bool TestLockPointValidity(CChain &active_chain, const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain. ...
void check(CChainState &active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
bool CheckFinalTx(const CBlockIndex *active_chain_tip, const CTransaction &tx, int flags)
Transaction validation functions.
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)
bool visited(const txiter it) const EXCLUSIVE_LOCKS_REQUIRED(cs
visited marks a CTxMemPoolEntry as having been traversed during the lifetime of the most recently cre...
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
LockPoints lockPoints
Track the height and time at which tx was final.
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. ...
CBlockPolicyEstimator *const minerPolicyEstimator
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
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)
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
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. ...
int nHeight
height of the entry in the chain. The genesis block has height 0
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...
CCoinsView that brings transactions from a mempool into view.
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.
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
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.