@@ -725,8 +725,27 @@ class MemPoolAccept
725
725
726
726
private:
727
727
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
+ */
728
740
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. */
729
745
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. */
730
749
CCoinsView m_dummy;
731
750
732
751
Chainstate& m_active_chainstate;
@@ -1651,7 +1670,8 @@ void MemPoolAccept::CleanupTemporaryCoins()
1651
1670
// (3) Confirmed coins don't need to be removed. The chainstate has not changed (we are
1652
1671
// holding cs_main and no blocks have been processed) so the confirmed tx cannot disappear like
1653
1672
// 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).
1655
1675
// Keeping them in m_view is an optimization to not re-fetch confirmed coins if we later look up
1656
1676
// inputs for this transaction again.
1657
1677
for (const auto & outpoint : m_viewmempool.GetNonBaseCoins ()) {
0 commit comments