78 int64_t time,
unsigned int entry_height,
79 bool spends_coinbase, int64_t sigops_cost,
LockPoints lp)
85 entryHeight{entry_height},
89 nSizeWithDescendants{GetTxSize()},
90 nModFeesWithDescendants{nFee},
91 nSizeWithAncestors{GetTxSize()},
92 nModFeesWithAncestors{nFee},
118 stageEntries = updateIt->GetMemPoolChildrenConst();
120 while (!stageEntries.empty()) {
122 descendants.insert(descendant);
123 stageEntries.erase(descendant);
126 cacheMap::iterator cacheIt = cachedDescendants.find(mapTx.iterator_to(childEntry));
127 if (cacheIt != cachedDescendants.end()) {
130 for (
txiter cacheEntry : cacheIt->second) {
131 descendants.insert(*cacheEntry);
133 }
else if (!descendants.count(childEntry)) {
135 stageEntries.insert(childEntry);
141 int64_t modifySize = 0;
143 int64_t modifyCount = 0;
145 if (!setExclude.count(descendant.GetTx().GetHash())) {
146 modifySize += descendant.GetTxSize();
147 modifyFee += descendant.GetModifiedFee();
149 cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
151 mapTx.modify(mapTx.iterator_to(descendant),
update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()));
168 cacheMap mapMemPoolDescendantsToUpdate;
172 std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
182 if (
it == mapTx.end()) {
185 auto iter = mapNextTx.lower_bound(
COutPoint(hash, 0));
191 for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
192 const uint256 &childHash = iter->second->GetHash();
193 txiter childIter = mapTx.find(childHash);
194 assert(childIter != mapTx.end());
197 if (!
visited(childIter) && !setAlreadyIncluded.count(childHash)) {
211 uint64_t limitAncestorCount,
212 uint64_t limitAncestorSize,
213 uint64_t limitDescendantCount,
214 uint64_t limitDescendantSize,
215 std::string &errString)
const
217 size_t totalSizeWithAncestors = entry_size;
219 while (!staged_ancestors.empty()) {
221 txiter stageit = mapTx.iterator_to(stage);
223 setAncestors.insert(stageit);
224 staged_ancestors.erase(stage);
225 totalSizeWithAncestors += stageit->
GetTxSize();
227 if (stageit->GetSizeWithDescendants() + entry_size > limitDescendantSize) {
228 errString =
strprintf(
"exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
230 }
else if (stageit->GetCountWithDescendants() + entry_count > limitDescendantCount) {
231 errString =
strprintf(
"too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
233 }
else if (totalSizeWithAncestors > limitAncestorSize) {
234 errString =
strprintf(
"exceeds ancestor size limit [limit: %u]", limitAncestorSize);
240 txiter parent_it = mapTx.iterator_to(parent);
243 if (setAncestors.count(parent_it) == 0) {
244 staged_ancestors.insert(parent);
246 if (staged_ancestors.size() + setAncestors.size() + entry_count > limitAncestorCount) {
247 errString =
strprintf(
"too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
257 uint64_t limitAncestorCount,
258 uint64_t limitAncestorSize,
259 uint64_t limitDescendantCount,
260 uint64_t limitDescendantSize,
261 std::string &errString)
const
264 size_t total_size = 0;
265 for (
const auto& tx : package) {
267 for (
const auto& input : tx->vin) {
268 std::optional<txiter> piter =
GetIter(input.prevout.hash);
270 staged_ancestors.insert(**piter);
271 if (staged_ancestors.size() + package.size() > limitAncestorCount) {
272 errString =
strprintf(
"too many unconfirmed parents [limit: %u]", limitAncestorCount);
283 setAncestors, staged_ancestors,
284 limitAncestorCount, limitAncestorSize,
285 limitDescendantCount, limitDescendantSize, errString);
287 if (!ret) errString.insert(0,
"possibly ");
293 uint64_t limitAncestorCount,
294 uint64_t limitAncestorSize,
295 uint64_t limitDescendantCount,
296 uint64_t limitDescendantSize,
297 std::string &errString,
298 bool fSearchForParents )
const
303 if (fSearchForParents) {
307 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
308 std::optional<txiter> piter =
GetIter(tx.
vin[i].prevout.hash);
310 staged_ancestors.insert(**piter);
311 if (staged_ancestors.size() + 1 > limitAncestorCount) {
312 errString =
strprintf(
"too many unconfirmed parents [limit: %u]", limitAncestorCount);
320 txiter it = mapTx.iterator_to(entry);
321 staged_ancestors =
it->GetMemPoolParentsConst();
325 setAncestors, staged_ancestors,
326 limitAncestorCount, limitAncestorSize,
327 limitDescendantCount, limitDescendantSize, errString);
337 const int64_t updateCount = (add ? 1 : -1);
338 const int64_t updateSize = updateCount *
it->GetTxSize();
339 const CAmount updateFee = updateCount *
it->GetModifiedFee();
340 for (
txiter ancestorIt : setAncestors) {
347 int64_t updateCount = setAncestors.size();
348 int64_t updateSize = 0;
350 int64_t updateSigOpsCost = 0;
351 for (
txiter ancestorIt : setAncestors) {
352 updateSize += ancestorIt->GetTxSize();
353 updateFee += ancestorIt->GetModifiedFee();
354 updateSigOpsCost += ancestorIt->GetSigOpCost();
371 const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
372 if (updateDescendants) {
379 for (
txiter removeIt : entriesToRemove) {
382 setDescendants.erase(removeIt);
383 int64_t modifySize = -((int64_t)removeIt->GetTxSize());
384 CAmount modifyFee = -removeIt->GetModifiedFee();
385 int modifySigOps = -removeIt->GetSigOpCost();
386 for (
txiter dit : setDescendants) {
391 for (
txiter removeIt : entriesToRemove) {
422 for (
txiter removeIt : entriesToRemove) {
448 : m_check_ratio(check_ratio), minerPolicyEstimator(estimator)
456 return mapNextTx.count(outpoint);
474 indexed_transaction_set::iterator newit = mapTx.insert(entry).first;
491 std::set<uint256> setParentTransactions;
492 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
493 mapNextTx.insert(std::make_pair(&tx.
vin[i].prevout, &tx));
494 setParentTransactions.insert(tx.
vin[i].prevout.hash);
504 for (
const auto& pit :
GetIterSet(setParentTransactions)) {
512 m_total_fee += entry.
GetFee();
518 newit->vTxHashesIdx = vTxHashes.size() - 1;
535 const uint256 hash =
it->GetTx().GetHash();
536 for (
const CTxIn& txin :
it->GetTx().vin)
537 mapNextTx.erase(txin.prevout);
541 if (vTxHashes.size() > 1) {
542 vTxHashes[
it->vTxHashesIdx] = std::move(vTxHashes.back());
543 vTxHashes[
it->vTxHashesIdx].second->vTxHashesIdx =
it->vTxHashesIdx;
544 vTxHashes.pop_back();
545 if (vTxHashes.size() * 2 < vTxHashes.capacity())
546 vTxHashes.shrink_to_fit();
550 totalTxSize -=
it->GetTxSize();
551 m_total_fee -=
it->GetFee();
552 cachedInnerUsage -=
it->DynamicMemoryUsage();
568 if (setDescendants.count(entryit) == 0) {
569 stage.insert(entryit);
574 while (!stage.empty()) {
576 setDescendants.insert(
it);
581 txiter childiter = mapTx.iterator_to(child);
582 if (!setDescendants.count(childiter)) {
583 stage.insert(childiter);
595 if (origit != mapTx.end()) {
596 txToRemove.insert(origit);
602 for (
unsigned int i = 0; i < origTx.
vout.size(); i++) {
604 if (
it == mapNextTx.end())
606 txiter nextit = mapTx.find(
it->second->GetHash());
607 assert(nextit != mapTx.end());
608 txToRemove.insert(nextit);
624 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
633 txToRemove.insert(
it);
634 }
else if (
it->GetSpendsCoinbase()) {
636 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
637 if (it2 != mapTx.end())
643 txToRemove.insert(
it);
665 if (
it != mapNextTx.end()) {
667 if (txConflict != tx)
682 std::vector<const CTxMemPoolEntry*> entries;
683 for (
const auto& tx : vtx)
687 indexed_transaction_set::iterator i = mapTx.find(hash);
688 if (i != mapTx.end())
689 entries.push_back(&*i);
693 for (
const auto& tx : vtx)
696 if (
it != mapTx.end()) {
704 lastRollingFeeUpdate =
GetTime();
705 blockSinceLastRollingFeeBump =
true;
714 cachedInnerUsage = 0;
715 lastRollingFeeUpdate =
GetTime();
716 blockSinceLastRollingFeeBump =
false;
717 rollingMinimumFeeRate = 0;
727void CTxMemPool::check(
const CCoinsViewCache& active_coins_tip, int64_t spendheight)
const
735 LogPrint(
BCLog::MEMPOOL,
"Checking mempool with %u transactions and %u inputs\n", (
unsigned int)mapTx.size(), (
unsigned int)mapNextTx.size());
737 uint64_t checkTotal = 0;
739 uint64_t innerUsage = 0;
740 uint64_t prev_ancestor_count{0};
745 checkTotal +=
it->GetTxSize();
746 check_total_fee +=
it->GetFee();
747 innerUsage +=
it->DynamicMemoryUsage();
753 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
754 if (it2 != mapTx.end()) {
757 setParentCheck.insert(*it2);
764 auto it3 = mapNextTx.find(txin.
prevout);
765 assert(it3 != mapNextTx.end());
767 assert(it3->second == &tx);
772 assert(setParentCheck.size() ==
it->GetMemPoolParentsConst().size());
773 assert(std::equal(setParentCheck.begin(), setParentCheck.end(),
it->GetMemPoolParentsConst().begin(), comp));
776 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
779 uint64_t nCountCheck = setAncestors.size() + 1;
780 uint64_t nSizeCheck =
it->GetTxSize();
781 CAmount nFeesCheck =
it->GetModifiedFee();
782 int64_t nSigOpCheck =
it->GetSigOpCost();
784 for (
txiter ancestorIt : setAncestors) {
785 nSizeCheck += ancestorIt->GetTxSize();
786 nFeesCheck += ancestorIt->GetModifiedFee();
787 nSigOpCheck += ancestorIt->GetSigOpCost();
790 assert(
it->GetCountWithAncestors() == nCountCheck);
791 assert(
it->GetSizeWithAncestors() == nSizeCheck);
792 assert(
it->GetSigOpCostWithAncestors() == nSigOpCheck);
793 assert(
it->GetModFeesWithAncestors() == nFeesCheck);
795 assert(prev_ancestor_count <= it->GetCountWithAncestors());
796 prev_ancestor_count =
it->GetCountWithAncestors();
800 auto iter = mapNextTx.lower_bound(
COutPoint(
it->GetTx().GetHash(), 0));
801 uint64_t child_sizes = 0;
802 for (; iter != mapNextTx.end() && iter->first->hash ==
it->GetTx().GetHash(); ++iter) {
803 txiter childit = mapTx.find(iter->second->GetHash());
804 assert(childit != mapTx.end());
805 if (setChildrenCheck.insert(*childit).second) {
806 child_sizes += childit->GetTxSize();
809 assert(setChildrenCheck.size() ==
it->GetMemPoolChildrenConst().size());
810 assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(),
it->GetMemPoolChildrenConst().begin(), comp));
813 assert(
it->GetSizeWithDescendants() >= child_sizes +
it->GetTxSize());
819 for (
const auto& input: tx.
vin) mempoolDuplicate.SpendCoin(input.prevout);
820 AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
822 for (
auto it = mapNextTx.cbegin();
it != mapNextTx.cend();
it++) {
824 indexed_transaction_set::const_iterator it2 = mapTx.find(hash);
826 assert(it2 != mapTx.end());
830 assert(totalTxSize == checkTotal);
831 assert(m_total_fee == check_total_fee);
832 assert(innerUsage == cachedInnerUsage);
838 indexed_transaction_set::const_iterator i = wtxid ?
get_iter_from_wtxid(hasha) : mapTx.find(hasha);
839 if (i == mapTx.end())
return false;
840 indexed_transaction_set::const_iterator j = wtxid ?
get_iter_from_wtxid(hashb) : mapTx.find(hashb);
841 if (j == mapTx.end())
return true;
842 uint64_t counta = i->GetCountWithAncestors();
843 uint64_t countb = j->GetCountWithAncestors();
844 if (counta == countb) {
847 return counta < countb;
851class DepthAndScoreComparator
854 bool operator()(
const CTxMemPool::indexed_transaction_set::const_iterator& a,
const CTxMemPool::indexed_transaction_set::const_iterator& b)
856 uint64_t counta = a->GetCountWithAncestors();
857 uint64_t countb = b->GetCountWithAncestors();
858 if (counta == countb) {
861 return counta < countb;
868 std::vector<indexed_transaction_set::const_iterator> iters;
871 iters.reserve(mapTx.size());
873 for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
876 std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
886 vtxid.reserve(mapTx.size());
888 for (
auto it : iters) {
889 vtxid.push_back(
it->GetTx().GetHash());
894 return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
902 std::vector<TxMempoolInfo> ret;
903 ret.reserve(mapTx.size());
904 for (
auto it : iters) {
914 indexed_transaction_set::const_iterator i = mapTx.find(hash);
915 if (i == mapTx.end())
917 return i->GetSharedTx();
924 if (i == mapTx.end())
933 CAmount &delta = mapDeltas[hash];
936 if (
it != mapTx.end()) {
940 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
943 for (
txiter ancestorIt : setAncestors) {
949 setDescendants.erase(
it);
950 for (
txiter descendantIt : setDescendants) {
962 std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
963 if (pos == mapDeltas.end())
965 const CAmount &delta = pos->second;
972 mapDeltas.erase(hash);
977 const auto it = mapNextTx.find(prevout);
978 return it == mapNextTx.end() ? nullptr :
it->second;
983 auto it = mapTx.find(txid);
984 if (
it != mapTx.end())
return it;
991 for (
const auto& h : hashes) {
993 if (mi) ret.insert(*mi);
1000 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
1021 if (outpoint.
n < ptx->vout.size()) {
1033 for (
unsigned int n = 0; n < tx->vout.size(); ++n) {
1047 if (m_unbroadcast_txids.erase(txid))
1049 LogPrint(
BCLog::MEMPOOL,
"Removed %i from set of unbroadcast txns%s\n", txid.
GetHex(), (unchecked ?
" before confirmation that txn was sent out" :
""));
1064 indexed_transaction_set::index<entry_time>::type::iterator
it = mapTx.get<
entry_time>().begin();
1066 while (
it != mapTx.get<
entry_time>().end() &&
it->GetTime() < time) {
1067 toremove.insert(mapTx.project<0>(
it));
1071 for (
txiter removeit : toremove) {
1075 return stage.size();
1081 uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
1084 return addUnchecked(entry, setAncestors, validFeeEstimate);
1091 if (add && entry->GetMemPoolChildren().insert(*child).second) {
1093 }
else if (!add && entry->GetMemPoolChildren().erase(*child)) {
1102 if (add && entry->GetMemPoolParents().insert(*parent).second) {
1104 }
else if (!add && entry->GetMemPoolParents().erase(*parent)) {
1111 if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
1112 return CFeeRate(llround(rollingMinimumFeeRate));
1115 if (time > lastRollingFeeUpdate + 10) {
1122 rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
1123 lastRollingFeeUpdate = time;
1126 rollingMinimumFeeRate = 0;
1135 if (rate.
GetFeePerK() > rollingMinimumFeeRate) {
1137 blockSinceLastRollingFeeBump =
false;
1144 unsigned nTxnRemoved = 0;
1147 indexed_transaction_set::index<descendant_score>::type::iterator
it = mapTx.get<
descendant_score>().begin();
1153 CFeeRate removed(
it->GetModFeesWithDescendants(),
it->GetSizeWithDescendants());
1156 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1160 nTxnRemoved += stage.size();
1162 std::vector<CTransaction> txn;
1163 if (pvNoSpendsRemaining) {
1164 txn.reserve(stage.size());
1165 for (
txiter iter : stage)
1166 txn.push_back(iter->GetTx());
1169 if (pvNoSpendsRemaining) {
1173 pvNoSpendsRemaining->push_back(txin.
prevout);
1179 if (maxFeeRateRemoved >
CFeeRate(0)) {
1186 std::vector<txiter> candidates;
1188 candidates.push_back(entry);
1189 uint64_t maximum = 0;
1190 while (candidates.size()) {
1191 txiter candidate = candidates.back();
1192 candidates.pop_back();
1193 if (!counted.insert(candidate).second)
continue;
1195 if (parents.size() == 0) {
1196 maximum = std::max(maximum, candidate->GetCountWithDescendants());
1199 candidates.push_back(mapTx.iterator_to(i));
1208 auto it = mapTx.find(txid);
1209 ancestors = descendants = 0;
1210 if (
it != mapTx.end()) {
1211 ancestors =
it->GetCountWithAncestors();
1212 if (ancestorsize) *ancestorsize =
it->GetSizeWithAncestors();
1213 if (ancestorfees) *ancestorfees =
it->GetModFeesWithAncestors();
1227 m_is_loaded = loaded;
int64_t CAmount
Amount in satoshis (Can be negative)
int nHeight
height of the entry in the chain. The genesis block has height 0
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.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
CChainState stores and provides an API to update our local knowledge of the current best chain.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
CChain m_chain
The current chain of blockheaders we consult and build on.
CCoinsView backed by another CCoinsView.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
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.
CCoinsView that brings transactions from a mempool into view.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
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 uint256 & GetWitnessHash() const
const uint256 & GetHash() const
const std::vector< CTxOut > vout
const std::vector< CTxIn > vin
An input of a transaction.
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
CTxMemPoolEntry(const CTransactionRef &tx, CAmount fee, int64_t time, unsigned int entry_height, bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
const int64_t sigOpCost
Total sigop cost.
void UpdateFeeDelta(int64_t feeDelta)
const size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
int64_t nSigOpCostWithAncestors
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
const CTransaction & GetTx() const
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
void UpdateLockPoints(const LockPoints &lp)
CAmount nModFeesWithAncestors
const Children & GetMemPoolChildrenConst() const
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 & GetFee() const
LockPoints lockPoints
Track the height and time at which tx was final.
uint64_t nSizeWithAncestors
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)
std::atomic< unsigned int > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
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...
void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Set ancestor state for an entry.
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...
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 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 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.
void removeForReorg(CChainState &active_chainstate, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs
std::optional< txiter > GetIter(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
CTransactionRef get(const uint256 &hash) const
size_t DynamicMemoryUsage() const
std::vector< TxMempoolInfo > infoAll() const
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.
void SetIsLoaded(bool loaded)
Sets the current loaded state.
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
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.
CBlockPolicyEstimator *const minerPolicyEstimator
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...
TxMempoolInfo info(const GenTxid >xid) const
void ApplyDelta(const uint256 &hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
CTxMemPool(CBlockPolicyEstimator *estimator=nullptr, int check_ratio=0)
Create a new CTxMemPool.
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
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.
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
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.
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 check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants) EXCLUSIVE_LOCKS_REQUIRED(cs)
For each transaction being removed, update ancestors and any direct children.
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...
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
bool isSpent(const COutPoint &outpoint) const
unsigned int GetTransactionsUpdated() const
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
bool IsSpent() const
Either this coin never existed (see e.g.
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
static GenTxid Txid(const uint256 &hash)
std::string ToString() const
std::string GetHex() const
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.
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)
#define WITH_FRESH_EPOCH(epoch)
#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::vector< CTransactionRef > Package
A package is an ordered list of transactions.
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.
void operator()(CTxMemPoolEntry &e)
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost)
void operator()(CTxMemPoolEntry &e)
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
update_fee_delta(int64_t _feeDelta)
void operator()(CTxMemPoolEntry &e)
void operator()(CTxMemPoolEntry &e)
update_lock_points(const LockPoints &_lp)
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
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 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.
bool CheckFinalTx(const CBlockIndex *active_chain_tip, const CTransaction &tx, int flags)
Transaction validation functions.
bool TestLockPointValidity(CChain &active_chain, const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain.
CMainSignals & GetMainSignals()