@@ -548,6 +548,9 @@ class MemPoolAccept
548
548
}
549
549
};
550
550
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
+
551
554
// Single transaction acceptance
552
555
MempoolAcceptResult AcceptSingleTransaction (const CTransactionRef& ptx, ATMPArgs& args) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
553
556
@@ -1347,26 +1350,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
1347
1350
return PackageMempoolAcceptResult (package_state, std::move (results));
1348
1351
}
1349
1352
1350
- PackageMempoolAcceptResult MemPoolAccept::AcceptSubPackage ( const std::vector<CTransactionRef>& subpackage, ATMPArgs& args )
1353
+ void MemPoolAccept::CleanupTemporaryCoins ( )
1351
1354
{
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
- //
1370
1355
// There are 3 kinds of coins in m_view:
1371
1356
// (1) Temporary coins from the transactions in subpackage, constructed by m_viewmempool.
1372
1357
// (2) Mempool coins from transactions in the mempool, constructed by m_viewmempool.
@@ -1392,6 +1377,30 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptSubPackage(const std::vector<CTr
1392
1377
}
1393
1378
// This deletes the temporary and mempool coins.
1394
1379
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
+
1395
1404
return result;
1396
1405
}
1397
1406
0 commit comments