Skip to content

Commit d227b72

Browse files
committed
[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.
1 parent 9698b81 commit d227b72

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/validation.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,19 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
15251525
Assume(results_final.count(wtxid) == 0);
15261526
results_final.emplace(wtxid, multi_submission_result.m_tx_results.at(wtxid));
15271527
} else if (const auto it{results_final.find(wtxid)}; it != results_final.end()) {
1528-
// Already-in-mempool transaction.
1528+
// Already-in-mempool transaction. Check to see if it's still there, as it could have
1529+
// been evicted when LimitMempoolSize() was called.
15291530
Assume(it->second.m_result_type != MempoolAcceptResult::ResultType::INVALID);
15301531
Assume(individual_results_nonfinal.count(wtxid) == 0);
1532+
// Query by txid to include the same-txid-different-witness ones.
1533+
if (!m_pool.exists(GenTxid::Txid(tx->GetHash()))) {
1534+
package_state_final.Invalid(PackageValidationResult::PCKG_TX, "transaction failed");
1535+
TxValidationState mempool_full_state;
1536+
mempool_full_state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "mempool full");
1537+
// Replace the previous result.
1538+
results_final.erase(wtxid);
1539+
results_final.emplace(wtxid, MempoolAcceptResult::Failure(mempool_full_state));
1540+
}
15311541
} else if (const auto it{individual_results_nonfinal.find(wtxid)}; it != individual_results_nonfinal.end()) {
15321542
Assume(it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
15331543
// Interesting result from previous processing.

0 commit comments

Comments
 (0)