[refactor] rename variables in AcceptPackage for clarity

This commit is contained in:
glozow 2023-01-06 17:45:45 +00:00
parent da484bc738
commit dae81e01e8

View File

@ -1352,7 +1352,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
m_view.SetBackend(m_dummy); m_view.SetBackend(m_dummy);
LOCK(m_pool.cs); LOCK(m_pool.cs);
std::map<const uint256, const MempoolAcceptResult> results; // Stores final results that won't change
std::map<const uint256, const MempoolAcceptResult> results_final;
// Node operators are free to set their mempool policies however they please, nodes may receive // Node operators are free to set their mempool policies however they please, nodes may receive
// transactions in different orders, and malicious counterparties may try to take advantage of // transactions in different orders, and malicious counterparties may try to take advantage of
// policy differences to pin or delay propagation of transactions. As such, it's possible for // 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,
// checking ancestor/descendant limits, or double-count transaction fees for fee-related policy. // checking ancestor/descendant limits, or double-count transaction fees for fee-related policy.
ATMPArgs single_args = ATMPArgs::SingleInPackageAccept(args); ATMPArgs single_args = ATMPArgs::SingleInPackageAccept(args);
bool quit_early{false}; bool quit_early{false};
std::vector<CTransactionRef> txns_new; std::vector<CTransactionRef> txns_package_eval;
for (const auto& tx : package) { for (const auto& tx : package) {
const auto& wtxid = tx->GetWitnessHash(); const auto& wtxid = tx->GetWitnessHash();
const auto& txid = tx->GetHash(); const auto& txid = tx->GetHash();
@ -1374,7 +1375,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
// Exact transaction already exists in the mempool. // Exact transaction already exists in the mempool.
auto iter = m_pool.GetIter(txid); auto iter = m_pool.GetIter(txid);
assert(iter != std::nullopt); assert(iter != std::nullopt);
results.emplace(wtxid, MempoolAcceptResult::MempoolTx(iter.value()->GetTxSize(), iter.value()->GetFee())); results_final.emplace(wtxid, MempoolAcceptResult::MempoolTx(iter.value()->GetTxSize(), iter.value()->GetFee()));
} else if (m_pool.exists(GenTxid::Txid(txid))) { } else if (m_pool.exists(GenTxid::Txid(txid))) {
// Transaction with the same non-witness data but different witness (same txid, // Transaction with the same non-witness data but different witness (same txid,
// different wtxid) already exists in the mempool. // different wtxid) already exists in the mempool.
@ -1386,7 +1387,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
auto iter = m_pool.GetIter(txid); auto iter = m_pool.GetIter(txid);
assert(iter != std::nullopt); assert(iter != std::nullopt);
// Provide the wtxid of the mempool tx so that the caller can look it up in the mempool. // Provide the wtxid of the mempool tx so that the caller can look it up in the mempool.
results.emplace(wtxid, MempoolAcceptResult::MempoolTxDifferentWitness(iter.value()->GetTx().GetWitnessHash())); results_final.emplace(wtxid, MempoolAcceptResult::MempoolTxDifferentWitness(iter.value()->GetTx().GetWitnessHash()));
} else { } else {
// Transaction does not already exist in the mempool. // Transaction does not already exist in the mempool.
// Try submitting the transaction on its own. // Try submitting the transaction on its own.
@ -1395,7 +1396,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
// The transaction succeeded on its own and is now in the mempool. Don't include it // The transaction succeeded on its own and is now in the mempool. Don't include it
// in package validation, because its fees should only be "used" once. // in package validation, because its fees should only be "used" once.
assert(m_pool.exists(GenTxid::Wtxid(wtxid))); assert(m_pool.exists(GenTxid::Wtxid(wtxid)));
results.emplace(wtxid, single_res); results_final.emplace(wtxid, single_res);
} else if (single_res.m_state.GetResult() != TxValidationResult::TX_MEMPOOL_POLICY && } else if (single_res.m_state.GetResult() != TxValidationResult::TX_MEMPOOL_POLICY &&
single_res.m_state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) { single_res.m_state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) {
// Package validation policy only differs from individual policy in its evaluation // Package validation policy only differs from individual policy in its evaluation
@ -1409,21 +1410,21 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
// some of them may still be valid. // some of them may still be valid.
quit_early = true; quit_early = true;
package_state_quit_early.Invalid(PackageValidationResult::PCKG_TX, "transaction failed"); package_state_quit_early.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
results.emplace(wtxid, single_res); results_final.emplace(wtxid, single_res);
} else { } else {
txns_new.push_back(tx); txns_package_eval.push_back(tx);
} }
} }
} }
// Nothing to do if the entire package has already been submitted. // Nothing to do if the entire package has already been submitted.
if (quit_early || txns_new.empty()) { if (quit_early || txns_package_eval.empty()) {
return PackageMempoolAcceptResult(package_state_quit_early, std::move(results)); return PackageMempoolAcceptResult(package_state_quit_early, std::move(results_final));
} }
// Validate the (deduplicated) transactions as a package. // Validate the (deduplicated) transactions as a package.
auto submission_result = AcceptMultipleTransactions(txns_new, args); auto submission_result = AcceptMultipleTransactions(txns_package_eval, args);
// Include already-in-mempool transaction results in the final result. // Include already-in-mempool transaction results in the final result.
for (const auto& [wtxid, mempoolaccept_res] : results) { for (const auto& [wtxid, mempoolaccept_res] : results_final) {
submission_result.m_tx_results.emplace(wtxid, mempoolaccept_res); submission_result.m_tx_results.emplace(wtxid, mempoolaccept_res);
} }
return submission_result; return submission_result;