59 std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>
ret;
63 auto iter = mapNextTx.lower_bound(
COutPoint(hash, 0));
64 for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
65 ret.emplace_back(*(iter->second));
69 auto removed = std::ranges::unique(
ret, [](
auto& a,
auto& b)
noexcept {
return &a.get() == &b.get(); });
70 ret.erase(removed.begin(), removed.end());
77 std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>
ret;
78 std::set<Txid> inputs;
79 for (
const auto& txin : entry.
GetTx().
vin) {
80 inputs.insert(txin.prevout.hash);
82 for (
const auto& hash : inputs) {
83 std::optional<txiter> piter =
GetIter(hash);
85 ret.emplace_back(**piter);
97 for (
const Txid& hash : vHashesToUpdate | std::views::reverse) {
99 txiter it = mapTx.find(hash);
100 if (it == mapTx.end()) {
103 auto iter = mapNextTx.lower_bound(
COutPoint(hash, 0));
105 for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
106 txiter childIter = iter->second;
107 assert(childIter != mapTx.end());
110 m_txgraph->AddDependency(*it, *childIter);
115 auto txs_to_remove = m_txgraph->Trim();
116 for (
auto txptr : txs_to_remove) {
126 if (!entry)
return false;
134 if (ancestors.size() > 0) {
135 for (
auto ancestor : ancestors) {
136 if (ancestor != &entry) {
149 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
150 std::optional<txiter> piter =
GetIter(tx.
vin[i].prevout.hash);
152 staged_parents.insert(*piter);
156 for (
const auto& parent : staged_parents) {
158 for (
auto ancestor : parent_ancestors) {
168 opts.
check_ratio = std::clamp<int>(opts.check_ratio, 0, 1'000'000);
169 int64_t cluster_limit_bytes = opts.limits.cluster_size_vbytes * 40;
170 if (opts.max_size_bytes < 0 || (opts.max_size_bytes > 0 && opts.max_size_bytes < cluster_limit_bytes)) {
171 error =
strprintf(
_(
"-maxmempool must be at least %d MB"), std::ceil(cluster_limit_bytes / 1'000'000.0));
173 return std::move(opts);
185 return mapNextTx.count(outpoint);
201 m_txgraph->CommitStaging();
205 for (
size_t i=0; i<changeset->
m_entry_vec.size(); ++i) {
208 auto node_handle = changeset->
m_to_add.extract(tx_entry);
209 auto result = mapTx.insert(std::move(node_handle));
212 txiter it = result.position;
229 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
230 mapNextTx.insert(std::make_pair(&tx.
vin[i].prevout, newit));
241 m_total_fee += entry.
GetFee();
244 newit->idx_randomized = txns_randomized.size() - 1;
267 it->GetTx().GetHash().data(),
271 std::chrono::duration_cast<std::chrono::duration<std::uint64_t>>(it->GetTime()).count()
274 for (
const CTxIn& txin : it->GetTx().vin)
275 mapNextTx.erase(txin.prevout);
279 if (txns_randomized.size() > 1) {
281 txns_randomized[it->idx_randomized] = std::move(txns_randomized.back());
282 txns_randomized[it->idx_randomized].second->idx_randomized = it->idx_randomized;
283 txns_randomized.pop_back();
284 if (txns_randomized.size() * 2 < txns_randomized.capacity()) {
285 txns_randomized.shrink_to_fit();
288 txns_randomized.clear();
291 totalTxSize -= it->GetTxSize();
292 m_total_fee -= it->GetFee();
293 cachedInnerUsage -= it->DynamicMemoryUsage();
308 setDescendants.insert(mapTx.iterator_to(
static_cast<const CTxMemPoolEntry&
>(*tx)));
310 return mapTx.iterator_to(entry);
316 Assume(!m_have_changeset);
318 for (
auto tx: descendants) {
327 Assume(!m_have_changeset);
329 if (origit != mapTx.end()) {
337 std::vector<const TxGraph::Ref*> to_remove;
338 while (iter != mapNextTx.end() && iter->first->hash == origTx.
GetHash()) {
339 to_remove.emplace_back(&*(iter->second));
343 for (
auto ref : all_removes) {
344 auto tx = mapTx.iterator_to(
static_cast<const CTxMemPoolEntry&
>(*ref));
355 Assume(!m_have_changeset);
357 std::vector<const TxGraph::Ref*> to_remove;
358 for (
txiter it = mapTx.begin(); it != mapTx.end(); it++) {
359 if (check_final_and_mature(it)) {
360 to_remove.emplace_back(&*it);
366 for (
auto ref : all_to_remove) {
367 auto it = mapTx.iterator_to(
static_cast<const CTxMemPoolEntry&
>(*ref));
370 for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
381 auto it = mapNextTx.find(txin.
prevout);
382 if (it != mapNextTx.end()) {
397 Assume(!m_have_changeset);
398 std::vector<RemovedMempoolTransactionInfo> txs_removed_for_block;
399 if (mapTx.size() || mapNextTx.size() || mapDeltas.size()) {
400 txs_removed_for_block.reserve(vtx.size());
401 for (
const auto& tx : vtx) {
402 txiter it = mapTx.find(tx->GetHash());
403 if (it != mapTx.end()) {
404 txs_removed_for_block.emplace_back(*it);
414 lastRollingFeeUpdate =
GetTime();
415 blockSinceLastRollingFeeBump =
true;
427 LogDebug(
BCLog::MEMPOOL,
"Checking mempool with %u transactions and %u inputs\n", (
unsigned int)mapTx.size(), (
unsigned int)mapNextTx.size());
429 uint64_t checkTotal = 0;
431 CAmount check_total_modified_fee{0};
432 int64_t check_total_adjusted_weight{0};
433 uint64_t innerUsage = 0;
436 m_txgraph->SanityCheck();
444 assert(diagram.size() <= score_with_topo.size() + 1);
445 assert(diagram.size() >= 1);
447 std::optional<Wtxid> last_wtxid = std::nullopt;
448 auto diagram_iter = diagram.cbegin();
450 for (
const auto& it : score_with_topo) {
457 assert(diagram_iter->size >= check_total_adjusted_weight);
458 if (diagram_iter->fee == check_total_modified_fee &&
459 diagram_iter->size == check_total_adjusted_weight) {
462 checkTotal += it->GetTxSize();
463 check_total_adjusted_weight += it->GetAdjustedWeight();
464 check_total_fee += it->GetFee();
465 check_total_modified_fee += it->GetModifiedFee();
466 innerUsage += it->DynamicMemoryUsage();
475 std::set<CTxMemPoolEntry::CTxMemPoolEntryRef, CompareIteratorByHash> setParentCheck;
476 std::set<CTxMemPoolEntry::CTxMemPoolEntryRef, CompareIteratorByHash> setParentsStored;
479 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
480 if (it2 != mapTx.end()) {
483 setParentCheck.insert(*it2);
491 auto it3 = mapNextTx.find(txin.
prevout);
492 assert(it3 != mapNextTx.end());
494 assert(&it3->second->GetTx() == &tx);
500 setParentsStored.insert(
dynamic_cast<const CTxMemPoolEntry&
>(txentry.get()));
502 assert(setParentCheck.size() == setParentsStored.size());
503 assert(std::equal(setParentCheck.begin(), setParentCheck.end(), setParentsStored.begin(), comp));
506 std::set<CTxMemPoolEntry::CTxMemPoolEntryRef, CompareIteratorByHash> setChildrenCheck;
507 std::set<CTxMemPoolEntry::CTxMemPoolEntryRef, CompareIteratorByHash> setChildrenStored;
508 auto iter = mapNextTx.lower_bound(
COutPoint(it->GetTx().GetHash(), 0));
509 for (; iter != mapNextTx.end() && iter->first->hash == it->GetTx().GetHash(); ++iter) {
510 txiter childit = iter->second;
511 assert(childit != mapTx.end());
512 setChildrenCheck.insert(*childit);
515 setChildrenStored.insert(
dynamic_cast<const CTxMemPoolEntry&
>(txentry.get()));
517 assert(setChildrenCheck.size() == setChildrenStored.size());
518 assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(), setChildrenStored.begin(), comp));
524 for (
const auto& input: tx.
vin) mempoolDuplicate.SpendCoin(input.prevout);
525 AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
527 for (
auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) {
528 indexed_transaction_set::const_iterator it2 = it->second;
529 assert(it2 != mapTx.end());
533 assert(diagram_iter == diagram.cend());
535 assert(totalTxSize == checkTotal);
536 assert(m_total_fee == check_total_fee);
537 assert(diagram.back().fee == check_total_modified_fee);
538 assert(diagram.back().size == check_total_adjusted_weight);
539 assert(innerUsage == cachedInnerUsage);
551 if (!j.has_value())
return false;
553 if (!i.has_value())
return true;
555 return m_txgraph->CompareMainOrder(*i.value(), *j.value()) < 0;
560 std::vector<indexed_transaction_set::const_iterator> iters;
563 iters.reserve(mapTx.size());
565 for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
569 return m_txgraph->CompareMainOrder(*a, *b) < 0;
578 std::vector<CTxMemPoolEntryRef>
ret;
579 ret.reserve(mapTx.size());
581 ret.emplace_back(*it);
591 std::vector<TxMempoolInfo>
ret;
592 ret.reserve(mapTx.size());
593 for (
auto it : iters) {
603 const auto i = mapTx.find(txid);
604 return i == mapTx.end() ? nullptr : &(*i);
610 indexed_transaction_set::const_iterator i = mapTx.find(hash);
611 if (i == mapTx.end())
613 return i->GetSharedTx();
620 CAmount &delta = mapDeltas[hash];
622 txiter it = mapTx.find(hash);
623 if (it != mapTx.end()) {
626 it->UpdateModifiedFee(nFeeDelta);
627 m_txgraph->SetTransactionFee(*it, it->GetModifiedFee());
631 mapDeltas.erase(hash);
632 LogInfo(
"PrioritiseTransaction: %s (%sin mempool) delta cleared\n", hash.
ToString(), it == mapTx.end() ?
"not " :
"");
634 LogInfo(
"PrioritiseTransaction: %s (%sin mempool) fee += %s, new delta=%s\n",
636 it == mapTx.end() ?
"not " :
"",
646 std::map<Txid, CAmount>::const_iterator pos = mapDeltas.find(hash);
647 if (pos == mapDeltas.end())
649 const CAmount &delta = pos->second;
656 mapDeltas.erase(hash);
663 std::vector<delta_info> result;
664 result.reserve(mapDeltas.size());
665 for (
const auto& [txid, delta] : mapDeltas) {
666 const auto iter{mapTx.find(txid)};
667 const bool in_mempool{iter != mapTx.end()};
668 std::optional<CAmount> modified_fee;
669 if (in_mempool) modified_fee = iter->GetModifiedFee();
670 result.emplace_back(
delta_info{in_mempool, delta, modified_fee, txid});
677 const auto it = mapNextTx.find(prevout);
678 return it == mapNextTx.end() ? nullptr : &(it->second->GetTx());
684 auto it = mapTx.find(txid);
685 return it != mapTx.end() ? std::make_optional(it) : std::nullopt;
691 auto it{mapTx.project<0>(mapTx.get<
index_by_wtxid>().find(wtxid))};
692 return it != mapTx.end() ? std::make_optional(it) : std::nullopt;
698 for (
const auto& h : hashes) {
700 if (mi)
ret.insert(*mi);
708 std::vector<txiter>
ret;
709 ret.reserve(txids.size());
710 for (
const auto& txid : txids) {
720 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
741 if (outpoint.
n < ptx->vout.size()) {
753 for (
unsigned int n = 0; n < tx->vout.size(); ++n) {
773 if (m_unbroadcast_txids.erase(txid))
775 LogDebug(
BCLog::MEMPOOL,
"Removed %i from set of unbroadcast txns%s\n", txid.
GetHex(), (unchecked ?
" before confirmation that txn was sent out" :
""));
800 Assume(!m_have_changeset);
801 indexed_transaction_set::index<entry_time>::type::iterator it = mapTx.get<
entry_time>().begin();
803 while (it != mapTx.get<
entry_time>().end() && it->GetTime() < time) {
804 toremove.insert(mapTx.project<0>(it));
808 for (
txiter removeit : toremove) {
817 if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
818 return CFeeRate(llround(rollingMinimumFeeRate));
821 if (time > lastRollingFeeUpdate + 10) {
828 rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
829 lastRollingFeeUpdate = time;
832 rollingMinimumFeeRate = 0;
841 if (rate.
GetFeePerK() > rollingMinimumFeeRate) {
843 blockSinceLastRollingFeeBump =
false;
849 Assume(!m_have_changeset);
851 unsigned nTxnRemoved = 0;
855 const auto &[worst_chunk, feeperweight] = m_txgraph->GetWorstMainChunk();
865 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
867 nTxnRemoved += worst_chunk.size();
869 std::vector<CTransaction> txn;
870 if (pvNoSpendsRemaining) {
871 txn.reserve(worst_chunk.size());
872 for (
auto ref : worst_chunk) {
878 for (
auto ref : worst_chunk) {
879 stage.insert(mapTx.iterator_to(
static_cast<const CTxMemPoolEntry&
>(*ref)));
881 for (
auto e : stage) {
884 if (pvNoSpendsRemaining) {
888 pvNoSpendsRemaining->push_back(txin.
prevout);
894 if (maxFeeRateRemoved >
CFeeRate(0)) {
903 size_t ancestor_count = ancestors.size();
904 size_t ancestor_size = 0;
906 for (
auto tx: ancestors) {
911 return {ancestor_count, ancestor_size, ancestor_fees};
917 size_t descendant_count = descendants.size();
918 size_t descendant_size = 0;
921 for (
auto tx: descendants) {
926 return {descendant_count, descendant_size, descendant_fees};
931 auto it = mapTx.find(txid);
932 ancestors = cluster_count = 0;
933 if (it != mapTx.end()) {
935 ancestors = ancestor_count;
936 if (ancestorsize) *ancestorsize = ancestor_size;
937 if (ancestorfees) *ancestorfees = ancestor_fees;
951 m_load_tried = load_tried;
958 std::vector<CTxMemPool::txiter>
ret;
959 std::set<const CTxMemPoolEntry*> unique_cluster_representatives;
960 for (
auto txid : txids) {
961 auto it = mapTx.find(txid);
962 if (it != mapTx.end()) {
967 if (unique_cluster_representatives.insert(
static_cast<const CTxMemPoolEntry*
>(&(**cluster.begin()))).second) {
968 for (
auto tx : cluster) {
974 if (
ret.size() > 500) {
988 return m_pool->m_txgraph->GetMainStagingDiagrams();
994 Assume(m_to_add.find(tx->GetHash()) == m_to_add.end());
995 Assume(!m_dependencies_processed);
998 m_dependencies_processed =
false;
1001 m_pool->ApplyDelta(tx->GetHash(), delta);
1004 auto newit = m_to_add.emplace(std::move(ref), tx,
fee, time, entry_height, entry_sequence, spends_coinbase, sigops_cost,
lp).first;
1006 newit->UpdateModifiedFee(delta);
1007 m_pool->m_txgraph->SetTransactionFee(*newit, newit->GetModifiedFee());
1010 m_entry_vec.push_back(newit);
1018 m_pool->m_txgraph->RemoveTransaction(*it);
1019 m_to_remove.insert(it);
1025 if (!m_dependencies_processed) {
1026 ProcessDependencies();
1028 m_pool->Apply(
this);
1030 m_to_remove.clear();
1031 m_entry_vec.clear();
1032 m_ancestors.clear();
1038 Assume(!m_dependencies_processed);
1039 for (
const auto& entryptr : m_entry_vec) {
1040 for (
const auto &txin : entryptr->GetSharedTx()->vin) {
1041 std::optional<txiter> piter = m_pool->GetIter(txin.
prevout.
hash);
1044 if (it != m_to_add.end()) {
1045 piter = std::make_optional(it);
1049 m_pool->m_txgraph->AddDependency(**piter, *entryptr);
1053 m_dependencies_processed =
true;
1060 if (!m_dependencies_processed) {
1061 ProcessDependencies();
1070 std::vector<FeePerWeight>
ret;
1072 ret.emplace_back(zero);
1076 std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef> dummy;
1080 last_selection +=
ret.back();
1081 ret.emplace_back(last_selection);
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assume(val)
Assume is the identity function.
An in-memory indexed chain of blocks.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
CCoinsView backed by another CCoinsView.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Abstract view on the open txout dataset.
virtual std::optional< Coin > GetCoin(const COutPoint &outpoint) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
GetCoin, returning whether it exists and is not spent.
void Reset()
Clear m_temp_added and m_non_base_coins.
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
std::unordered_set< COutPoint, SaltedOutpointHasher > m_non_base_coins
Set of all coins that have been fetched from mempool or created using PackageAddTransaction (not base...
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
const CTxMemPool & mempool
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
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 Wtxid & GetWitnessHash() const LIFETIMEBOUND
const Txid & GetHash() const LIFETIMEBOUND
const std::vector< CTxIn > vin
An input of a transaction.
CTxMemPool::setEntries m_to_remove
void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
void StageRemoval(CTxMemPool::txiter it)
util::Result< std::pair< std::vector< FeeFrac >, std::vector< FeeFrac > > > CalculateChunksForRBF()
Calculate the sorted chunks for the old and new mempool relating to the clusters that would be affect...
CTxMemPool::txiter TxHandle
CTxMemPool::indexed_transaction_set m_to_add
TxHandle StageAddition(const CTransactionRef &tx, CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
bool CheckMemPoolPolicyLimits()
Check if any cluster limits are exceeded.
void ProcessDependencies()
std::vector< CTxMemPool::txiter > m_entry_vec
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
const CTransaction & GetTx() const
size_t DynamicMemoryUsage() const
int32_t GetTxSize() const
const CAmount & GetFee() const
CAmount GetModifiedFee() const
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 Apply(CTxMemPool::ChangeSet *changeset) EXCLUSIVE_LOCKS_REQUIRED(cs)
void PrioritiseTransaction(const Txid &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
std::unique_ptr< ChangeSet > GetChangeSet() EXCLUSIVE_LOCKS_REQUIRED(cs)
bool CompareMiningScoreWithTopology(const Wtxid &hasha, const Wtxid &hashb) const
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
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...
setEntries GetIterSet(const std::set< Txid > &hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Translate a set of hashes into a set of pool iterators to avoid repeated lookups.
void ClearPrioritisation(const Txid &hash) EXCLUSIVE_LOCKS_REQUIRED(cs)
std::optional< txiter > GetIter(const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
bool GetLoadTried() const
void StopBlockBuilding() const EXCLUSIVE_LOCKS_REQUIRED(cs)
CFeeRate GetMinFee() const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
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 GetTransactionAncestry(const Txid &txid, size_t &ancestors, size_t &cluster_count, size_t *ancestorsize=nullptr, CAmount *ancestorfees=nullptr) const
Calculate the ancestor and cluster count for the given transaction.
void UpdateTransactionsFromBlock(const std::vector< Txid > &vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs
UpdateTransactionsFromBlock is called when adding transactions from a disconnected block back to the ...
void AddTransactionsUpdated(unsigned int n)
bool HasDescendants(const Txid &txid) const
std::vector< indexed_transaction_set::const_iterator > GetSortedScoreWithTopology() const EXCLUSIVE_LOCKS_REQUIRED(cs)
void StartBlockBuilding() const EXCLUSIVE_LOCKS_REQUIRED(cs)
CTransactionRef get(const Txid &hash) const
size_t DynamicMemoryUsage() const
std::vector< TxMempoolInfo > infoAll() const
CTxMemPool(Options opts, bilingual_str &error)
Create a new CTxMemPool.
void addNewTransaction(CTxMemPool::txiter it) EXCLUSIVE_LOCKS_REQUIRED(cs)
void removeUnchecked(txiter entry, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
Expire all transaction (and their dependencies) in the mempool older than time.
void IncludeBuilderChunk() const EXCLUSIVE_LOCKS_REQUIRED(cs)
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...
std::vector< FeePerWeight > GetFeerateDiagram() const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::tuple< size_t, size_t, CAmount > CalculateDescendantData(const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
bool exists(const Txid &txid) const
std::vector< txiter > GetIterVec(const std::vector< Txid > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Translate a list of hashes into a list of mempool iterators to avoid repeated lookups.
static const int ROLLING_FEE_HALFLIFE
std::set< txiter, CompareIteratorByHash > setEntries
std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > GetParents(const CTxMemPoolEntry &entry) const
void ApplyDelta(const Txid &hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
std::vector< delta_info > GetPrioritisedTransactions() const EXCLUSIVE_LOCKS_REQUIRED(!cs)
Return a vector of all entries in mapDeltas with their corresponding delta_info.
std::vector< txiter > GatherClusters(const std::vector< Txid > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Collect the entire cluster of connected transactions for each transaction in txids.
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.
bool CheckPolicyLimits(const CTransactionRef &tx)
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of given transaction.
std::tuple< size_t, size_t, CAmount > CalculateAncestorData(const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > GetChildren(const CTxMemPoolEntry &entry) const
setEntries CalculateMemPoolAncestors(const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Calculate all in-mempool ancestors of entry (not including the tx itself)
void RemoveUnbroadcastTx(const Txid &txid, bool unchecked=false)
Removes a transaction from the unbroadcast set.
void SetLoadTried(bool load_tried)
Set whether or not an initial attempt to load the persisted mempool was made (regardless of whether t...
void RemoveStaged(setEntries &stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
std::vector< CTxMemPoolEntryRef > entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs)
bool isSpent(const COutPoint &outpoint) const
FeePerWeight GetBlockBuilderChunk(std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > &entries) const EXCLUSIVE_LOCKS_REQUIRED(cs)
const CTxMemPoolEntry * GetEntry(const Txid &txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs)
unsigned int GetTransactionsUpdated() const
@ MAIN
Always refers to the main graph, whether staging is present or not.
@ TOP
Refers to staging if it exists, main otherwise.
void MempoolTransactionsRemovedForBlock(const std::vector< RemovedMempoolTransactionInfo > &, unsigned int nBlockHeight)
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason, uint64_t mempool_sequence)
std::string ToString() const
std::string GetHex() const
constexpr const std::byte * data() 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 int32_t GetTransactionWeight(const CTransaction &tx)
static const int WITNESS_SCALE_FACTOR
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
#define LogDebug(category,...)
std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept
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.
@ REPLACED
Removed for replacement.
@ CONFLICT
Removed for conflict with in-block transaction.
@ REORG
Removed for reorganization.
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 MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
T SaturatingAdd(const T i, const T j) noexcept
unsigned int nBytesPerSigOp
int64_t GetSigOpsAdjustedWeight(int64_t weight, int64_t sigop_cost, unsigned int bytes_per_sigop)
static FeePerVSize ToFeePerVSize(FeePerWeight feerate)
std::shared_ptr< const CTransaction > CTransactionRef
CBlockIndex * maxInputBlock
unsigned cluster_count
The maximum number of transactions in a cluster.
int64_t cluster_size_vbytes
The maximum allowed size in virtual bytes of a cluster.
Options struct containing options for constructing a CTxMemPool.
ValidationSignals * signals
CFeeRate incremental_relay_feerate
#define AssertLockNotHeld(cs)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
#define TRACEPOINT(context,...)
consteval auto _(util::TranslatedLiteral str)
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
std::unique_ptr< TxGraph > MakeTxGraph(unsigned max_cluster_count, uint64_t max_cluster_size, uint64_t acceptable_iters) noexcept
Construct a new TxGraph with the specified limit on the number of transactions within a cluster,...
static CTxMemPool::Options && Flatten(CTxMemPool::Options &&opts, bilingual_str &error)
TRACEPOINT_SEMAPHORE(mempool, added)
bool TestLockPointValidity(CChain &active_chain, const LockPoints &lp)
Test whether the LockPoints height and time are still valid on the current chain.
static constexpr uint64_t ACCEPTABLE_ITERS
How many linearization iterations required for TxGraph clusters to have "acceptable" quality,...
static constexpr uint64_t POST_CHANGE_WORK
How much work we ask TxGraph to do after a mempool change occurs (either due to a changeset being app...
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 GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.