45 int64_t time,
unsigned int entry_height,
46 bool spends_coinbase, int64_t sigops_cost,
LockPoints lp)
52 entryHeight{entry_height},
57 nSizeWithDescendants{GetTxSize()},
58 nModFeesWithDescendants{nFee},
59 nSizeWithAncestors{GetTxSize()},
60 nModFeesWithAncestors{nFee},
81 const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove)
84 stageEntries = updateIt->GetMemPoolChildrenConst();
86 while (!stageEntries.empty()) {
88 descendants.insert(descendant);
89 stageEntries.erase(descendant);
92 cacheMap::iterator cacheIt = cachedDescendants.find(mapTx.iterator_to(childEntry));
93 if (cacheIt != cachedDescendants.end()) {
96 for (
txiter cacheEntry : cacheIt->second) {
97 descendants.insert(*cacheEntry);
99 }
else if (!descendants.count(childEntry)) {
101 stageEntries.insert(childEntry);
107 int64_t modifySize = 0;
109 int64_t modifyCount = 0;
111 if (!setExclude.count(descendant.GetTx().GetHash())) {
112 modifySize += descendant.GetTxSize();
113 modifyFee += descendant.GetModifiedFee();
115 cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
118 e.UpdateAncestorState(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost());
124 descendants_to_remove.insert(descendant.GetTx().GetHash());
137 cacheMap mapMemPoolDescendantsToUpdate;
141 std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
143 std::set<uint256> descendants_to_remove;
153 if (
it == mapTx.end()) {
156 auto iter = mapNextTx.lower_bound(
COutPoint(hash, 0));
162 for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
163 const uint256 &childHash = iter->second->GetHash();
164 txiter childIter = mapTx.find(childHash);
165 assert(childIter != mapTx.end());
168 if (!
visited(childIter) && !setAlreadyIncluded.count(childHash)) {
177 for (
const auto& txid : descendants_to_remove) {
190 uint64_t limitAncestorCount,
191 uint64_t limitAncestorSize,
192 uint64_t limitDescendantCount,
193 uint64_t limitDescendantSize,
194 std::string &errString)
const 196 size_t totalSizeWithAncestors = entry_size;
198 while (!staged_ancestors.empty()) {
200 txiter stageit = mapTx.iterator_to(stage);
202 setAncestors.insert(stageit);
203 staged_ancestors.erase(stage);
204 totalSizeWithAncestors += stageit->
GetTxSize();
206 if (stageit->GetSizeWithDescendants() + entry_size > limitDescendantSize) {
207 errString =
strprintf(
"exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
209 }
else if (stageit->GetCountWithDescendants() + entry_count > limitDescendantCount) {
210 errString =
strprintf(
"too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
212 }
else if (totalSizeWithAncestors > limitAncestorSize) {
213 errString =
strprintf(
"exceeds ancestor size limit [limit: %u]", limitAncestorSize);
219 txiter parent_it = mapTx.iterator_to(parent);
222 if (setAncestors.count(parent_it) == 0) {
223 staged_ancestors.insert(parent);
225 if (staged_ancestors.size() + setAncestors.size() + entry_count > limitAncestorCount) {
226 errString =
strprintf(
"too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
236 uint64_t limitAncestorCount,
237 uint64_t limitAncestorSize,
238 uint64_t limitDescendantCount,
239 uint64_t limitDescendantSize,
240 std::string &errString)
const 243 size_t total_size = 0;
244 for (
const auto& tx : package) {
246 for (
const auto& input : tx->vin) {
247 std::optional<txiter> piter =
GetIter(input.prevout.hash);
249 staged_ancestors.insert(**piter);
250 if (staged_ancestors.size() + package.size() > limitAncestorCount) {
251 errString =
strprintf(
"too many unconfirmed parents [limit: %u]", limitAncestorCount);
262 setAncestors, staged_ancestors,
263 limitAncestorCount, limitAncestorSize,
264 limitDescendantCount, limitDescendantSize, errString);
266 if (!
ret) errString.insert(0,
"possibly ");
272 uint64_t limitAncestorCount,
273 uint64_t limitAncestorSize,
274 uint64_t limitDescendantCount,
275 uint64_t limitDescendantSize,
276 std::string &errString,
277 bool fSearchForParents )
const 282 if (fSearchForParents) {
286 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
287 std::optional<txiter> piter =
GetIter(tx.
vin[i].prevout.hash);
289 staged_ancestors.insert(**piter);
290 if (staged_ancestors.size() + 1 > limitAncestorCount) {
291 errString =
strprintf(
"too many unconfirmed parents [limit: %u]", limitAncestorCount);
299 txiter it = mapTx.iterator_to(entry);
300 staged_ancestors =
it->GetMemPoolParentsConst();
304 setAncestors, staged_ancestors,
305 limitAncestorCount, limitAncestorSize,
306 limitDescendantCount, limitDescendantSize, errString);
316 const int64_t updateCount = (add ? 1 : -1);
317 const int64_t updateSize = updateCount *
it->GetTxSize();
318 const CAmount updateFee = updateCount *
it->GetModifiedFee();
319 for (
txiter ancestorIt : setAncestors) {
326 int64_t updateCount = setAncestors.size();
327 int64_t updateSize = 0;
329 int64_t updateSigOpsCost = 0;
330 for (
txiter ancestorIt : setAncestors) {
331 updateSize += ancestorIt->GetTxSize();
332 updateFee += ancestorIt->GetModifiedFee();
333 updateSigOpsCost += ancestorIt->GetSigOpCost();
350 const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
351 if (updateDescendants) {
358 for (
txiter removeIt : entriesToRemove) {
361 setDescendants.erase(removeIt);
362 int64_t modifySize = -((int64_t)removeIt->GetTxSize());
363 CAmount modifyFee = -removeIt->GetModifiedFee();
364 int modifySigOps = -removeIt->GetSigOpCost();
365 for (
txiter dit : setDescendants) {
370 for (
txiter removeIt : entriesToRemove) {
401 for (
txiter removeIt : entriesToRemove) {
428 minerPolicyEstimator{opts.estimator},
429 m_max_size_bytes{opts.max_size_bytes},
430 m_expiry{opts.expiry},
431 m_incremental_relay_feerate{opts.incremental_relay_feerate},
432 m_min_relay_feerate{opts.min_relay_feerate},
433 m_dust_relay_feerate{opts.dust_relay_feerate},
434 m_permit_bare_multisig{opts.permit_bare_multisig},
435 m_max_datacarrier_bytes{opts.max_datacarrier_bytes},
436 m_require_standard{opts.require_standard},
437 m_full_rbf{opts.full_rbf},
438 m_limits{opts.limits}
446 return mapNextTx.count(outpoint);
464 indexed_transaction_set::iterator newit = mapTx.insert(entry).first;
481 std::set<uint256> setParentTransactions;
482 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
483 mapNextTx.insert(std::make_pair(&tx.
vin[i].prevout, &tx));
484 setParentTransactions.insert(tx.
vin[i].prevout.hash);
494 for (
const auto& pit :
GetIterSet(setParentTransactions)) {
502 m_total_fee += entry.
GetFee();
508 newit->vTxHashesIdx = vTxHashes.size() - 1;
525 const uint256 hash =
it->GetTx().GetHash();
526 for (
const CTxIn& txin :
it->GetTx().vin)
527 mapNextTx.erase(txin.prevout);
531 if (vTxHashes.size() > 1) {
532 vTxHashes[
it->vTxHashesIdx] = std::move(vTxHashes.back());
533 vTxHashes[
it->vTxHashesIdx].second->vTxHashesIdx =
it->vTxHashesIdx;
534 vTxHashes.pop_back();
535 if (vTxHashes.size() * 2 < vTxHashes.capacity())
536 vTxHashes.shrink_to_fit();
540 totalTxSize -=
it->GetTxSize();
541 m_total_fee -=
it->GetFee();
542 cachedInnerUsage -=
it->DynamicMemoryUsage();
558 if (setDescendants.count(entryit) == 0) {
559 stage.insert(entryit);
564 while (!stage.empty()) {
566 setDescendants.insert(
it);
571 txiter childiter = mapTx.iterator_to(child);
572 if (!setDescendants.count(childiter)) {
573 stage.insert(childiter);
585 if (origit != mapTx.end()) {
586 txToRemove.insert(origit);
592 for (
unsigned int i = 0; i < origTx.
vout.size(); i++) {
594 if (
it == mapNextTx.end())
596 txiter nextit = mapTx.find(
it->second->GetHash());
597 assert(nextit != mapTx.end());
598 txToRemove.insert(nextit);
616 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
617 if (check_final_and_mature(
it)) txToRemove.insert(
it);
624 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
635 if (
it != mapNextTx.end()) {
637 if (txConflict != tx)
652 std::vector<const CTxMemPoolEntry*> entries;
653 for (
const auto& tx : vtx)
657 indexed_transaction_set::iterator i = mapTx.find(hash);
658 if (i != mapTx.end())
659 entries.push_back(&*i);
663 for (
const auto& tx : vtx)
666 if (
it != mapTx.end()) {
674 lastRollingFeeUpdate =
GetTime();
675 blockSinceLastRollingFeeBump =
true;
685 cachedInnerUsage = 0;
686 lastRollingFeeUpdate =
GetTime();
687 blockSinceLastRollingFeeBump =
false;
688 rollingMinimumFeeRate = 0;
698 void CTxMemPool::check(
const CCoinsViewCache& active_coins_tip, int64_t spendheight)
const 706 LogPrint(
BCLog::MEMPOOL,
"Checking mempool with %u transactions and %u inputs\n", (
unsigned int)mapTx.size(), (
unsigned int)mapNextTx.size());
708 uint64_t checkTotal = 0;
710 uint64_t innerUsage = 0;
711 uint64_t prev_ancestor_count{0};
713 CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
716 checkTotal +=
it->GetTxSize();
717 check_total_fee +=
it->GetFee();
718 innerUsage +=
it->DynamicMemoryUsage();
724 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
725 if (it2 != mapTx.end()) {
728 setParentCheck.insert(*it2);
735 auto it3 = mapNextTx.find(txin.
prevout);
736 assert(it3 != mapNextTx.end());
738 assert(it3->second == &tx);
743 assert(setParentCheck.size() ==
it->GetMemPoolParentsConst().size());
744 assert(std::equal(setParentCheck.begin(), setParentCheck.end(),
it->GetMemPoolParentsConst().begin(), comp));
747 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
750 uint64_t nCountCheck = setAncestors.size() + 1;
751 uint64_t nSizeCheck =
it->GetTxSize();
752 CAmount nFeesCheck =
it->GetModifiedFee();
753 int64_t nSigOpCheck =
it->GetSigOpCost();
755 for (
txiter ancestorIt : setAncestors) {
756 nSizeCheck += ancestorIt->GetTxSize();
757 nFeesCheck += ancestorIt->GetModifiedFee();
758 nSigOpCheck += ancestorIt->GetSigOpCost();
761 assert(
it->GetCountWithAncestors() == nCountCheck);
762 assert(
it->GetSizeWithAncestors() == nSizeCheck);
763 assert(
it->GetSigOpCostWithAncestors() == nSigOpCheck);
764 assert(
it->GetModFeesWithAncestors() == nFeesCheck);
766 assert(prev_ancestor_count <= it->GetCountWithAncestors());
767 prev_ancestor_count =
it->GetCountWithAncestors();
771 auto iter = mapNextTx.lower_bound(
COutPoint(
it->GetTx().GetHash(), 0));
772 uint64_t child_sizes = 0;
773 for (; iter != mapNextTx.end() && iter->first->hash ==
it->GetTx().GetHash(); ++iter) {
774 txiter childit = mapTx.find(iter->second->GetHash());
775 assert(childit != mapTx.end());
776 if (setChildrenCheck.insert(*childit).second) {
777 child_sizes += childit->GetTxSize();
780 assert(setChildrenCheck.size() ==
it->GetMemPoolChildrenConst().size());
781 assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(),
it->GetMemPoolChildrenConst().begin(), comp));
784 assert(
it->GetSizeWithDescendants() >= child_sizes +
it->GetTxSize());
790 for (
const auto& input: tx.
vin) mempoolDuplicate.SpendCoin(input.prevout);
791 AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
793 for (
auto it = mapNextTx.cbegin();
it != mapNextTx.cend();
it++) {
795 indexed_transaction_set::const_iterator it2 = mapTx.find(hash);
797 assert(it2 != mapTx.end());
801 assert(totalTxSize == checkTotal);
802 assert(m_total_fee == check_total_fee);
803 assert(innerUsage == cachedInnerUsage);
814 indexed_transaction_set::const_iterator j = wtxid ?
get_iter_from_wtxid(hashb) : mapTx.find(hashb);
815 if (j == mapTx.end())
return false;
816 indexed_transaction_set::const_iterator i = wtxid ?
get_iter_from_wtxid(hasha) : mapTx.find(hasha);
817 if (i == mapTx.end())
return true;
818 uint64_t counta = i->GetCountWithAncestors();
819 uint64_t countb = j->GetCountWithAncestors();
820 if (counta == countb) {
823 return counta < countb;
827 class DepthAndScoreComparator
830 bool operator()(
const CTxMemPool::indexed_transaction_set::const_iterator& a,
const CTxMemPool::indexed_transaction_set::const_iterator& b)
832 uint64_t counta = a->GetCountWithAncestors();
833 uint64_t countb = b->GetCountWithAncestors();
834 if (counta == countb) {
837 return counta < countb;
844 std::vector<indexed_transaction_set::const_iterator> iters;
847 iters.reserve(mapTx.size());
849 for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
852 std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
862 vtxid.reserve(mapTx.size());
864 for (
auto it : iters) {
865 vtxid.push_back(
it->GetTx().GetHash());
870 return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
878 std::vector<TxMempoolInfo>
ret;
879 ret.reserve(mapTx.size());
880 for (
auto it : iters) {
890 indexed_transaction_set::const_iterator i = mapTx.find(hash);
891 if (i == mapTx.end())
893 return i->GetSharedTx();
900 if (i == mapTx.end())
909 CAmount &delta = mapDeltas[hash];
912 if (
it != mapTx.end()) {
916 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
919 for (
txiter ancestorIt : setAncestors) {
925 setDescendants.erase(
it);
926 for (
txiter descendantIt : setDescendants) {
938 std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
939 if (pos == mapDeltas.end())
941 const CAmount &delta = pos->second;
948 mapDeltas.erase(hash);
953 const auto it = mapNextTx.find(prevout);
954 return it == mapNextTx.end() ? nullptr :
it->second;
959 auto it = mapTx.find(txid);
960 if (
it != mapTx.end())
return it;
967 for (
const auto& h : hashes) {
969 if (mi)
ret.insert(*mi);
976 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
997 if (outpoint.
n < ptx->vout.size()) {
1009 for (
unsigned int n = 0; n < tx->vout.size(); ++n) {
1023 if (m_unbroadcast_txids.erase(txid))
1025 LogPrint(
BCLog::MEMPOOL,
"Removed %i from set of unbroadcast txns%s\n", txid.
GetHex(), (unchecked ?
" before confirmation that txn was sent out" :
""));
1040 indexed_transaction_set::index<entry_time>::type::iterator
it = mapTx.get<
entry_time>().begin();
1042 while (
it != mapTx.get<
entry_time>().end() &&
it->GetTime() < time) {
1043 toremove.insert(mapTx.project<0>(
it));
1047 for (
txiter removeit : toremove) {
1051 return stage.size();
1057 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
1060 return addUnchecked(entry, setAncestors, validFeeEstimate);
1067 if (add && entry->GetMemPoolChildren().insert(*child).second) {
1069 }
else if (!add && entry->GetMemPoolChildren().erase(*child)) {
1078 if (add && entry->GetMemPoolParents().insert(*parent).second) {
1080 }
else if (!add && entry->GetMemPoolParents().erase(*parent)) {
1087 if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
1088 return CFeeRate(llround(rollingMinimumFeeRate));
1091 if (time > lastRollingFeeUpdate + 10) {
1098 rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
1099 lastRollingFeeUpdate = time;
1102 rollingMinimumFeeRate = 0;
1111 if (rate.
GetFeePerK() > rollingMinimumFeeRate) {
1113 blockSinceLastRollingFeeBump =
false;
1120 unsigned nTxnRemoved = 0;
1123 indexed_transaction_set::index<descendant_score>::type::iterator
it = mapTx.get<
descendant_score>().begin();
1129 CFeeRate removed(
it->GetModFeesWithDescendants(),
it->GetSizeWithDescendants());
1132 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1136 nTxnRemoved += stage.size();
1138 std::vector<CTransaction> txn;
1139 if (pvNoSpendsRemaining) {
1140 txn.reserve(stage.size());
1141 for (
txiter iter : stage)
1142 txn.push_back(iter->GetTx());
1145 if (pvNoSpendsRemaining) {
1149 pvNoSpendsRemaining->push_back(txin.
prevout);
1155 if (maxFeeRateRemoved >
CFeeRate(0)) {
1162 std::vector<txiter> candidates;
1164 candidates.push_back(entry);
1165 uint64_t maximum = 0;
1166 while (candidates.size()) {
1167 txiter candidate = candidates.back();
1168 candidates.pop_back();
1169 if (!counted.insert(candidate).second)
continue;
1171 if (parents.size() == 0) {
1172 maximum = std::max(maximum, candidate->GetCountWithDescendants());
1175 candidates.push_back(mapTx.iterator_to(i));
1184 auto it = mapTx.find(txid);
1185 ancestors = descendants = 0;
1186 if (
it != mapTx.end()) {
1187 ancestors =
it->GetCountWithAncestors();
1188 if (ancestorsize) *ancestorsize =
it->GetSizeWithAncestors();
1189 if (ancestorfees) *ancestorfees =
it->GetModFeesWithAncestors();
1197 return m_load_tried;
1203 m_load_tried = load_tried;
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.
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)
void UpdateModifiedFee(CAmount fee_diff)
void processBlock(unsigned int nBlockHeight, std::vector< const CTxMemPoolEntry *> &entries) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Process all the transactions that have been included in a block.
CAmount m_modified_fee
Used for determining the priority of the transaction for mining in a block.
#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
CTxMemPoolEntry(const CTransactionRef &tx, CAmount fee, int64_t time, unsigned int entry_height, bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
bool exists(const GenTxid >xid) const
void UpdateTransactionsFromBlock(const std::vector< uint256 > &vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs
UpdateTransactionsFromBlock is called when adding transactions from a disconnected block back to the ...
An in-memory indexed chain of blocks.
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.
reverse_range< T > reverse_iterate(T &x)
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
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
bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb, bool wtxid=false)
std::set< txiter, CompareIteratorByHash > setEntries
const Children & GetMemPoolChildrenConst() const
CTxMemPool(const Options &opts)
Create a new CTxMemPool.
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 SetLoadTried(bool load_tried)
Set whether or not we've made an attempt to load the mempool (regardless of whether the attempt was s...
CFeeRate GetMinFee() const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
uint64_t nCountWithDescendants
number of descendant transactions
CAmount GetModifiedFee() const
#define WITH_FRESH_EPOCH(epoch)
bool CheckPackageLimits(const Package &package, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Calculate all in-mempool ancestors of a set of transactions not already in the mempool and check ance...
bool isSpent(const COutPoint &outpoint) const
const std::vector< CTxIn > vin
void removeForReorg(CChain &chain, std::function< bool(txiter)> filter_final_and_mature) EXCLUSIVE_LOCKS_REQUIRED(cs
After reorg, filter the entries that would no longer be valid in the next block, and update the entri...
bool removeTx(uint256 hash, bool inBlock) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Remove a transaction from the mempool tracking stats.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) 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)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
void UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude, std::set< uint256 > &descendants_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs)
UpdateForDescendants is used by UpdateTransactionsFromBlock to update the descendants for a single tr...
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction's outputs to a cache.
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
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
uint64_t nSizeWithAncestors
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
const uint256 & GetHash() const
const CAmount & GetFee() const
Removed for conflict with in-block transaction.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
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
bool TestLockPointValidity(CChain &active_chain, const LockPoints &lp)
Test whether the LockPoints height and time are still valid on the current chain. ...
CMainSignals & GetMainSignals()
static const int ROLLING_FEE_HALFLIFE
CAmount nModFeesWithAncestors
std::string ToString() const
bool CalculateAncestorsAndCheckLimits(size_t entry_size, size_t entry_count, setEntries &setAncestors, CTxMemPoolEntry::Parents &staged_ancestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Helper function to calculate all in-mempool ancestors of staged_ancestors and apply ancestor and desc...
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)
void processTransaction(const CTxMemPoolEntry &entry, bool validFeeEstimate) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Process a transaction accepted to the mempool.
void ApplyDelta(const uint256 &hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
#define Assume(val)
Assume is the identity function.
const CFeeRate m_incremental_relay_feerate
int64_t ancestor_size_vbytes
The maximum allowed size in virtual bytes of an entry and its ancestors within a package.
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
bool GetLoadTried() const
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.
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
T SaturatingAdd(const T i, const T j) noexcept
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)
unsigned int nBytesPerSigOp
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...
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.
TxMempoolInfo info(const GenTxid >xid) const
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
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
void GetTransactionAncestry(const uint256 &txid, size_t &ancestors, size_t &descendants, size_t *ancestorsize=nullptr, CAmount *ancestorfees=nullptr) const
Calculate the ancestor and descendant count for the given transaction.
std::string GetHex() const
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Children
uint64_t nCountWithAncestors
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
unsigned int GetTransactionsUpdated() const
static size_t IncrementalDynamicUsage(const std::set< X, Y > &s)
static size_t RecursiveDynamicUsage(const CScript &script)
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)
Options struct containing options for constructing a CTxMemPool.
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
int64_t ancestor_count
The maximum allowed number of transactions in a package including the entry and its ancestors...
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()
DEPRECATED, see GetTime.
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
CBlockIndex * maxInputBlock
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
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 vsize of 1000 vbytes.
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
static GenTxid Txid(const uint256 &hash)
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 TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason, uint64_t mempool_sequence)