Skip to content

Commit 98ba2b1

Browse files
committed
[doc] MemPoolAccept coins views
1 parent ba02c30 commit 98ba2b1

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/validation.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,27 @@ class MemPoolAccept
725725

726726
private:
727727
CTxMemPool& m_pool;
728+
729+
/** Holds a cached view of available coins from the UTXO set, mempool, and artificial temporary coins (to enable package validation).
730+
* The view doesn't track whether a coin previously existed but has now been spent. We detect conflicts in other ways:
731+
* - conflicts within a transaction are checked in CheckTransaction (bad-txns-inputs-duplicate)
732+
* - conflicts within a package are checked in IsWellFormedPackage (conflict-in-package)
733+
* - conflicts with an existing mempool transaction are found in CTxMemPool::GetConflictTx and replacements are allowed
734+
* The temporary coins should persist between individual transaction checks so that package validation is possible,
735+
* but must be cleaned up when we finish validating a subpackage, whether accepted or rejected. The cache must also
736+
* be cleared when mempool contents change (when a changeset is applied or when the mempool trims itself) because it
737+
* can return cached coins that no longer exist in the backend. Use CleanupTemporaryCoins() anytime you are finished
738+
* with a SubPackageState or call LimitMempoolSize().
739+
*/
728740
CCoinsViewCache m_view;
741+
742+
// These are the two possible backends for m_view.
743+
/** When m_view is connected to m_viewmempool as its backend, it can pull coins from the mempool and from the UTXO
744+
* set. This is also where temporary coins are stored. */
729745
CCoinsViewMemPool m_viewmempool;
746+
/** When m_view is connected to m_dummy, it can no longer look up coins from the mempool or UTXO set (meaning no disk
747+
* operations happen), but can still return coins it accessed previously. Useful for keeping track of which coins
748+
* were pulled from disk. */
730749
CCoinsView m_dummy;
731750

732751
Chainstate& m_active_chainstate;
@@ -1651,7 +1670,8 @@ void MemPoolAccept::CleanupTemporaryCoins()
16511670
// (3) Confirmed coins don't need to be removed. The chainstate has not changed (we are
16521671
// holding cs_main and no blocks have been processed) so the confirmed tx cannot disappear like
16531672
// a mempool tx can. The coin may now be spent after we submitted a tx to mempool, but
1654-
// we have already checked that the package does not have 2 transactions spending the same coin.
1673+
// we have already checked that the package does not have 2 transactions spending the same coin
1674+
// and we check whether a mempool transaction spends conflicting coins (CTxMemPool::GetConflictTx).
16551675
// Keeping them in m_view is an optimization to not re-fetch confirmed coins if we later look up
16561676
// inputs for this transaction again.
16571677
for (const auto& outpoint : m_viewmempool.GetNonBaseCoins()) {

0 commit comments

Comments
 (0)