Skip to content

Commit dae81e0

Browse files
committed
[refactor] rename variables in AcceptPackage for clarity
1 parent da484bc commit dae81e0

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/validation.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13521352
m_view.SetBackend(m_dummy);
13531353

13541354
LOCK(m_pool.cs);
1355-
std::map<const uint256, const MempoolAcceptResult> results;
1355+
// Stores final results that won't change
1356+
std::map<const uint256, const MempoolAcceptResult> results_final;
13561357
// Node operators are free to set their mempool policies however they please, nodes may receive
13571358
// transactions in different orders, and malicious counterparties may try to take advantage of
13581359
// policy differences to pin or delay propagation of transactions. As such, it's possible for
@@ -1363,7 +1364,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13631364
// checking ancestor/descendant limits, or double-count transaction fees for fee-related policy.
13641365
ATMPArgs single_args = ATMPArgs::SingleInPackageAccept(args);
13651366
bool quit_early{false};
1366-
std::vector<CTransactionRef> txns_new;
1367+
std::vector<CTransactionRef> txns_package_eval;
13671368
for (const auto& tx : package) {
13681369
const auto& wtxid = tx->GetWitnessHash();
13691370
const auto& txid = tx->GetHash();
@@ -1374,7 +1375,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13741375
// Exact transaction already exists in the mempool.
13751376
auto iter = m_pool.GetIter(txid);
13761377
assert(iter != std::nullopt);
1377-
results.emplace(wtxid, MempoolAcceptResult::MempoolTx(iter.value()->GetTxSize(), iter.value()->GetFee()));
1378+
results_final.emplace(wtxid, MempoolAcceptResult::MempoolTx(iter.value()->GetTxSize(), iter.value()->GetFee()));
13781379
} else if (m_pool.exists(GenTxid::Txid(txid))) {
13791380
// Transaction with the same non-witness data but different witness (same txid,
13801381
// different wtxid) already exists in the mempool.
@@ -1386,7 +1387,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13861387
auto iter = m_pool.GetIter(txid);
13871388
assert(iter != std::nullopt);
13881389
// Provide the wtxid of the mempool tx so that the caller can look it up in the mempool.
1389-
results.emplace(wtxid, MempoolAcceptResult::MempoolTxDifferentWitness(iter.value()->GetTx().GetWitnessHash()));
1390+
results_final.emplace(wtxid, MempoolAcceptResult::MempoolTxDifferentWitness(iter.value()->GetTx().GetWitnessHash()));
13901391
} else {
13911392
// Transaction does not already exist in the mempool.
13921393
// Try submitting the transaction on its own.
@@ -1395,7 +1396,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
13951396
// The transaction succeeded on its own and is now in the mempool. Don't include it
13961397
// in package validation, because its fees should only be "used" once.
13971398
assert(m_pool.exists(GenTxid::Wtxid(wtxid)));
1398-
results.emplace(wtxid, single_res);
1399+
results_final.emplace(wtxid, single_res);
13991400
} else if (single_res.m_state.GetResult() != TxValidationResult::TX_MEMPOOL_POLICY &&
14001401
single_res.m_state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) {
14011402
// Package validation policy only differs from individual policy in its evaluation
@@ -1409,21 +1410,21 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
14091410
// some of them may still be valid.
14101411
quit_early = true;
14111412
package_state_quit_early.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
1412-
results.emplace(wtxid, single_res);
1413+
results_final.emplace(wtxid, single_res);
14131414
} else {
1414-
txns_new.push_back(tx);
1415+
txns_package_eval.push_back(tx);
14151416
}
14161417
}
14171418
}
14181419

14191420
// Nothing to do if the entire package has already been submitted.
1420-
if (quit_early || txns_new.empty()) {
1421-
return PackageMempoolAcceptResult(package_state_quit_early, std::move(results));
1421+
if (quit_early || txns_package_eval.empty()) {
1422+
return PackageMempoolAcceptResult(package_state_quit_early, std::move(results_final));
14221423
}
14231424
// Validate the (deduplicated) transactions as a package.
1424-
auto submission_result = AcceptMultipleTransactions(txns_new, args);
1425+
auto submission_result = AcceptMultipleTransactions(txns_package_eval, args);
14251426
// Include already-in-mempool transaction results in the final result.
1426-
for (const auto& [wtxid, mempoolaccept_res] : results) {
1427+
for (const auto& [wtxid, mempoolaccept_res] : results_final) {
14271428
submission_result.m_tx_results.emplace(wtxid, mempoolaccept_res);
14281429
}
14291430
return submission_result;

0 commit comments

Comments
 (0)