aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2022-01-21 12:40:59 +0000
committerglozow <gloriajzhao@gmail.com>2022-02-14 10:04:51 +0000
commit5ae187f8761f5f85a1ef41d24f75afb7eecf366f (patch)
treea3a6588fef2dc210f18c814d67a334cd0a6fa2d1
parentbd482b3ffebc68130f8a18dabf08ed1aff7ea159 (diff)
downloadbitcoin-5ae187f8761f5f85a1ef41d24f75afb7eecf366f.tar.xz
[validation] look up transaction by txid
GetIter takes a txid, not wtxid.
-rw-r--r--src/test/txpackage_tests.cpp11
-rw-r--r--src/validation.cpp2
2 files changed, 12 insertions, 1 deletions
diff --git a/src/test/txpackage_tests.cpp b/src/test/txpackage_tests.cpp
index 560efb6b42..6013080dc6 100644
--- a/src/test/txpackage_tests.cpp
+++ b/src/test/txpackage_tests.cpp
@@ -413,6 +413,17 @@ BOOST_FIXTURE_TEST_CASE(package_witness_swap_tests, TestChain100Setup)
BOOST_CHECK(m_node.mempool->exists(GenTxid::Txid(ptx_child2->GetHash())));
BOOST_CHECK(!m_node.mempool->exists(GenTxid::Wtxid(ptx_child2->GetWitnessHash())));
+
+ // Deduplication should work when wtxid != txid. Submit package with the already-in-mempool
+ // transactions again, which should not fail.
+ const auto submit_segwit_dedup = ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool,
+ {ptx_parent, ptx_child1}, /*test_accept=*/ false);
+ BOOST_CHECK_MESSAGE(submit_segwit_dedup.m_state.IsValid(),
+ "Package validation unexpectedly failed: " << submit_segwit_dedup.m_state.GetRejectReason());
+ auto it_parent_dup = submit_segwit_dedup.m_tx_results.find(ptx_parent->GetWitnessHash());
+ auto it_child_dup = submit_segwit_dedup.m_tx_results.find(ptx_child1->GetWitnessHash());
+ BOOST_CHECK(it_parent_dup->second.m_result_type == MempoolAcceptResult::ResultType::MEMPOOL_ENTRY);
+ BOOST_CHECK(it_child_dup->second.m_result_type == MempoolAcceptResult::ResultType::MEMPOOL_ENTRY);
}
// Try submitting Package1{child2, grandchild} where child2 is same-txid-different-witness as
diff --git a/src/validation.cpp b/src/validation.cpp
index 1b1d01a4c2..5241b1a2c6 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1306,7 +1306,7 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
// we know is that the inputs aren't available.
if (m_pool.exists(GenTxid::Wtxid(wtxid))) {
// Exact transaction already exists in the mempool.
- auto iter = m_pool.GetIter(wtxid);
+ auto iter = m_pool.GetIter(txid);
assert(iter != std::nullopt);
results.emplace(wtxid, MempoolAcceptResult::MempoolTx(iter.value()->GetTxSize(), iter.value()->GetFee()));
} else if (m_pool.exists(GenTxid::Txid(txid))) {