Skip to content

Commit 5fbab37

Browse files
committed
[unit test] sibling not returned from SingleV3Checks if 1p2c or 3gen
1 parent 1703067 commit 5fbab37

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/test/txvalidation_tests.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,38 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
349349
Package package_v3_1p2c{mempool_tx_v3, tx_mempool_v3_child, tx_v3_child2};
350350
BOOST_CHECK_EQUAL(*PackageV3Checks(tx_v3_child2, GetVirtualTransactionSize(*tx_v3_child2), package_v3_1p2c, empty_ancestors),
351351
expected_error_str);
352+
353+
// Configuration where parent already has 2 other children in mempool (no sibling eviction allowed). This may happen as the result of a reorg.
354+
pool.addUnchecked(entry.FromTx(tx_v3_child2));
355+
auto tx_v3_child3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 24}}, /*version=*/3);
356+
auto entry_mempool_parent = pool.GetIter(mempool_tx_v3->GetHash().ToUint256()).value();
357+
BOOST_CHECK_EQUAL(entry_mempool_parent->GetCountWithDescendants(), 3);
358+
auto ancestors_2siblings{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_child3), m_limits)};
359+
360+
auto result_2children{SingleV3Checks(tx_v3_child3, *ancestors_2siblings, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_child3))};
361+
BOOST_CHECK_EQUAL(result_2children->first, expected_error_str);
362+
// The other mempool child is not returned because sibling eviction is not allowed.
363+
BOOST_CHECK_EQUAL(result_2children->second, nullptr);
364+
}
365+
366+
// Sibling eviction: parent already has 1 other child, which also has its own child (no sibling eviction allowed). This may happen as the result of a reorg.
367+
{
368+
auto tx_mempool_grandparent = make_tx(random_outpoints(1), /*version=*/3);
369+
auto tx_mempool_sibling = make_tx({COutPoint{tx_mempool_grandparent->GetHash(), 0}}, /*version=*/3);
370+
auto tx_mempool_nibling = make_tx({COutPoint{tx_mempool_sibling->GetHash(), 0}}, /*version=*/3);
371+
auto tx_to_submit = make_tx({COutPoint{tx_mempool_grandparent->GetHash(), 1}}, /*version=*/3);
372+
373+
pool.addUnchecked(entry.FromTx(tx_mempool_grandparent));
374+
pool.addUnchecked(entry.FromTx(tx_mempool_sibling));
375+
pool.addUnchecked(entry.FromTx(tx_mempool_nibling));
376+
377+
auto ancestors_3gen{pool.CalculateMemPoolAncestors(entry.FromTx(tx_to_submit), m_limits)};
378+
const auto expected_error_str{strprintf("tx %s (wtxid=%s) would exceed descendant count limit",
379+
tx_mempool_grandparent->GetHash().ToString(), tx_mempool_grandparent->GetWitnessHash().ToString())};
380+
auto result_3gen{SingleV3Checks(tx_to_submit, *ancestors_3gen, empty_conflicts_set, GetVirtualTransactionSize(*tx_to_submit))};
381+
BOOST_CHECK_EQUAL(result_3gen->first, expected_error_str);
382+
// The other mempool child is not returned because sibling eviction is not allowed.
383+
BOOST_CHECK_EQUAL(result_3gen->second, nullptr);
352384
}
353385

354386
// Configuration where tx has multiple generations of descendants is not tested because that is

0 commit comments

Comments
 (0)