60 std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>
ret;
63 for (; iter != mapNextTx.end() && iter->first->hash == entry.
GetTx().
GetHash(); ++iter) {
65 ret.emplace_back(*(iter->second));
74 std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>
ret;
75 std::set<Txid> inputs;
76 for (
const auto& txin : entry.
GetTx().
vin) {
77 inputs.insert(txin.prevout.hash);
79 for (
const auto& hash : inputs) {
80 std::optional<txiter> piter =
GetIter(hash);
82 ret.emplace_back(**piter);
94 for (
const Txid& hash : vHashesToUpdate | std::views::reverse) {
97 if (
it == mapTx.end()) {
100 auto iter = mapNextTx.lower_bound(
COutPoint(hash, 0));
102 for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
103 txiter childIter = iter->second;
104 assert(childIter != mapTx.end());
107 m_txgraph->AddDependency(*
it, *childIter);
112 auto txs_to_remove = m_txgraph->Trim();
113 for (
auto txptr : txs_to_remove) {
123 if (!entry)
return false;
131 if (ancestors.size() > 0) {
132 for (
auto ancestor : ancestors) {
133 if (ancestor != &entry) {
146 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
147 std::optional<txiter> piter =
GetIter(tx.
vin[i].prevout.hash);
149 staged_parents.insert(*piter);
153 for (
const auto& parent : staged_parents) {
155 for (
auto ancestor : parent_ancestors) {
165 opts.
check_ratio = std::clamp<int>(opts.check_ratio, 0, 1'000'000);
166 int64_t cluster_limit_bytes = opts.limits.cluster_size_vbytes * 40;
167 if (opts.max_size_bytes < 0 || (opts.max_size_bytes > 0 && opts.max_size_bytes < cluster_limit_bytes)) {
168 error =
strprintf(
_(
"-maxmempool must be at least %d MB"), std::ceil(cluster_limit_bytes / 1'000'000.0));
170 return std::move(opts);
182 return mapNextTx.count(outpoint);
198 m_txgraph->CommitStaging();
202 for (
size_t i=0; i<changeset->
m_entry_vec.size(); ++i) {
205 auto node_handle = changeset->
m_to_add.extract(tx_entry);
206 auto result = mapTx.insert(std::move(node_handle));
226 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
227 mapNextTx.insert(std::make_pair(&tx.
vin[i].prevout, newit));
238 m_total_fee += entry.
GetFee();
241 newit->idx_randomized = txns_randomized.size() - 1;
264 it->GetTx().GetHash().data(),
268 std::chrono::duration_cast<std::chrono::duration<std::uint64_t>>(
it->GetTime()).count()
271 for (
const CTxIn& txin :
it->GetTx().vin)
272 mapNextTx.erase(txin.prevout);
276 if (txns_randomized.size() > 1) {
278 txns_randomized[
it->idx_randomized] = std::move(txns_randomized.back());
279 txns_randomized[
it->idx_randomized].second->idx_randomized =
it->idx_randomized;
280 txns_randomized.pop_back();
281 if (txns_randomized.size() * 2 < txns_randomized.capacity()) {
282 txns_randomized.shrink_to_fit();
285 txns_randomized.clear();
288 totalTxSize -=
it->GetTxSize();
289 m_total_fee -=
it->GetFee();
290 cachedInnerUsage -=
it->DynamicMemoryUsage();
305 setDescendants.insert(mapTx.iterator_to(
static_cast<const CTxMemPoolEntry&
>(*tx)));
307 return mapTx.iterator_to(entry);
313 Assume(!m_have_changeset);
315 for (
auto tx: descendants) {
324 Assume(!m_have_changeset);
326 if (origit != mapTx.end()) {
334 std::vector<const TxGraph::Ref*> to_remove;
335 while (iter != mapNextTx.end() && iter->first->hash == origTx.
GetHash()) {
336 to_remove.emplace_back(&*(iter->second));
340 for (
auto ref : all_removes) {
341 auto tx = mapTx.iterator_to(
static_cast<const CTxMemPoolEntry&
>(*ref));
352 Assume(!m_have_changeset);
354 std::vector<const TxGraph::Ref*> to_remove;
355 for (
txiter it = mapTx.begin();
it != mapTx.end();
it++) {
356 if (check_final_and_mature(
it)) {
357 to_remove.emplace_back(&*
it);
363 for (
auto ref : all_to_remove) {
367 for (indexed_transaction_set::const_iterator
it = mapTx.begin();
it != mapTx.end();
it++) {
379 if (
it != mapNextTx.end()) {
394 Assume(!m_have_changeset);
395 std::vector<RemovedMempoolTransactionInfo> txs_removed_for_block;
396 if (mapTx.size() || mapNextTx.size() || mapDeltas.size()) {
397 txs_removed_for_block.reserve(vtx.size());
398 for (
const auto& tx : vtx) {
399 txiter it = mapTx.find(tx->GetHash());
400 if (
it != mapTx.end()) {
401 txs_removed_for_block.emplace_back(*
it);
411 lastRollingFeeUpdate =
GetTime();
412 blockSinceLastRollingFeeBump =
true;
424 LogDebug(
BCLog::MEMPOOL,
"Checking mempool with %u transactions and %u inputs\n", (
unsigned int)mapTx.size(), (
unsigned int)mapNextTx.size());
426 uint64_t checkTotal = 0;
428 CAmount check_total_modified_fee{0};
429 int64_t check_total_adjusted_weight{0};
430 uint64_t innerUsage = 0;
433 m_txgraph->SanityCheck();
441 assert(diagram.size() <= score_with_topo.size() + 1);
442 assert(diagram.size() >= 1);
444 std::optional<Wtxid> last_wtxid = std::nullopt;
445 auto diagram_iter = diagram.cbegin();
447 for (
const auto&
it : score_with_topo) {
454 assert(diagram_iter->size >= check_total_adjusted_weight);
455 if (diagram_iter->fee == check_total_modified_fee &&
456 diagram_iter->size == check_total_adjusted_weight) {
459 checkTotal +=
it->GetTxSize();
460 check_total_adjusted_weight +=
it->GetAdjustedWeight();
461 check_total_fee +=
it->GetFee();
462 check_total_modified_fee +=
it->GetModifiedFee();
463 innerUsage +=
it->DynamicMemoryUsage();
472 std::set<CTxMemPoolEntry::CTxMemPoolEntryRef, CompareIteratorByHash> setParentCheck;
473 std::set<CTxMemPoolEntry::CTxMemPoolEntryRef, CompareIteratorByHash> setParentsStored;
476 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.
prevout.
hash);
477 if (it2 != mapTx.end()) {
480 setParentCheck.insert(*it2);
488 auto it3 = mapNextTx.find(txin.
prevout);
489 assert(it3 != mapNextTx.end());
491 assert(&it3->second->GetTx() == &tx);
497 setParentsStored.insert(
dynamic_cast<const CTxMemPoolEntry&
>(txentry.get()));
499 assert(setParentCheck.size() == setParentsStored.size());
500 assert(std::equal(setParentCheck.begin(), setParentCheck.end(), setParentsStored.begin(), comp));
503 std::set<CTxMemPoolEntry::CTxMemPoolEntryRef, CompareIteratorByHash> setChildrenCheck;
504 std::set<CTxMemPoolEntry::CTxMemPoolEntryRef, CompareIteratorByHash> setChildrenStored;
505 auto iter = mapNextTx.lower_bound(
COutPoint(
it->GetTx().GetHash(), 0));
506 for (; iter != mapNextTx.end() && iter->first->hash ==
it->GetTx().GetHash(); ++iter) {
507 txiter childit = iter->second;
508 assert(childit != mapTx.end());
509 setChildrenCheck.insert(*childit);
512 setChildrenStored.insert(
dynamic_cast<const CTxMemPoolEntry&
>(txentry.get()));
514 assert(setChildrenCheck.size() == setChildrenStored.size());
515 assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(), setChildrenStored.begin(), comp));
521 for (
const auto& input: tx.
vin) mempoolDuplicate.SpendCoin(input.prevout);
522 AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
524 for (
auto it = mapNextTx.cbegin();
it != mapNextTx.cend();
it++) {
525 indexed_transaction_set::const_iterator it2 =
it->second;
526 assert(it2 != mapTx.end());
530 assert(diagram_iter == diagram.cend());
532 assert(totalTxSize == checkTotal);
533 assert(m_total_fee == check_total_fee);
534 assert(diagram.back().fee == check_total_modified_fee);
535 assert(diagram.back().size == check_total_adjusted_weight);
536 assert(innerUsage == cachedInnerUsage);
548 if (!j.has_value())
return false;
550 if (!i.has_value())
return true;
552 return m_txgraph->CompareMainOrder(*i.value(), *j.value()) < 0;
557 std::vector<indexed_transaction_set::const_iterator> iters;
560 iters.reserve(mapTx.size());
562 for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
566 return m_txgraph->CompareMainOrder(*a, *b) < 0;
575 std::vector<CTxMemPoolEntryRef>
ret;
576 ret.reserve(mapTx.size());
578 ret.emplace_back(*
it);
588 std::vector<TxMempoolInfo>
ret;
589 ret.reserve(mapTx.size());
590 for (
auto it : iters) {
600 const auto i = mapTx.find(txid);
601 return i == mapTx.end() ? nullptr : &(*i);
607 indexed_transaction_set::const_iterator i = mapTx.find(hash);
608 if (i == mapTx.end())
610 return i->GetSharedTx();
617 CAmount &delta = mapDeltas[hash];
620 if (
it != mapTx.end()) {
623 it->UpdateModifiedFee(nFeeDelta);
624 m_txgraph->SetTransactionFee(*
it,
it->GetModifiedFee());
628 mapDeltas.erase(hash);
629 LogInfo(
"PrioritiseTransaction: %s (%sin mempool) delta cleared\n", hash.
ToString(),
it == mapTx.end() ?
"not " :
"");
631 LogInfo(
"PrioritiseTransaction: %s (%sin mempool) fee += %s, new delta=%s\n",
633 it == mapTx.end() ?
"not " :
"",
643 std::map<Txid, CAmount>::const_iterator pos = mapDeltas.find(hash);
644 if (pos == mapDeltas.end())
646 const CAmount &delta = pos->second;
653 mapDeltas.erase(hash);
660 std::vector<delta_info> result;
661 result.reserve(mapDeltas.size());
662 for (
const auto& [txid, delta] : mapDeltas) {
663 const auto iter{mapTx.find(txid)};
664 const bool in_mempool{iter != mapTx.end()};
665 std::optional<CAmount> modified_fee;
666 if (in_mempool) modified_fee = iter->GetModifiedFee();
667 result.emplace_back(
delta_info{in_mempool, delta, modified_fee, txid});
674 const auto it = mapNextTx.find(prevout);
675 return it == mapNextTx.end() ? nullptr : &(
it->second->GetTx());
681 auto it = mapTx.find(txid);
682 return it != mapTx.end() ? std::make_optional(
it) : std::nullopt;
689 return it != mapTx.end() ? std::make_optional(
it) : std::nullopt;
695 for (
const auto& h : hashes) {
697 if (mi)
ret.insert(*mi);
705 std::vector<txiter>
ret;
706 ret.reserve(txids.size());
707 for (
const auto& txid : txids) {
717 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
738 if (outpoint.
n < ptx->vout.size()) {
750 for (
unsigned int n = 0; n < tx->vout.size(); ++n) {
770 if (m_unbroadcast_txids.erase(txid))
772 LogDebug(
BCLog::MEMPOOL,
"Removed %i from set of unbroadcast txns%s\n", txid.
GetHex(), (unchecked ?
" before confirmation that txn was sent out" :
""));
797 Assume(!m_have_changeset);
798 indexed_transaction_set::index<entry_time>::type::iterator
it = mapTx.get<
entry_time>().begin();
800 while (
it != mapTx.get<
entry_time>().end() &&
it->GetTime() < time) {
801 toremove.insert(mapTx.project<0>(
it));
805 for (
txiter removeit : toremove) {
814 if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
815 return CFeeRate(llround(rollingMinimumFeeRate));
818 if (time > lastRollingFeeUpdate + 10) {
825 rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
826 lastRollingFeeUpdate = time;
829 rollingMinimumFeeRate = 0;
838 if (rate.
GetFeePerK() > rollingMinimumFeeRate) {
840 blockSinceLastRollingFeeBump =
false;
846 Assume(!m_have_changeset);
848 unsigned nTxnRemoved = 0;
852 const auto &[worst_chunk, feeperweight] = m_txgraph->GetWorstMainChunk();
862 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
864 nTxnRemoved += worst_chunk.size();
866 std::vector<CTransaction> txn;
867 if (pvNoSpendsRemaining) {
868 txn.reserve(worst_chunk.size());
869 for (
auto ref : worst_chunk) {
875 for (
auto ref : worst_chunk) {
876 stage.insert(mapTx.iterator_to(
static_cast<const CTxMemPoolEntry&
>(*ref)));
878 for (
auto e : stage) {
881 if (pvNoSpendsRemaining) {
885 pvNoSpendsRemaining->push_back(txin.
prevout);
891 if (maxFeeRateRemoved >
CFeeRate(0)) {
900 size_t ancestor_count = ancestors.size();
901 size_t ancestor_size = 0;
903 for (
auto tx: ancestors) {
908 return {ancestor_count, ancestor_size, ancestor_fees};
914 size_t descendant_count = descendants.size();
915 size_t descendant_size = 0;
918 for (
auto tx: descendants) {
923 return {descendant_count, descendant_size, descendant_fees};
928 auto it = mapTx.find(txid);
929 ancestors = cluster_count = 0;
930 if (
it != mapTx.end()) {
932 ancestors = ancestor_count;
933 if (ancestorsize) *ancestorsize = ancestor_size;
934 if (ancestorfees) *ancestorfees = ancestor_fees;
948 m_load_tried = load_tried;
955 std::vector<CTxMemPool::txiter>
ret;
956 std::set<const CTxMemPoolEntry*> unique_cluster_representatives;
957 for (
auto txid : txids) {
958 auto it = mapTx.find(txid);
959 if (
it != mapTx.end()) {
964 if (unique_cluster_representatives.insert(
static_cast<const CTxMemPoolEntry*
>(&(**cluster.begin()))).second) {
965 for (
auto tx : cluster) {
971 if (
ret.size() > 500) {
985 return m_pool->m_txgraph->GetMainStagingDiagrams();
991 Assume(m_to_add.find(tx->GetHash()) == m_to_add.end());
992 Assume(!m_dependencies_processed);
995 m_dependencies_processed =
false;
998 m_pool->ApplyDelta(tx->GetHash(), delta);
1001 auto newit = m_to_add.emplace(std::move(ref), tx,
fee, time, entry_height, entry_sequence, spends_coinbase, sigops_cost,
lp).first;
1003 newit->UpdateModifiedFee(delta);
1004 m_pool->m_txgraph->SetTransactionFee(*newit, newit->GetModifiedFee());
1007 m_entry_vec.push_back(newit);
1015 m_pool->m_txgraph->RemoveTransaction(*
it);
1016 m_to_remove.insert(
it);
1022 if (!m_dependencies_processed) {
1023 ProcessDependencies();
1025 m_pool->Apply(
this);
1027 m_to_remove.clear();
1028 m_entry_vec.clear();
1029 m_ancestors.clear();
1035 Assume(!m_dependencies_processed);
1036 for (
const auto& entryptr : m_entry_vec) {
1037 for (
const auto &txin : entryptr->GetSharedTx()->vin) {
1038 std::optional<txiter> piter = m_pool->GetIter(txin.
prevout.
hash);
1041 if (
it != m_to_add.end()) {
1042 piter = std::make_optional(
it);
1046 m_pool->m_txgraph->AddDependency(**piter, *entryptr);
1050 m_dependencies_processed =
true;
1057 if (!m_dependencies_processed) {
1058 ProcessDependencies();
1067 std::vector<FeePerWeight>
ret;
1069 ret.emplace_back(zero);
1073 std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef> dummy;
1077 last_selection +=
ret.back();
1078 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)
TxHandle StageAddition(const CTransactionRef &tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
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
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
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...
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)
Before calling removeUnchecked for a given transaction, UpdateForRemoveFromMempool must be called on ...
void RemoveUnbroadcastTx(const Txid &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
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 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 WITH_FRESH_EPOCH(epoch)
#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.