Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 731 Lines • ▼ Show 20 Lines | |||||
PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions( | PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions( | ||||
const std::vector<CTransactionRef> &txns, ATMPArgs &args) { | const std::vector<CTransactionRef> &txns, ATMPArgs &args) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
PackageValidationState package_state; | PackageValidationState package_state; | ||||
const size_t package_count = txns.size(); | const size_t 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{}; | std::vector<Workspace> workspaces{}; | ||||
workspaces.reserve(package_count); | workspaces.reserve(package_count); | ||||
std::transform(txns.cbegin(), txns.cend(), std::back_inserter(workspaces), | std::transform(txns.cbegin(), txns.cend(), std::back_inserter(workspaces), | ||||
[&args, this](const auto &tx) { | [&args, this](const auto &tx) { | ||||
return Workspace( | return Workspace( | ||||
tx, | tx, | ||||
GetNextBlockScriptFlags( | GetNextBlockScriptFlags( | ||||
args.m_config.GetChainParams().GetConsensus(), | args.m_config.GetChainParams().GetConsensus(), | ||||
▲ Show 20 Lines • Show All 5,449 Lines • Show Last 20 Lines |