Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
501{502BOOST_CHECK(GetTransactionWeight(*tx_mempool_v3_child) <= TRUC_CHILD_MAX_VSIZE * WITNESS_SCALE_FACTOR);503auto parents{pool.GetParents(entry.FromTx(tx_mempool_v3_child))};504BOOST_CHECK(SingleTRUCChecks(pool, tx_mempool_v3_child, parents, empty_conflicts_set, GetVirtualTransactionSize(*tx_mempool_v3_child)) == std::nullopt);505TryAddToMempool(pool, entry.FromTx(tx_mempool_v3_child));507Package package_v3_1p1c{mempool_tx_v3, tx_mempool_v3_child};508BOOST_CHECK(PackageTRUCChecks(pool, tx_mempool_v3_child, GetVirtualTransactionSize(*tx_mempool_v3_child), package_v3_1p1c, empty_parents) == std::nullopt);509}511// A TRUC transaction cannot have more than 1 descendant. Sibling is returned when exactly 1 exists.512{513auto tx_v3_child2 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 1}}, /*version=*/3);514// Configuration where parent already has 1 other child in mempool515auto parents_1sibling{pool.GetParents(entry.FromTx(tx_v3_child2))};516const auto expected_error_str{strprintf("tx %s (wtxid=%s) would exceed descendant count limit",517mempool_tx_v3->GetHash().ToString(), mempool_tx_v3->GetWitnessHash().ToString())};518auto result_with_sibling_eviction{SingleTRUCChecks(pool, tx_v3_child2, parents_1sibling, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_child2))};519BOOST_CHECK_EQUAL(result_with_sibling_eviction->first, expected_error_str);520// The other mempool child is returned to allow for sibling eviction.521BOOST_CHECK_EQUAL(result_with_sibling_eviction->second, tx_mempool_v3_child);523// If directly replacing the child, make sure there is no double-counting.524BOOST_CHECK(SingleTRUCChecks(pool, tx_v3_child2, parents_1sibling, {tx_mempool_v3_child->GetHash()}, GetVirtualTransactionSize(*tx_v3_child2))525== std::nullopt);527Package package_v3_1p2c{mempool_tx_v3, tx_mempool_v3_child, tx_v3_child2};528BOOST_CHECK_EQUAL(*PackageTRUCChecks(pool, tx_v3_child2, GetVirtualTransactionSize(*tx_v3_child2), package_v3_1p2c, empty_parents),529expected_error_str);531// Configuration where parent already has 2 other children in mempool (no sibling eviction allowed). This may happen as the result of a reorg.532TryAddToMempool(pool, entry.FromTx(tx_v3_child2));533auto tx_v3_child3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 24}}, /*version=*/3);534auto entry_mempool_parent = pool.GetIter(mempool_tx_v3->GetHash()).value();535BOOST_CHECK_EQUAL(pool.GetDescendantCount(entry_mempool_parent), 3);536auto parents_2siblings{pool.GetParents(entry.FromTx(tx_v3_child3))};538auto result_2children{SingleTRUCChecks(pool, tx_v3_child3, parents_2siblings, empty_conflicts_set, GetVirtualTransactionSize(*tx_v3_child3))};539BOOST_CHECK_EQUAL(result_2children->first, expected_error_str);540// The other mempool child is not returned because sibling eviction is not allowed.541BOOST_CHECK_EQUAL(result_2children->second, nullptr);542}544// 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.545{546auto tx_mempool_grandparent = make_tx(random_outpoints(1), /*version=*/3);547auto tx_mempool_sibling = make_tx({COutPoint{tx_mempool_grandparent->GetHash(), 0}}, /*version=*/3);548auto tx_mempool_nibling = make_tx({COutPoint{tx_mempool_sibling->GetHash(), 0}}, /*version=*/3);549auto tx_to_submit = make_tx({COutPoint{tx_mempool_grandparent->GetHash(), 1}}, /*version=*/3);551TryAddToMempool(pool, entry.FromTx(tx_mempool_grandparent));552TryAddToMempool(pool, entry.FromTx(tx_mempool_sibling));553TryAddToMempool(pool, entry.FromTx(tx_mempool_nibling));555auto parents_3gen{pool.GetParents(entry.FromTx(tx_to_submit))};556const auto expected_error_str{strprintf("tx %s (wtxid=%s) would exceed descendant count limit",557tx_mempool_grandparent->GetHash().ToString(), tx_mempool_grandparent->GetWitnessHash().ToString())};558auto result_3gen{SingleTRUCChecks(pool, tx_to_submit, parents_3gen, empty_conflicts_set, GetVirtualTransactionSize(*tx_to_submit))};559BOOST_CHECK_EQUAL(result_3gen->first, expected_error_str);560// The other mempool child is not returned because sibling eviction is not allowed.561BOOST_CHECK_EQUAL(result_3gen->second, nullptr);562}564// Configuration where tx has multiple generations of descendants is not tested because that is565// equivalent to the tx with multiple generations of ancestors.566}568BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.