From d227b7234cd4cfd7c593ffcf8e2f24573d1ebea5 Mon Sep 17 00:00:00 2001 From: glozow Date: Fri, 25 Aug 2023 11:11:36 +0100 Subject: [PATCH] [validation] return correct result when already-in-mempool tx gets evicted Bug fix: a transaction may be in the mempool when package evaluation begins (so it is added to results_final with MEMPOOL_ENTRY or DIFFERENT_WITNESS), but get evicted due to another transaction submission. --- src/validation.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index 3cd815da264..70aa51b1028 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1525,9 +1525,19 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package, Assume(results_final.count(wtxid) == 0); results_final.emplace(wtxid, multi_submission_result.m_tx_results.at(wtxid)); } else if (const auto it{results_final.find(wtxid)}; it != results_final.end()) { - // Already-in-mempool transaction. + // Already-in-mempool transaction. Check to see if it's still there, as it could have + // been evicted when LimitMempoolSize() was called. Assume(it->second.m_result_type != MempoolAcceptResult::ResultType::INVALID); Assume(individual_results_nonfinal.count(wtxid) == 0); + // 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(it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID); // Interesting result from previous processing.