1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_TXMEMPOOL_H
7 #define BITCOIN_TXMEMPOOL_H
18 #include "indirectmap.h"
19 #include "policy/feerate.h"
20 #include "primitives/transaction.h"
24 #include "boost/multi_index_container.hpp"
25 #include "boost/multi_index/ordered_index.hpp"
26 #include "boost/multi_index/hashed_index.hpp"
28 #include <boost/signals2/signal.hpp>
33 /** Fake height value used in CCoins to signify they are only in the memory pool (since 0.8) */
34 static const unsigned int MEMPOOL_HEIGHT
= 0x7FFFFFFF;
38 // Will be set to the blockchain height and median time past
39 // values that would be necessary to satisfy all relative locktime
40 // constraints (BIP68) of this tx given our view of block chain history
43 // As long as the current chain descends from the highest height block
44 // containing one of the inputs used in the calculation, then the cached
45 // values are still valid even after a reorg.
46 CBlockIndex
* maxInputBlock
;
48 LockPoints() : height(0), time(0), maxInputBlock(NULL
) { }
53 /** \class CTxMemPoolEntry
55 * CTxMemPoolEntry stores data about the corresponding transaction, as well
56 * as data about all in-mempool transactions that depend on the transaction
57 * ("descendant" transactions).
59 * When a new entry is added to the mempool, we update the descendant state
60 * (nCountWithDescendants, nSizeWithDescendants, and nModFeesWithDescendants) for
61 * all ancestors of the newly added transaction.
69 CAmount nFee
; //!< Cached to avoid expensive parent-transaction lookups
70 size_t nTxWeight
; //!< ... and avoid recomputing tx weight (also used for GetTxSize())
71 size_t nUsageSize
; //!< ... and total memory usage
72 int64_t nTime
; //!< Local time when entering the mempool
73 unsigned int entryHeight
; //!< Chain height when entering the mempool
74 bool spendsCoinbase
; //!< keep track of transactions that spend a coinbase
75 int64_t sigOpCost
; //!< Total sigop cost
76 int64_t feeDelta
; //!< Used for determining the priority of the transaction for mining in a block
77 LockPoints lockPoints
; //!< Track the height and time at which tx was final
79 // Information about descendants of this transaction that are in the
80 // mempool; if we remove this transaction we must remove all of these
81 // descendants as well.
82 uint64_t nCountWithDescendants
; //!< number of descendant transactions
83 uint64_t nSizeWithDescendants
; //!< ... and size
84 CAmount nModFeesWithDescendants
; //!< ... and total fees (all including us)
86 // Analogous statistics for ancestor transactions
87 uint64_t nCountWithAncestors
;
88 uint64_t nSizeWithAncestors
;
89 CAmount nModFeesWithAncestors
;
90 int64_t nSigOpCostWithAncestors
;
93 CTxMemPoolEntry(const CTransactionRef
& _tx
, const CAmount
& _nFee
,
94 int64_t _nTime
, unsigned int _entryHeight
,
96 int64_t nSigOpsCost
, LockPoints lp
);
98 CTxMemPoolEntry(const CTxMemPoolEntry
& other
);
100 const CTransaction
& GetTx() const { return *this->tx
; }
101 CTransactionRef
GetSharedTx() const { return this->tx
; }
102 const CAmount
& GetFee() const { return nFee
; }
103 size_t GetTxSize() const;
104 size_t GetTxWeight() const { return nTxWeight
; }
105 int64_t GetTime() const { return nTime
; }
106 unsigned int GetHeight() const { return entryHeight
; }
107 int64_t GetSigOpCost() const { return sigOpCost
; }
108 int64_t GetModifiedFee() const { return nFee
+ feeDelta
; }
109 size_t DynamicMemoryUsage() const { return nUsageSize
; }
110 const LockPoints
& GetLockPoints() const { return lockPoints
; }
112 // Adjusts the descendant state.
113 void UpdateDescendantState(int64_t modifySize
, CAmount modifyFee
, int64_t modifyCount
);
114 // Adjusts the ancestor state
115 void UpdateAncestorState(int64_t modifySize
, CAmount modifyFee
, int64_t modifyCount
, int modifySigOps
);
116 // Updates the fee delta used for mining priority score, and the
117 // modified fees with descendants.
118 void UpdateFeeDelta(int64_t feeDelta
);
119 // Update the LockPoints after a reorg
120 void UpdateLockPoints(const LockPoints
& lp
);
122 uint64_t GetCountWithDescendants() const { return nCountWithDescendants
; }
123 uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants
; }
124 CAmount
GetModFeesWithDescendants() const { return nModFeesWithDescendants
; }
126 bool GetSpendsCoinbase() const { return spendsCoinbase
; }
128 uint64_t GetCountWithAncestors() const { return nCountWithAncestors
; }
129 uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors
; }
130 CAmount
GetModFeesWithAncestors() const { return nModFeesWithAncestors
; }
131 int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors
; }
133 mutable size_t vTxHashesIdx
; //!< Index in mempool's vTxHashes
136 // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
137 struct update_descendant_state
139 update_descendant_state(int64_t _modifySize
, CAmount _modifyFee
, int64_t _modifyCount
) :
140 modifySize(_modifySize
), modifyFee(_modifyFee
), modifyCount(_modifyCount
)
143 void operator() (CTxMemPoolEntry
&e
)
144 { e
.UpdateDescendantState(modifySize
, modifyFee
, modifyCount
); }
152 struct update_ancestor_state
154 update_ancestor_state(int64_t _modifySize
, CAmount _modifyFee
, int64_t _modifyCount
, int64_t _modifySigOpsCost
) :
155 modifySize(_modifySize
), modifyFee(_modifyFee
), modifyCount(_modifyCount
), modifySigOpsCost(_modifySigOpsCost
)
158 void operator() (CTxMemPoolEntry
&e
)
159 { e
.UpdateAncestorState(modifySize
, modifyFee
, modifyCount
, modifySigOpsCost
); }
165 int64_t modifySigOpsCost
;
168 struct update_fee_delta
170 update_fee_delta(int64_t _feeDelta
) : feeDelta(_feeDelta
) { }
172 void operator() (CTxMemPoolEntry
&e
) { e
.UpdateFeeDelta(feeDelta
); }
178 struct update_lock_points
180 update_lock_points(const LockPoints
& _lp
) : lp(_lp
) { }
182 void operator() (CTxMemPoolEntry
&e
) { e
.UpdateLockPoints(lp
); }
185 const LockPoints
& lp
;
188 // extracts a TxMemPoolEntry's transaction hash
189 struct mempoolentry_txid
191 typedef uint256 result_type
;
192 result_type
operator() (const CTxMemPoolEntry
&entry
) const
194 return entry
.GetTx().GetHash();
198 /** \class CompareTxMemPoolEntryByDescendantScore
200 * Sort an entry by max(score/size of entry's tx, score/size with all descendants).
202 class CompareTxMemPoolEntryByDescendantScore
205 bool operator()(const CTxMemPoolEntry
& a
, const CTxMemPoolEntry
& b
)
207 bool fUseADescendants
= UseDescendantScore(a
);
208 bool fUseBDescendants
= UseDescendantScore(b
);
210 double aModFee
= fUseADescendants
? a
.GetModFeesWithDescendants() : a
.GetModifiedFee();
211 double aSize
= fUseADescendants
? a
.GetSizeWithDescendants() : a
.GetTxSize();
213 double bModFee
= fUseBDescendants
? b
.GetModFeesWithDescendants() : b
.GetModifiedFee();
214 double bSize
= fUseBDescendants
? b
.GetSizeWithDescendants() : b
.GetTxSize();
216 // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
217 double f1
= aModFee
* bSize
;
218 double f2
= aSize
* bModFee
;
221 return a
.GetTime() >= b
.GetTime();
226 // Calculate which score to use for an entry (avoiding division).
227 bool UseDescendantScore(const CTxMemPoolEntry
&a
)
229 double f1
= (double)a
.GetModifiedFee() * a
.GetSizeWithDescendants();
230 double f2
= (double)a
.GetModFeesWithDescendants() * a
.GetTxSize();
235 /** \class CompareTxMemPoolEntryByScore
237 * Sort by score of entry ((fee+delta)/size) in descending order
239 class CompareTxMemPoolEntryByScore
242 bool operator()(const CTxMemPoolEntry
& a
, const CTxMemPoolEntry
& b
)
244 double f1
= (double)a
.GetModifiedFee() * b
.GetTxSize();
245 double f2
= (double)b
.GetModifiedFee() * a
.GetTxSize();
247 return b
.GetTx().GetHash() < a
.GetTx().GetHash();
253 class CompareTxMemPoolEntryByEntryTime
256 bool operator()(const CTxMemPoolEntry
& a
, const CTxMemPoolEntry
& b
)
258 return a
.GetTime() < b
.GetTime();
262 class CompareTxMemPoolEntryByAncestorFee
265 bool operator()(const CTxMemPoolEntry
& a
, const CTxMemPoolEntry
& b
)
267 double aFees
= a
.GetModFeesWithAncestors();
268 double aSize
= a
.GetSizeWithAncestors();
270 double bFees
= b
.GetModFeesWithAncestors();
271 double bSize
= b
.GetSizeWithAncestors();
273 // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
274 double f1
= aFees
* bSize
;
275 double f2
= aSize
* bFees
;
278 return a
.GetTx().GetHash() < b
.GetTx().GetHash();
285 // Multi_index tag names
286 struct descendant_score
{};
287 struct entry_time
{};
288 struct mining_score
{};
289 struct ancestor_score
{};
291 class CBlockPolicyEstimator
;
294 * Information about a mempool transaction.
298 /** The transaction itself */
301 /** Time the transaction entered the mempool. */
304 /** Feerate of the transaction. */
307 /** The fee delta. */
311 /** Reason why a transaction was removed from the mempool,
312 * this is passed to the notification signal.
314 enum class MemPoolRemovalReason
{
315 UNKNOWN
= 0, //! Manually removed or unknown reason
316 EXPIRY
, //! Expired from mempool
317 SIZELIMIT
, //! Removed in size limiting
318 REORG
, //! Removed for reorganization
319 BLOCK
, //! Removed for block
320 CONFLICT
, //! Removed for conflict with in-block transaction
321 REPLACED
//! Removed for replacement
325 * CTxMemPool stores valid-according-to-the-current-best-chain transactions
326 * that may be included in the next block.
328 * Transactions are added when they are seen on the network (or created by the
329 * local node), but not all transactions seen are added to the pool. For
330 * example, the following new transactions will not be added to the mempool:
331 * - a transaction which doesn't meet the minimum fee requirements.
332 * - a new transaction that double-spends an input of a transaction already in
333 * the pool where the new transaction does not meet the Replace-By-Fee
334 * requirements as defined in BIP 125.
335 * - a non-standard transaction.
337 * CTxMemPool::mapTx, and CTxMemPoolEntry bookkeeping:
339 * mapTx is a boost::multi_index that sorts the mempool on 4 criteria:
341 * - feerate [we use max(feerate of tx, feerate of tx with all descendants)]
343 * - mining score (feerate modified by any fee deltas from PrioritiseTransaction)
345 * Note: the term "descendant" refers to in-mempool transactions that depend on
346 * this one, while "ancestor" refers to in-mempool transactions that a given
347 * transaction depends on.
349 * In order for the feerate sort to remain correct, we must update transactions
350 * in the mempool when new descendants arrive. To facilitate this, we track
351 * the set of in-mempool direct parents and direct children in mapLinks. Within
352 * each CTxMemPoolEntry, we track the size and fees of all descendants.
354 * Usually when a new transaction is added to the mempool, it has no in-mempool
355 * children (because any such children would be an orphan). So in
356 * addUnchecked(), we:
357 * - update a new entry's setMemPoolParents to include all in-mempool parents
358 * - update the new entry's direct parents to include the new tx as a child
359 * - update all ancestors of the transaction to include the new tx's size/fee
361 * When a transaction is removed from the mempool, we must:
362 * - update all in-mempool parents to not track the tx in setMemPoolChildren
363 * - update all ancestors to not include the tx's size/fees in descendant state
364 * - update all in-mempool children to not include it as a parent
366 * These happen in UpdateForRemoveFromMempool(). (Note that when removing a
367 * transaction along with its descendants, we must calculate that set of
368 * transactions to be removed before doing the removal, or else the mempool can
369 * be in an inconsistent state where it's impossible to walk the ancestors of
372 * In the event of a reorg, the assumption that a newly added tx has no
373 * in-mempool children is false. In particular, the mempool is in an
374 * inconsistent state while new transactions are being added, because there may
375 * be descendant transactions of a tx coming from a disconnected block that are
376 * unreachable from just looking at transactions in the mempool (the linking
377 * transactions may also be in the disconnected block, waiting to be added).
378 * Because of this, there's not much benefit in trying to search for in-mempool
379 * children in addUnchecked(). Instead, in the special case of transactions
380 * being added from a disconnected block, we require the caller to clean up the
381 * state, to account for in-mempool, out-of-block descendants for all the
382 * in-block transactions by calling UpdateTransactionsFromBlock(). Note that
383 * until this is called, the mempool state is not consistent, and in particular
384 * mapLinks may not be correct (and therefore functions like
385 * CalculateMemPoolAncestors() and CalculateDescendants() that rely
386 * on them to walk the mempool are not generally safe to use).
388 * Computational limits:
390 * Updating all in-mempool ancestors of a newly added transaction can be slow,
391 * if no bound exists on how many in-mempool ancestors there may be.
392 * CalculateMemPoolAncestors() takes configurable limits that are designed to
393 * prevent these calculations from being too CPU intensive.
399 uint32_t nCheckFrequency
; //!< Value n means that n times in 2^32 we check.
400 unsigned int nTransactionsUpdated
; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
401 CBlockPolicyEstimator
* minerPolicyEstimator
;
403 uint64_t totalTxSize
; //!< sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.
404 uint64_t cachedInnerUsage
; //!< sum of dynamic memory usage of all the map elements (NOT the maps themselves)
406 mutable int64_t lastRollingFeeUpdate
;
407 mutable bool blockSinceLastRollingFeeBump
;
408 mutable double rollingMinimumFeeRate
; //!< minimum fee to get into the pool, decreases exponentially
410 void trackPackageRemoved(const CFeeRate
& rate
);
414 static const int ROLLING_FEE_HALFLIFE
= 60 * 60 * 12; // public only for testing
416 typedef boost::multi_index_container
<
418 boost::multi_index::indexed_by
<
420 boost::multi_index::hashed_unique
<mempoolentry_txid
, SaltedTxidHasher
>,
421 // sorted by fee rate
422 boost::multi_index::ordered_non_unique
<
423 boost::multi_index::tag
<descendant_score
>,
424 boost::multi_index::identity
<CTxMemPoolEntry
>,
425 CompareTxMemPoolEntryByDescendantScore
427 // sorted by entry time
428 boost::multi_index::ordered_non_unique
<
429 boost::multi_index::tag
<entry_time
>,
430 boost::multi_index::identity
<CTxMemPoolEntry
>,
431 CompareTxMemPoolEntryByEntryTime
433 // sorted by score (for mining prioritization)
434 boost::multi_index::ordered_unique
<
435 boost::multi_index::tag
<mining_score
>,
436 boost::multi_index::identity
<CTxMemPoolEntry
>,
437 CompareTxMemPoolEntryByScore
439 // sorted by fee rate with ancestors
440 boost::multi_index::ordered_non_unique
<
441 boost::multi_index::tag
<ancestor_score
>,
442 boost::multi_index::identity
<CTxMemPoolEntry
>,
443 CompareTxMemPoolEntryByAncestorFee
446 > indexed_transaction_set
;
448 mutable CCriticalSection cs
;
449 indexed_transaction_set mapTx
;
451 typedef indexed_transaction_set::nth_index
<0>::type::iterator txiter
;
452 std::vector
<std::pair
<uint256
, txiter
> > vTxHashes
; //!< All tx witness hashes/entries in mapTx, in random order
454 struct CompareIteratorByHash
{
455 bool operator()(const txiter
&a
, const txiter
&b
) const {
456 return a
->GetTx().GetHash() < b
->GetTx().GetHash();
459 typedef std::set
<txiter
, CompareIteratorByHash
> setEntries
;
461 const setEntries
& GetMemPoolParents(txiter entry
) const;
462 const setEntries
& GetMemPoolChildren(txiter entry
) const;
464 typedef std::map
<txiter
, setEntries
, CompareIteratorByHash
> cacheMap
;
471 typedef std::map
<txiter
, TxLinks
, CompareIteratorByHash
> txlinksMap
;
474 void UpdateParent(txiter entry
, txiter parent
, bool add
);
475 void UpdateChild(txiter entry
, txiter child
, bool add
);
477 std::vector
<indexed_transaction_set::const_iterator
> GetSortedDepthAndScore() const;
480 indirectmap
<COutPoint
, const CTransaction
*> mapNextTx
;
481 std::map
<uint256
, CAmount
> mapDeltas
;
483 /** Create a new CTxMemPool.
485 CTxMemPool(CBlockPolicyEstimator
* estimator
= nullptr);
488 * If sanity-checking is turned on, check makes sure the pool is
489 * consistent (does not contain two transactions that spend the same inputs,
490 * all inputs are in the mapNextTx array). If sanity-checking is turned off,
491 * check does nothing.
493 void check(const CCoinsViewCache
*pcoins
) const;
494 void setSanityCheck(double dFrequency
= 1.0) { nCheckFrequency
= dFrequency
* 4294967295.0; }
496 // addUnchecked must updated state for all ancestors of a given transaction,
497 // to track size/count of descendant transactions. First version of
498 // addUnchecked can be used to have it call CalculateMemPoolAncestors(), and
499 // then invoke the second version.
500 bool addUnchecked(const uint256
& hash
, const CTxMemPoolEntry
&entry
, bool validFeeEstimate
= true);
501 bool addUnchecked(const uint256
& hash
, const CTxMemPoolEntry
&entry
, setEntries
&setAncestors
, bool validFeeEstimate
= true);
503 void removeRecursive(const CTransaction
&tx
, MemPoolRemovalReason reason
= MemPoolRemovalReason::UNKNOWN
);
504 void removeForReorg(const CCoinsViewCache
*pcoins
, unsigned int nMemPoolHeight
, int flags
);
505 void removeConflicts(const CTransaction
&tx
);
506 void removeForBlock(const std::vector
<CTransactionRef
>& vtx
, unsigned int nBlockHeight
);
509 void _clear(); //lock free
510 bool CompareDepthAndScore(const uint256
& hasha
, const uint256
& hashb
);
511 void queryHashes(std::vector
<uint256
>& vtxid
);
512 void pruneSpent(const uint256
& hash
, CCoins
&coins
);
513 unsigned int GetTransactionsUpdated() const;
514 void AddTransactionsUpdated(unsigned int n
);
516 * Check that none of this transactions inputs are in the mempool, and thus
517 * the tx is not dependent on other mempool transactions to be included in a block.
519 bool HasNoInputsOf(const CTransaction
& tx
) const;
521 /** Affect CreateNewBlock prioritisation of transactions */
522 void PrioritiseTransaction(const uint256
& hash
, const CAmount
& nFeeDelta
);
523 void ApplyDelta(const uint256 hash
, CAmount
&nFeeDelta
) const;
524 void ClearPrioritisation(const uint256 hash
);
527 /** Remove a set of transactions from the mempool.
528 * If a transaction is in this set, then all in-mempool descendants must
529 * also be in the set, unless this transaction is being removed for being
531 * Set updateDescendants to true when removing a tx that was in a block, so
532 * that any in-mempool descendants have their ancestor state updated.
534 void RemoveStaged(setEntries
&stage
, bool updateDescendants
, MemPoolRemovalReason reason
= MemPoolRemovalReason::UNKNOWN
);
536 /** When adding transactions from a disconnected block back to the mempool,
537 * new mempool entries may have children in the mempool (which is generally
538 * not the case when otherwise adding transactions).
539 * UpdateTransactionsFromBlock() will find child transactions and update the
540 * descendant state for each transaction in vHashesToUpdate (excluding any
541 * child transactions present in vHashesToUpdate, which are already accounted
542 * for). Note: vHashesToUpdate should be the set of transactions from the
543 * disconnected block that have been accepted back into the mempool.
545 void UpdateTransactionsFromBlock(const std::vector
<uint256
> &vHashesToUpdate
);
547 /** Try to calculate all in-mempool ancestors of entry.
548 * (these are all calculated including the tx itself)
549 * limitAncestorCount = max number of ancestors
550 * limitAncestorSize = max size of ancestors
551 * limitDescendantCount = max number of descendants any ancestor can have
552 * limitDescendantSize = max size of descendants any ancestor can have
553 * errString = populated with error reason if any limits are hit
554 * fSearchForParents = whether to search a tx's vin for in-mempool parents, or
555 * look up parents from mapLinks. Must be true for entries not in the mempool
557 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;
559 /** Populate setDescendants with all in-mempool descendants of hash.
560 * Assumes that setDescendants includes all in-mempool descendants of anything
562 void CalculateDescendants(txiter it
, setEntries
&setDescendants
);
564 /** The minimum fee to get into the mempool, which may itself not be enough
565 * for larger-sized transactions.
566 * The incrementalRelayFee policy variable is used to bound the time it
567 * takes the fee rate to go back down all the way to 0. When the feerate
568 * would otherwise be half of this, it is set to 0 instead.
570 CFeeRate
GetMinFee(size_t sizelimit
) const;
572 /** Remove transactions from the mempool until its dynamic size is <= sizelimit.
573 * pvNoSpendsRemaining, if set, will be populated with the list of transactions
574 * which are not in mempool which no longer have any spends in this mempool.
576 void TrimToSize(size_t sizelimit
, std::vector
<uint256
>* pvNoSpendsRemaining
=NULL
);
578 /** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */
579 int Expire(int64_t time
);
581 /** Returns false if the transaction is in the mempool and not within the chain limit specified. */
582 bool TransactionWithinChainLimit(const uint256
& txid
, size_t chainLimit
) const;
590 uint64_t GetTotalTxSize()
596 bool exists(uint256 hash
) const
599 return (mapTx
.count(hash
) != 0);
602 CTransactionRef
get(const uint256
& hash
) const;
603 TxMempoolInfo
info(const uint256
& hash
) const;
604 std::vector
<TxMempoolInfo
> infoAll() const;
606 size_t DynamicMemoryUsage() const;
608 boost::signals2::signal
<void (CTransactionRef
)> NotifyEntryAdded
;
609 boost::signals2::signal
<void (CTransactionRef
, MemPoolRemovalReason
)> NotifyEntryRemoved
;
612 /** UpdateForDescendants is used by UpdateTransactionsFromBlock to update
613 * the descendants for a single transaction that has been added to the
614 * mempool but may have child transactions in the mempool, eg during a
615 * chain reorg. setExclude is the set of descendant transactions in the
616 * mempool that must not be accounted for (because any descendants in
617 * setExclude were added to the mempool after the transaction being
618 * updated and hence their state is already reflected in the parent
621 * cachedDescendants will be updated with the descendants of the transaction
622 * being updated, so that future invocations don't need to walk the
623 * same transaction again, if encountered in another transaction chain.
625 void UpdateForDescendants(txiter updateIt
,
626 cacheMap
&cachedDescendants
,
627 const std::set
<uint256
> &setExclude
);
628 /** Update ancestors of hash to add/remove it as a descendant transaction. */
629 void UpdateAncestorsOf(bool add
, txiter hash
, setEntries
&setAncestors
);
630 /** Set ancestor state for an entry */
631 void UpdateEntryForAncestors(txiter it
, const setEntries
&setAncestors
);
632 /** For each transaction being removed, update ancestors and any direct children.
633 * If updateDescendants is true, then also update in-mempool descendants'
635 void UpdateForRemoveFromMempool(const setEntries
&entriesToRemove
, bool updateDescendants
);
636 /** Sever link between specified transaction and direct children. */
637 void UpdateChildrenForRemoval(txiter entry
);
639 /** Before calling removeUnchecked for a given transaction,
640 * UpdateForRemoveFromMempool must be called on the entire (dependent) set
641 * of transactions being removed at the same time. We use each
642 * CTxMemPoolEntry's setMemPoolParents in order to walk ancestors of a
643 * given transaction that is removed, so we can't remove intermediate
644 * transactions in a chain before we've updated all the state for the
647 void removeUnchecked(txiter entry
, MemPoolRemovalReason reason
= MemPoolRemovalReason::UNKNOWN
);
651 * CCoinsView that brings transactions from a memorypool into view.
652 * It does not check for spendings by memory pool transactions.
654 class CCoinsViewMemPool
: public CCoinsViewBacked
657 const CTxMemPool
& mempool
;
660 CCoinsViewMemPool(CCoinsView
* baseIn
, const CTxMemPool
& mempoolIn
);
661 bool GetCoins(const uint256
&txid
, CCoins
&coins
) const;
662 bool HaveCoins(const uint256
&txid
) const;
665 #endif // BITCOIN_TXMEMPOOL_H