aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorglozow <gzhao408@berkeley.edu>2021-04-05 11:13:27 -0700
committerglozow <gzhao408@berkeley.edu>2021-05-24 14:42:10 +0100
commitae8e6df709ff3d52b8e9918e09cacb64f83ae379 (patch)
treebfbd17da9d061c54cb724cada601096965fc8155 /src/validation.cpp
parentc9e1a26d1f17c8b98632b7796ffa8f8788b5a83c (diff)
downloadbitcoin-ae8e6df709ff3d52b8e9918e09cacb64f83ae379.tar.xz
[policy] limit package sizes
Maximum number of transactions allowed in a package is 25, equal to the default mempool descendant limit: if a package has more transactions than this, either it would fail default mempool descendant limit or the transactions don't all have a dependency relationship (but then they shouldn't be in a package together). Same rationale for 101KvB virtual size package limit. Note that these policies are only used in test accepts so far.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index ad0f636554..07308aab39 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1079,6 +1079,20 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
PackageValidationState package_state;
const unsigned int package_count = txns.size();
+ // These context-free package limits can be checked before taking the mempool lock.
+ if (package_count > MAX_PACKAGE_COUNT) {
+ package_state.Invalid(PackageValidationResult::PCKG_POLICY, "package-too-many-transactions");
+ return PackageMempoolAcceptResult(package_state, {});
+ }
+
+ const int64_t total_size = std::accumulate(txns.cbegin(), txns.cend(), 0,
+ [](int64_t sum, const auto& tx) { return sum + GetVirtualTransactionSize(*tx); });
+ // If the package only contains 1 tx, it's better to report the policy violation on individual tx size.
+ if (package_count > 1 && total_size > MAX_PACKAGE_SIZE * 1000) {
+ package_state.Invalid(PackageValidationResult::PCKG_POLICY, "package-too-large");
+ return PackageMempoolAcceptResult(package_state, {});
+ }
+
std::vector<Workspace> workspaces{};
workspaces.reserve(package_count);
std::transform(txns.cbegin(), txns.cend(), std::back_inserter(workspaces), [](const auto& tx) {