@@ -1352,7 +1352,8 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
1352
1352
m_view.SetBackend (m_dummy);
1353
1353
1354
1354
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;
1356
1357
// Node operators are free to set their mempool policies however they please, nodes may receive
1357
1358
// transactions in different orders, and malicious counterparties may try to take advantage of
1358
1359
// 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,
1363
1364
// checking ancestor/descendant limits, or double-count transaction fees for fee-related policy.
1364
1365
ATMPArgs single_args = ATMPArgs::SingleInPackageAccept (args);
1365
1366
bool quit_early{false };
1366
- std::vector<CTransactionRef> txns_new ;
1367
+ std::vector<CTransactionRef> txns_package_eval ;
1367
1368
for (const auto & tx : package) {
1368
1369
const auto & wtxid = tx->GetWitnessHash ();
1369
1370
const auto & txid = tx->GetHash ();
@@ -1374,7 +1375,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
1374
1375
// Exact transaction already exists in the mempool.
1375
1376
auto iter = m_pool.GetIter (txid);
1376
1377
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 ()));
1378
1379
} else if (m_pool.exists (GenTxid::Txid (txid))) {
1379
1380
// Transaction with the same non-witness data but different witness (same txid,
1380
1381
// different wtxid) already exists in the mempool.
@@ -1386,7 +1387,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
1386
1387
auto iter = m_pool.GetIter (txid);
1387
1388
assert (iter != std::nullopt);
1388
1389
// 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 ()));
1390
1391
} else {
1391
1392
// Transaction does not already exist in the mempool.
1392
1393
// Try submitting the transaction on its own.
@@ -1395,7 +1396,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
1395
1396
// The transaction succeeded on its own and is now in the mempool. Don't include it
1396
1397
// in package validation, because its fees should only be "used" once.
1397
1398
assert (m_pool.exists (GenTxid::Wtxid (wtxid)));
1398
- results .emplace (wtxid, single_res);
1399
+ results_final .emplace (wtxid, single_res);
1399
1400
} else if (single_res.m_state .GetResult () != TxValidationResult::TX_MEMPOOL_POLICY &&
1400
1401
single_res.m_state .GetResult () != TxValidationResult::TX_MISSING_INPUTS) {
1401
1402
// Package validation policy only differs from individual policy in its evaluation
@@ -1409,21 +1410,21 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
1409
1410
// some of them may still be valid.
1410
1411
quit_early = true ;
1411
1412
package_state_quit_early.Invalid (PackageValidationResult::PCKG_TX, " transaction failed" );
1412
- results .emplace (wtxid, single_res);
1413
+ results_final .emplace (wtxid, single_res);
1413
1414
} else {
1414
- txns_new .push_back (tx);
1415
+ txns_package_eval .push_back (tx);
1415
1416
}
1416
1417
}
1417
1418
}
1418
1419
1419
1420
// 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 ));
1422
1423
}
1423
1424
// Validate the (deduplicated) transactions as a package.
1424
- auto submission_result = AcceptMultipleTransactions (txns_new , args);
1425
+ auto submission_result = AcceptMultipleTransactions (txns_package_eval , args);
1425
1426
// 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 ) {
1427
1428
submission_result.m_tx_results .emplace (wtxid, mempoolaccept_res);
1428
1429
}
1429
1430
return submission_result;
0 commit comments