23 int64_t _nTime,
unsigned int _entryHeight,
24 bool _spendsCoinbase, int64_t _sigOpsCost,
LockPoints lp)
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;
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;
int64_t CAmount
Amount in satoshis (Can be negative)
static const unsigned char k1[32]
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
bool removeTx(uint256 hash, bool inBlock)
Remove a transaction from the mempool tracking stats.
void processTransaction(const CTxMemPoolEntry &entry, bool validFeeEstimate)
Process a transaction accepted to the mempool.
void processBlock(unsigned int nBlockHeight, std::vector< const CTxMemPoolEntry * > &entries)
Process all the transactions that have been included in a block.
CCoinsView backed by another CCoinsView.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Abstract view on the open txout dataset.
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
const CTxMemPool & mempool
Fee rate in satoshis per kilobyte: CAmount / kB.
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason, uint64_t mempool_sequence)
An outpoint - a combination of a transaction hash and an index n into its vout.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
const uint256 & GetHash() const
const std::vector< CTxIn > vin
const uint256 & GetWitnessHash() const
An input of a transaction.
EpochGuard: RAII-style guard for using epoch-based graph traversal algorithms.
EpochGuard(const CTxMemPool &in)
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
const int64_t sigOpCost
Total sigop cost.
CTxMemPoolEntry(const CTransactionRef &_tx, const CAmount &_nFee, int64_t _nTime, unsigned int _entryHeight, bool spendsCoinbase, int64_t nSigOpsCost, LockPoints lp)
void UpdateFeeDelta(int64_t feeDelta)
const size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
int64_t nSigOpCostWithAncestors
const CTransaction & GetTx() const
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
void UpdateLockPoints(const LockPoints &lp)
CAmount nModFeesWithAncestors
uint64_t nCountWithDescendants
number of descendant transactions
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
uint64_t nSizeWithDescendants
... and size
size_t DynamicMemoryUsage() const
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Children
CAmount nModFeesWithDescendants
... and total fees (all including us)
uint64_t nCountWithAncestors
const CAmount nFee
Cached to avoid expensive parent-transaction lookups.
LockPoints lockPoints
Track the height and time at which tx was final.
uint64_t nSizeWithAncestors
const Children & GetMemPoolChildrenConst() const
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Parents
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
CTxMemPool(CBlockPolicyEstimator *estimator=nullptr)
Create a new CTxMemPool.
std::atomic< unsigned int > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
void GetTransactionAncestry(const uint256 &txid, size_t &ancestors, size_t &descendants) const
Calculate the ancestor and descendant count for the given transaction.
void RemoveUnbroadcastTx(const uint256 &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
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...
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 UpdateEntryForAncestors(txiter it, const setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Set ancestor state for an entry.
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
void ClearPrioritisation(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs)
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
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 removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
void addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs
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.
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 AddTransactionsUpdated(unsigned int n)
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
CTransactionRef get(const uint256 &hash) const
size_t DynamicMemoryUsage() const
std::vector< TxMempoolInfo > infoAll() const
void SetIsLoaded(bool loaded)
Sets the current loaded state.
int64_t lastRollingFeeUpdate
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
std::map< uint256, CAmount > mapDeltas
void removeUnchecked(txiter entry, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Before calling removeUnchecked for a given transaction, UpdateForRemoveFromMempool must be called on ...
int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
Expire all transaction (and their dependencies) in the mempool older than time.
txiter get_iter_from_wtxid(const uint256 &wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Update ancestors of hash to add/remove it as a descendant transaction.
void ApplyDelta(const uint256 &hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Optional< txiter > GetIter(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
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.
static const int ROLLING_FEE_HALFLIFE
std::set< txiter, CompareIteratorByHash > setEntries
std::vector< indexed_transaction_set::const_iterator > GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs)
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
void queryHashes(std::vector< uint256 > &vtxid) const
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
EpochGuard GetFreshEpoch() const EXCLUSIVE_LOCKS_REQUIRED(cs)
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
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 exists(const GenTxid >xid) const
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
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...
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.
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
uint64_t totalTxSize
sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discount...
TxMempoolInfo info(const uint256 &hash) const
bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb, bool wtxid=false)
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants) EXCLUSIVE_LOCKS_REQUIRED(cs)
For each transaction being removed, update ancestors and any direct children.
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
bool blockSinceLastRollingFeeBump
bool isSpent(const COutPoint &outpoint) const
CBlockPolicyEstimator * minerPolicyEstimator
unsigned int GetTransactionsUpdated() const
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Sort by feerate of entry (fee/size) in descending order This is only used for transaction relay,...
A generic txid reference (txid or wtxid).
const uint256 & GetHash() const
std::string ToString() const
std::string GetHex() const
static int64_t GetTransactionWeight(const CTransaction &tx)
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
static size_t RecursiveDynamicUsage(const CScript &script)
static void LogPrintf(const char *fmt, const Args &... args)
#define LogPrint(category,...)
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
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...
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
static size_t IncrementalDynamicUsage(const std::set< X, Y > &s)
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
std::deque< CInv >::iterator it
boost::optional< T > Optional
Substitute for C++17 std::optional.
CFeeRate incrementalRelayFee
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
std::shared_ptr< const CTransaction > CTransactionRef
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
reverse_range< T > reverse_iterate(T &x)
Information about a mempool transaction.
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
static void CheckInputsAndUpdateCoins(const CTransaction &tx, CCoinsViewCache &mempoolDuplicate, const int64_t spendheight)
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
@ SIZELIMIT
Removed in size limiting.
@ BLOCK
Removed for block.
@ EXPIRY
Expired from mempool.
@ CONFLICT
Removed for conflict with in-block transaction.
@ REORG
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....
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain.
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight)
bool CheckFinalTx(const CTransaction &tx, int flags)
Transaction validation functions.
AssertLockHeld(mempool.cs)
bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
int GetSpendHeight(const CCoinsViewCache &inputs)
Return the spend height, which is one more than the inputs.GetBestBlock().
CMainSignals & GetMainSignals()