[refactor] move package checks into helper functions

This allows IsSorted() and IsConsistent() to be used by themselves.
IsSorted() with a precomputed set is used so that we don't create this
set multiple times.
This commit is contained in:
glozow
2022-09-16 16:49:24 +01:00
parent d51fb9caa6
commit da9aceba21
4 changed files with 137 additions and 39 deletions

View File

@@ -1258,7 +1258,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
// These context-free package limits can be done before taking the mempool lock.
PackageValidationState package_state;
if (!CheckPackage(txns, package_state)) return PackageMempoolAcceptResult(package_state, {});
if (!CheckPackage(txns, package_state, /*require_sorted=*/true)) return PackageMempoolAcceptResult(package_state, {});
std::vector<Workspace> workspaces{};
workspaces.reserve(txns.size());
@@ -1405,7 +1405,9 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
// transactions and thus won't return any MempoolAcceptResults, just a package-wide error.
// Context-free package checks.
if (!CheckPackage(package, package_state_quit_early)) return PackageMempoolAcceptResult(package_state_quit_early, {});
if (!CheckPackage(package, package_state_quit_early, /*require_sorted=*/true)) {
return PackageMempoolAcceptResult(package_state_quit_early, {});
}
// All transactions in the package must be a parent of the last transaction. This is just an
// opportunity for us to fail fast on a context-free check without taking the mempool lock.