@@ -548,6 +548,9 @@ class MemPoolAccept
548548 }
549549 };
550550
551+ /* * Clean up all non-chainstate coins from m_view and m_viewmempool. */
552+ void CleanupTemporaryCoins () EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
553+
551554 // Single transaction acceptance
552555 MempoolAcceptResult AcceptSingleTransaction (const CTransactionRef& ptx, ATMPArgs& args) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
553556
@@ -1347,26 +1350,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
13471350 return PackageMempoolAcceptResult (package_state, std::move (results));
13481351}
13491352
1350- PackageMempoolAcceptResult MemPoolAccept::AcceptSubPackage ( const std::vector<CTransactionRef>& subpackage, ATMPArgs& args )
1353+ void MemPoolAccept::CleanupTemporaryCoins ( )
13511354{
1352- AssertLockHeld (::cs_main);
1353- AssertLockHeld (m_pool.cs );
1354- auto result = [&]() EXCLUSIVE_LOCKS_REQUIRED (::cs_main, m_pool.cs ) {
1355- if (subpackage.size () > 1 ) {
1356- return AcceptMultipleTransactions (subpackage, args);
1357- }
1358- const auto & tx = subpackage.front ();
1359- ATMPArgs single_args = ATMPArgs::SingleInPackageAccept (args);
1360- const auto single_res = AcceptSingleTransaction (tx, single_args);
1361- PackageValidationState package_state_wrapped;
1362- if (single_res.m_result_type != MempoolAcceptResult::ResultType::VALID) {
1363- package_state_wrapped.Invalid (PackageValidationResult::PCKG_TX, " transaction failed" );
1364- }
1365- return PackageMempoolAcceptResult (package_state_wrapped, {{tx->GetWitnessHash (), single_res}});
1366- }();
1367- // Clean up m_view and m_viewmempool so that other subpackage evaluations don't have access to
1368- // coins they shouldn't. Keep some coins in order to minimize re-fetching coins from the UTXO set.
1369- //
13701355 // There are 3 kinds of coins in m_view:
13711356 // (1) Temporary coins from the transactions in subpackage, constructed by m_viewmempool.
13721357 // (2) Mempool coins from transactions in the mempool, constructed by m_viewmempool.
@@ -1392,6 +1377,30 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptSubPackage(const std::vector<CTr
13921377 }
13931378 // This deletes the temporary and mempool coins.
13941379 m_viewmempool.Reset ();
1380+ }
1381+
1382+ PackageMempoolAcceptResult MemPoolAccept::AcceptSubPackage (const std::vector<CTransactionRef>& subpackage, ATMPArgs& args)
1383+ {
1384+ AssertLockHeld (::cs_main);
1385+ AssertLockHeld (m_pool.cs );
1386+ auto result = [&]() EXCLUSIVE_LOCKS_REQUIRED (::cs_main, m_pool.cs ) {
1387+ if (subpackage.size () > 1 ) {
1388+ return AcceptMultipleTransactions (subpackage, args);
1389+ }
1390+ const auto & tx = subpackage.front ();
1391+ ATMPArgs single_args = ATMPArgs::SingleInPackageAccept (args);
1392+ const auto single_res = AcceptSingleTransaction (tx, single_args);
1393+ PackageValidationState package_state_wrapped;
1394+ if (single_res.m_result_type != MempoolAcceptResult::ResultType::VALID) {
1395+ package_state_wrapped.Invalid (PackageValidationResult::PCKG_TX, " transaction failed" );
1396+ }
1397+ return PackageMempoolAcceptResult (package_state_wrapped, {{tx->GetWitnessHash (), single_res}});
1398+ }();
1399+
1400+ // Clean up m_view and m_viewmempool so that other subpackage evaluations don't have access to
1401+ // coins they shouldn't. Keep some coins in order to minimize re-fetching coins from the UTXO set.
1402+ CleanupTemporaryCoins ();
1403+
13951404 return result;
13961405}
13971406
0 commit comments