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.
251auto mtx_parent = CreateValidMempoolTransaction(m_coinbase_txns[coinbase_idx++], /*input_vout=*/0, test_chain_height,252coinbaseKey, destination, amount_depth_1 + i, /*submit=*/false);253auto ptx_parent = MakeTransactionRef(mtx_parent);254parents.emplace_back(ptx_parent);255outpoints.emplace_back(ptx_parent->GetHash(), 0);256}258// Send all coins to 1 output.259auto mtx_orphan = CreateValidMempoolTransaction(parents, outpoints, test_chain_height, {wallet_key}, {{amount_depth_2 * num_parents, destination}}, /*submit=*/false);260auto orphan = MakeTransactionRef(mtx_orphan);262// 1 parent in RecentRejectsReconsiderableFilter, the rest are unknown263{264node::TxDownloadManagerImpl txdownload_impl{DEFAULT_OPTS};265txdownload_impl.ConnectedPeer(nodeid, DEFAULT_CONN);267txdownload_impl.RecentRejectsReconsiderableFilter().insert(parents[0]->GetHash().ToUint256());268const auto ret_1p1c_parent_reconsiderable = txdownload_impl.MempoolRejectedTx(orphan, state_orphan, nodeid, /*first_time_failure=*/true);269std::string err_msg;270const bool ok = CheckOrphanBehavior(txdownload_impl, orphan, ret_1p1c_parent_reconsiderable, err_msg,271/*expect_orphan=*/true, /*expect_keep=*/true, /*expected_parents=*/num_parents);272BOOST_CHECK_MESSAGE(ok, err_msg);273}275// 1 parent in RecentRejectsReconsiderableFilter, the rest are confirmed276{277node::TxDownloadManagerImpl txdownload_impl{DEFAULT_OPTS};278txdownload_impl.ConnectedPeer(nodeid, DEFAULT_CONN);280txdownload_impl.RecentRejectsReconsiderableFilter().insert(parents[0]->GetHash().ToUint256());281for (int32_t i = 1; i < num_parents; ++i) {282txdownload_impl.RecentConfirmedTransactionsFilter().insert(parents[i]->GetHash().ToUint256());283}284const unsigned int expected_parents = 1;286const auto ret_1recon_conf = txdownload_impl.MempoolRejectedTx(orphan, state_orphan, nodeid, /*first_time_failure=*/true);287std::string err_msg;288const bool ok = CheckOrphanBehavior(txdownload_impl, orphan, ret_1recon_conf, err_msg,289/*expect_orphan=*/true, /*expect_keep=*/true, /*expected_parents=*/expected_parents);290BOOST_CHECK_MESSAGE(ok, err_msg);291}293// 1 parent in RecentRejectsReconsiderableFilter, 1 other in {RecentRejectsReconsiderableFilter, RecentRejectsFilter}294for (int i = 0; i < 2; ++i) {295node::TxDownloadManagerImpl txdownload_impl{DEFAULT_OPTS};296txdownload_impl.ConnectedPeer(nodeid, DEFAULT_CONN);298txdownload_impl.RecentRejectsReconsiderableFilter().insert(parents[1]->GetHash().ToUint256());300// Doesn't really matter which parent301auto& alreadyhave_parent = parents[0];302if (i == 0) {303txdownload_impl.RecentRejectsReconsiderableFilter().insert(alreadyhave_parent->GetHash().ToUint256());304} else if (i == 1) {305txdownload_impl.RecentRejectsFilter().insert(alreadyhave_parent->GetHash().ToUint256());306}308const auto ret_2_problems = txdownload_impl.MempoolRejectedTx(orphan, state_orphan, nodeid, /*first_time_failure=*/true);309std::string err_msg;310const bool ok = CheckOrphanBehavior(txdownload_impl, orphan, ret_2_problems, err_msg,311/*expect_orphan=*/false, /*expect_keep=*/true, /*expected_parents=*/0);312BOOST_CHECK_MESSAGE(ok, err_msg);313}314}316// Orphan with multiple inputs spending from a single parent317{318assert(coinbase_idx < m_coinbase_txns.size());319auto parent_2outputs = MakeTransactionRef(CreateValidMempoolTransaction({m_coinbase_txns[coinbase_idx]}, {{m_coinbase_txns[coinbase_idx]->GetHash(), 0}}, test_chain_height, {coinbaseKey},320{{amount_split_half, destination}, {amount_split_half, destination}}, /*submit=*/false));322auto orphan = MakeTransactionRef(CreateValidMempoolTransaction({parent_2outputs}, {{parent_2outputs->GetHash(), 0}, {parent_2outputs->GetHash(), 1}},323test_chain_height, {wallet_key}, {{amount_depth_2, destination}}, /*submit=*/false));324// Parent is in RecentRejectsReconsiderableFilter. Inputs will find it twice, but this325// should only counts as 1 parent in the filter.326{327node::TxDownloadManagerImpl txdownload_impl{DEFAULT_OPTS};328txdownload_impl.ConnectedPeer(nodeid, DEFAULT_CONN);330txdownload_impl.RecentRejectsReconsiderableFilter().insert(parent_2outputs->GetHash().ToUint256());331const auto ret_1p1c_2reconsiderable = txdownload_impl.MempoolRejectedTx(orphan, state_orphan, nodeid, /*first_time_failure=*/true);332std::string err_msg;333const bool ok = CheckOrphanBehavior(txdownload_impl, orphan, ret_1p1c_2reconsiderable, err_msg,334/*expect_orphan=*/true, /*expect_keep=*/true, /*expected_parents=*/1);335BOOST_CHECK_MESSAGE(ok, err_msg);336}337}338}340BOOST_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.