[cleanup] replace TxOrphanage::Size() with CountUniqueOrphans

This commit is contained in:
glozow
2025-06-05 14:13:28 -04:00
parent ed24e01696
commit cc50f2f0df
4 changed files with 15 additions and 19 deletions

View File

@@ -498,11 +498,11 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
BOOST_CHECK(!orphanage->AddTx(MakeTransactionRef(tx), i));
}
size_t expected_num_orphans = orphanage->Size();
size_t expected_num_orphans = orphanage->CountUniqueOrphans();
// Non-existent peer; nothing should be deleted
orphanage->EraseForPeer(/*peer=*/-1);
BOOST_CHECK_EQUAL(orphanage->Size(), expected_num_orphans);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_num_orphans);
// Each of first three peers stored
// two transactions each.
@@ -510,7 +510,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
{
orphanage->EraseForPeer(i);
expected_num_orphans -= 2;
BOOST_CHECK(orphanage->Size() == expected_num_orphans);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_num_orphans);
}
}
@@ -732,7 +732,7 @@ BOOST_AUTO_TEST_CASE(process_block)
BOOST_CHECK(!orphanage->HaveTx(expected_removed_wtxid));
}
// Only remaining tx is control_tx
BOOST_CHECK_EQUAL(orphanage->Size(), 1);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), 1);
BOOST_CHECK(orphanage->HaveTx(control_tx->GetWitnessHash()));
}
@@ -753,11 +753,11 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
BOOST_CHECK(orphanage->AddTx(ptx, node0));
BOOST_CHECK(orphanage->HaveTx(wtxid));
expected_total_count += 1;
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
// Adding again should do nothing.
BOOST_CHECK(!orphanage->AddTx(ptx, node0));
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
// We can add another tx with the same txid but different witness.
auto ptx_mutated{MakeMutation(ptx)};
@@ -769,7 +769,7 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
// Adding a new announcer should not change overall accounting.
BOOST_CHECK(orphanage->AddAnnouncer(ptx->GetWitnessHash(), node2));
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
// If we already have this announcer, AddAnnouncer returns false.
BOOST_CHECK(orphanage->HaveTxFromPeer(ptx->GetWitnessHash(), node2));
@@ -777,7 +777,7 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
// Same with using AddTx for an existing tx, which is equivalent to using AddAnnouncer
BOOST_CHECK(!orphanage->AddTx(ptx, node1));
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
// if EraseForPeer is called for an orphan with multiple announcers, the orphanage should only
// erase that peer from the announcers set.
@@ -787,15 +787,15 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
// node0 is the only one that announced ptx_mutated
BOOST_CHECK(!orphanage->HaveTx(ptx_mutated->GetWitnessHash()));
expected_total_count -= 1;
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
// EraseForPeer should delete the orphan if it's the only announcer left.
orphanage->EraseForPeer(node1);
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
BOOST_CHECK(orphanage->HaveTx(ptx->GetWitnessHash()));
orphanage->EraseForPeer(node2);
expected_total_count -= 1;
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
BOOST_CHECK(!orphanage->HaveTx(ptx->GetWitnessHash()));
}
@@ -809,13 +809,13 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
expected_total_count += 1;
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
orphanage->EraseForBlock(block);
expected_total_count -= 1;
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
}
}
BOOST_AUTO_TEST_CASE(peer_worksets)
@@ -863,7 +863,7 @@ BOOST_AUTO_TEST_CASE(peer_worksets)
// Delete this tx, clearing the orphanage.
BOOST_CHECK_EQUAL(orphanage->EraseTx(orphan_wtxid), 1);
BOOST_CHECK_EQUAL(orphanage->Size(), 0);
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), 0);
for (NodeId node = node0; node <= node2; ++node) {
BOOST_CHECK_EQUAL(orphanage->GetTxToReconsider(node), nullptr);
BOOST_CHECK(!orphanage->HaveTxFromPeer(orphan_wtxid, node));