Skip to content

Commit

Permalink
Further improve
Browse files Browse the repository at this point in the history
  • Loading branch information
naumenkogs committed Nov 13, 2024
1 parent 745fc55 commit 88c10c5
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,16 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
}
}

// Handle one-tx package before LimitMempoolSize because it was already
// called in AcceptSingleTransaction.
if (package.size() == 1) {
Assume(results_final.size() == 1);
const auto wtxid = package[0]->GetWitnessHash();
const auto it{results_final.find(wtxid)};
Assume(it != results_final.end());
return PackageMempoolAcceptResult(wtxid, it->second);

This comment has been minimized.

Copy link
@instagibbs

instagibbs Nov 13, 2024

This shortcuts too early, you're going to miss mempool trimming so your mempool may have become too large, and if you limit mempool anyways, you need to detect if the single transaction was also evicted immediately.

This comment has been minimized.

Copy link
@naumenkogs

naumenkogs Nov 18, 2024

Author Owner

The fix is trivial (should not break anything), although a little ugly.

It's the next commit (66ea850) in this branch.

Could be better to update PackageChildWithParents for this special-case.

This comment has been minimized.

Copy link
@instagibbs

instagibbs Nov 19, 2024

I'm not convinced by the relative complexity, I appreciate you giving it a shot though

}

auto multi_submission_result = quit_early || txns_package_eval.empty() ? PackageMempoolAcceptResult(package_state_quit_early, {}) :
AcceptSubPackage(txns_package_eval, args);
PackageValidationState& package_state_final = multi_submission_result.m_state;
Expand All @@ -1809,12 +1819,12 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
// Package transactions that were submitted to mempool or already in mempool may be evicted.
LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip());

Assume(package.size() > 1);
for (const auto& tx : package) {
const auto& wtxid = tx->GetWitnessHash();
if (multi_submission_result.m_tx_results.count(wtxid) > 0) {
// We shouldn't have re-submitted if the tx result was already in results_final.
Assume(results_final.count(wtxid) == 0);
Assume(package.size() > 1);
// If it was submitted, check to see if the tx is still in the mempool. It could have
// been evicted due to LimitMempoolSize() above.
const auto& txresult = multi_submission_result.m_tx_results.at(wtxid);
Expand All @@ -1833,20 +1843,17 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
// Could also be a failed (any kind) single-tx package. Do nothing, because if it was
// evicted, we would know it from AcceptSingleTransaction().
Assume(individual_results_nonfinal.count(wtxid) == 0);
if (package.size() > 1) {
Assume(it->second.m_result_type != MempoolAcceptResult::ResultType::INVALID);
// Query by txid to include the same-txid-different-witness ones.
if (!m_pool.exists(GenTxid::Txid(tx->GetHash()))) {
package_state_final.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
TxValidationState mempool_full_state;
mempool_full_state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "mempool full");
// Replace the previous result.
results_final.erase(wtxid);
results_final.emplace(wtxid, MempoolAcceptResult::Failure(mempool_full_state));
}
Assume(it->second.m_result_type != MempoolAcceptResult::ResultType::INVALID);
// Query by txid to include the same-txid-different-witness ones.
if (!m_pool.exists(GenTxid::Txid(tx->GetHash()))) {
package_state_final.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
TxValidationState mempool_full_state;
mempool_full_state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "mempool full");
// Replace the previous result.
results_final.erase(wtxid);
results_final.emplace(wtxid, MempoolAcceptResult::Failure(mempool_full_state));
}
} else if (const auto it{individual_results_nonfinal.find(wtxid)}; it != individual_results_nonfinal.end()) {
Assume(package.size() > 1);
Assume(it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
// Interesting result from previous processing.
results_final.emplace(wtxid, it->second);
Expand Down

0 comments on commit 88c10c5

Please sign in to comment.