aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2023-10-04 08:42:28 +0100
committerglozow <gloriajzhao@gmail.com>2023-11-01 17:21:54 +0000
commitb5a60abe8783852f5b31bc1e63b5836530410e65 (patch)
tree1ff89a2125ceeba8ef4f64f7fa3cdb656690b665
parent10c0a8678cd28e7f0715e6cfa3e651903e4ad4aa (diff)
MOVEONLY: CleanupTemporaryCoins into its own function
Avoid duplicate code. This will be used at the end of every AcceptSubPackage and after PreChecks loop in AcceptPackage.
-rw-r--r--src/validation.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index ffa63dcff1..2f8c0a9f04 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -548,6 +548,9 @@ public:
}
};
+ /** Clean up all non-chainstate coins from m_view and m_viewmempool. */
+ void CleanupTemporaryCoins() EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);
+
// Single transaction acceptance
MempoolAcceptResult AcceptSingleTransaction(const CTransactionRef& ptx, ATMPArgs& args) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -1347,26 +1350,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
return PackageMempoolAcceptResult(package_state, std::move(results));
}
-PackageMempoolAcceptResult MemPoolAccept::AcceptSubPackage(const std::vector<CTransactionRef>& subpackage, ATMPArgs& args)
+void MemPoolAccept::CleanupTemporaryCoins()
{
- AssertLockHeld(::cs_main);
- AssertLockHeld(m_pool.cs);
- auto result = [&]() EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_pool.cs) {
- if (subpackage.size() > 1) {
- return AcceptMultipleTransactions(subpackage, args);
- }
- const auto& tx = subpackage.front();
- ATMPArgs single_args = ATMPArgs::SingleInPackageAccept(args);
- const auto single_res = AcceptSingleTransaction(tx, single_args);
- PackageValidationState package_state_wrapped;
- if (single_res.m_result_type != MempoolAcceptResult::ResultType::VALID) {
- package_state_wrapped.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
- }
- return PackageMempoolAcceptResult(package_state_wrapped, {{tx->GetWitnessHash(), single_res}});
- }();
- // Clean up m_view and m_viewmempool so that other subpackage evaluations don't have access to
- // coins they shouldn't. Keep some coins in order to minimize re-fetching coins from the UTXO set.
- //
// There are 3 kinds of coins in m_view:
// (1) Temporary coins from the transactions in subpackage, constructed by m_viewmempool.
// (2) Mempool coins from transactions in the mempool, constructed by m_viewmempool.
@@ -1392,6 +1377,30 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptSubPackage(const std::vector<CTr
}
// This deletes the temporary and mempool coins.
m_viewmempool.Reset();
+}
+
+PackageMempoolAcceptResult MemPoolAccept::AcceptSubPackage(const std::vector<CTransactionRef>& subpackage, ATMPArgs& args)
+{
+ AssertLockHeld(::cs_main);
+ AssertLockHeld(m_pool.cs);
+ auto result = [&]() EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_pool.cs) {
+ if (subpackage.size() > 1) {
+ return AcceptMultipleTransactions(subpackage, args);
+ }
+ const auto& tx = subpackage.front();
+ ATMPArgs single_args = ATMPArgs::SingleInPackageAccept(args);
+ const auto single_res = AcceptSingleTransaction(tx, single_args);
+ PackageValidationState package_state_wrapped;
+ if (single_res.m_result_type != MempoolAcceptResult::ResultType::VALID) {
+ package_state_wrapped.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
+ }
+ return PackageMempoolAcceptResult(package_state_wrapped, {{tx->GetWitnessHash(), single_res}});
+ }();
+
+ // Clean up m_view and m_viewmempool so that other subpackage evaluations don't have access to
+ // coins they shouldn't. Keep some coins in order to minimize re-fetching coins from the UTXO set.
+ CleanupTemporaryCoins();
+
return result;
}