@@ -522,7 +522,7 @@ class MemPoolAccept
522522 };
523523 }
524524
525- /* * Parameters for child-with-unconfirmed- parents package validation. */
525+ /* * Parameters for child-with-parents package validation. */
526526 static ATMPArgs PackageChildWithParents (const CChainParams& chainparams, int64_t accept_time,
527527 std::vector<COutPoint>& coins_to_uncache, const std::optional<CFeeRate>& client_maxfeerate) {
528528 return ATMPArgs{/* m_chainparams */ chainparams,
@@ -1694,7 +1694,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
16941694
16951695 // There are two topologies we are able to handle through this function:
16961696 // (1) A single transaction
1697- // (2) A child-with-unconfirmed- parents package.
1697+ // (2) A child-with-parents package.
16981698 // Check that the package is well-formed. If it isn't, we won't try to validate any of the
16991699 // transactions and thus won't return any MempoolAcceptResults, just a package-wide error.
17001700
@@ -1703,49 +1703,11 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
17031703 return PackageMempoolAcceptResult (package_state_quit_early, {});
17041704 }
17051705
1706- if (package.size () > 1 ) {
1706+ if (package.size () > 1 && ! IsChildWithParents (package) ) {
17071707 // All transactions in the package must be a parent of the last transaction. This is just an
17081708 // opportunity for us to fail fast on a context-free check without taking the mempool lock.
1709- if (!IsChildWithParents (package)) {
1710- package_state_quit_early.Invalid (PackageValidationResult::PCKG_POLICY, " package-not-child-with-parents" );
1711- return PackageMempoolAcceptResult (package_state_quit_early, {});
1712- }
1713-
1714- // IsChildWithParents() guarantees the package is > 1 transactions.
1715- assert (package.size () > 1 );
1716- // The package must be 1 child with all of its unconfirmed parents. The package is expected to
1717- // be sorted, so the last transaction is the child.
1718- const auto & child = package.back ();
1719- std::unordered_set<uint256, SaltedTxidHasher> unconfirmed_parent_txids;
1720- std::transform (package.cbegin (), package.cend () - 1 ,
1721- std::inserter (unconfirmed_parent_txids, unconfirmed_parent_txids.end ()),
1722- [](const auto & tx) { return tx->GetHash (); });
1723-
1724- // All child inputs must refer to a preceding package transaction or a confirmed UTXO. The only
1725- // way to verify this is to look up the child's inputs in our current coins view (not including
1726- // mempool), and enforce that all parents not present in the package be available at chain tip.
1727- // Since this check can bring new coins into the coins cache, keep track of these coins and
1728- // uncache them if we don't end up submitting this package to the mempool.
1729- const CCoinsViewCache& coins_tip_cache = m_active_chainstate.CoinsTip ();
1730- for (const auto & input : child->vin ) {
1731- if (!coins_tip_cache.HaveCoinInCache (input.prevout )) {
1732- args.m_coins_to_uncache .push_back (input.prevout );
1733- }
1734- }
1735- // Using the MemPoolAccept m_view cache allows us to look up these same coins faster later.
1736- // This should be connecting directly to CoinsTip, not to m_viewmempool, because we specifically
1737- // require inputs to be confirmed if they aren't in the package.
1738- m_view.SetBackend (m_active_chainstate.CoinsTip ());
1739- const auto package_or_confirmed = [this , &unconfirmed_parent_txids](const auto & input) {
1740- return unconfirmed_parent_txids.count (input.prevout .hash ) > 0 || m_view.HaveCoin (input.prevout );
1741- };
1742- if (!std::all_of (child->vin .cbegin (), child->vin .cend (), package_or_confirmed)) {
1743- package_state_quit_early.Invalid (PackageValidationResult::PCKG_POLICY, " package-not-child-with-unconfirmed-parents" );
1744- return PackageMempoolAcceptResult (package_state_quit_early, {});
1745- }
1746- // Protect against bugs where we pull more inputs from disk that miss being added to
1747- // coins_to_uncache. The backend will be connected again when needed in PreChecks.
1748- m_view.SetBackend (m_dummy);
1709+ package_state_quit_early.Invalid (PackageValidationResult::PCKG_POLICY, " package-not-child-with-parents" );
1710+ return PackageMempoolAcceptResult (package_state_quit_early, {});
17491711 }
17501712
17511713 LOCK (m_pool.cs );
0 commit comments