Skip to content

Commit c6893b0

Browse files
committed
[txdownload] remove unique_parents that we already have
This means we no longer return parents we already have in the m_unique_parents result from MempoolRejectedTx. We need to separate the loop that checks AlreadyHave parents from the loop that adds parents as announcements, because we may do the latter loop multiple times for different peers.
1 parent 163aaf2 commit c6893b0

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/node/txdownloadman_impl.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransaction
348348
}
349349
}
350350
if (!fRejectedParents) {
351+
// Filter parents that we already have.
352+
// Exclude m_lazy_recent_rejects_reconsiderable: the missing parent may have been
353+
// previously rejected for being too low feerate. This orphan might CPFP it.
354+
std::erase_if(unique_parents, [&](const auto& txid){
355+
return AlreadyHaveTx(GenTxid::Txid(txid), /*include_reconsiderable=*/false);
356+
});
351357
const auto current_time{GetTime<std::chrono::microseconds>()};
352358

353359
for (const uint256& parent_txid : unique_parents) {
@@ -357,11 +363,7 @@ node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransaction
357363
// Eventually we should replace this with an improved
358364
// protocol for getting all unconfirmed parents.
359365
const auto gtxid{GenTxid::Txid(parent_txid)};
360-
// Exclude m_lazy_recent_rejects_reconsiderable: the missing parent may have been
361-
// previously rejected for being too low feerate. This orphan might CPFP it.
362-
if (!AlreadyHaveTx(gtxid, /*include_reconsiderable=*/false)) {
363-
AddTxAnnouncement(nodeid, gtxid, current_time, /*p2p_inv=*/false);
364-
}
366+
AddTxAnnouncement(nodeid, gtxid, current_time, /*p2p_inv=*/false);
365367
}
366368

367369
// Potentially flip add_extra_compact_tx to false if AddTx returns false because the tx was already there

src/test/txdownload_tests.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,14 @@ BOOST_FIXTURE_TEST_CASE(handle_missing_inputs, TestChain100Setup)
231231
// it's in RecentRejectsFilter. Specifically, the parent is allowed to be in
232232
// RecentRejectsReconsiderableFilter, but it cannot be in RecentRejectsFilter.
233233
const bool expect_keep_orphan = !parent_recent_rej;
234+
const unsigned int expected_parents = parent_recent_rej || parent_recent_conf || parent_in_mempool ? 0 : 1;
235+
// If we don't expect to keep the orphan then expected_parents is 0.
236+
// !expect_keep_orphan => (expected_parents == 0)
237+
BOOST_CHECK(expect_keep_orphan || expected_parents == 0);
234238
const auto ret_1p1c = txdownload_impl.MempoolRejectedTx(orphan, state_orphan, nodeid, /*first_time_failure=*/true);
235239
std::string err_msg;
236240
const bool ok = CheckOrphanBehavior(txdownload_impl, orphan, ret_1p1c, err_msg,
237-
/*expect_orphan=*/expect_keep_orphan, /*expect_keep=*/true, /*expected_parents=*/expect_keep_orphan ? 1 : 0);
241+
/*expect_orphan=*/expect_keep_orphan, /*expect_keep=*/true, /*expected_parents=*/expected_parents);
238242
BOOST_CHECK_MESSAGE(ok, err_msg);
239243
}
240244

@@ -278,11 +282,12 @@ BOOST_FIXTURE_TEST_CASE(handle_missing_inputs, TestChain100Setup)
278282
for (int32_t i = 1; i < num_parents; ++i) {
279283
txdownload_impl.RecentConfirmedTransactionsFilter().insert(parents[i]->GetHash().ToUint256());
280284
}
285+
const unsigned int expected_parents = 1;
281286

282287
const auto ret_1recon_conf = txdownload_impl.MempoolRejectedTx(orphan, state_orphan, nodeid, /*first_time_failure=*/true);
283288
std::string err_msg;
284289
const bool ok = CheckOrphanBehavior(txdownload_impl, orphan, ret_1recon_conf, err_msg,
285-
/*expect_orphan=*/true, /*expect_keep=*/true, /*expected_parents=*/num_parents);
290+
/*expect_orphan=*/true, /*expect_keep=*/true, /*expected_parents=*/expected_parents);
286291
BOOST_CHECK_MESSAGE(ok, err_msg);
287292
}
288293

0 commit comments

Comments
 (0)