Skip to content

Commit cc50f2f

Browse files
committed
[cleanup] replace TxOrphanage::Size() with CountUniqueOrphans
1 parent ed24e01 commit cc50f2f

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

src/node/txdownloadman_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ void TxDownloadManagerImpl::CheckIsEmpty(NodeId nodeid)
572572
void TxDownloadManagerImpl::CheckIsEmpty()
573573
{
574574
assert(m_orphanage->TotalOrphanUsage() == 0);
575-
assert(m_orphanage->Size() == 0);
575+
assert(m_orphanage->CountUniqueOrphans() == 0);
576576
assert(m_txrequest.Size() == 0);
577577
assert(m_num_wtxid_peers == 0);
578578
}

src/node/txorphanage.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ class TxOrphanageImpl final : public TxOrphanage {
229229
std::vector<std::pair<Wtxid, NodeId>> AddChildrenToWorkSet(const CTransaction& tx, FastRandomContext& rng) override;
230230
bool HaveTxToReconsider(NodeId peer) override;
231231
std::vector<CTransactionRef> GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const override;
232-
size_t Size() const override { return m_unique_orphans; }
233232
std::vector<OrphanTxBase> GetOrphanTransactions() const override;
234233
TxOrphanage::Usage TotalOrphanUsage() const override;
235234
void SanityCheck() const override;

src/node/txorphanage.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ class TxOrphanage {
9898
* recent to least recent. */
9999
virtual std::vector<CTransactionRef> GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const = 0;
100100

101-
/** Return how many entries exist in the orphange */
102-
virtual size_t Size() const = 0;
103-
104101
/** Get all orphan transactions */
105102
virtual std::vector<OrphanTxBase> GetOrphanTransactions() const = 0;
106103

src/test/orphanage_tests.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -498,19 +498,19 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
498498
BOOST_CHECK(!orphanage->AddTx(MakeTransactionRef(tx), i));
499499
}
500500

501-
size_t expected_num_orphans = orphanage->Size();
501+
size_t expected_num_orphans = orphanage->CountUniqueOrphans();
502502

503503
// Non-existent peer; nothing should be deleted
504504
orphanage->EraseForPeer(/*peer=*/-1);
505-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_num_orphans);
505+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_num_orphans);
506506

507507
// Each of first three peers stored
508508
// two transactions each.
509509
for (NodeId i = 0; i < 3; i++)
510510
{
511511
orphanage->EraseForPeer(i);
512512
expected_num_orphans -= 2;
513-
BOOST_CHECK(orphanage->Size() == expected_num_orphans);
513+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_num_orphans);
514514
}
515515
}
516516

@@ -732,7 +732,7 @@ BOOST_AUTO_TEST_CASE(process_block)
732732
BOOST_CHECK(!orphanage->HaveTx(expected_removed_wtxid));
733733
}
734734
// Only remaining tx is control_tx
735-
BOOST_CHECK_EQUAL(orphanage->Size(), 1);
735+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), 1);
736736
BOOST_CHECK(orphanage->HaveTx(control_tx->GetWitnessHash()));
737737
}
738738

@@ -753,11 +753,11 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
753753
BOOST_CHECK(orphanage->AddTx(ptx, node0));
754754
BOOST_CHECK(orphanage->HaveTx(wtxid));
755755
expected_total_count += 1;
756-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
756+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
757757

758758
// Adding again should do nothing.
759759
BOOST_CHECK(!orphanage->AddTx(ptx, node0));
760-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
760+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
761761

762762
// We can add another tx with the same txid but different witness.
763763
auto ptx_mutated{MakeMutation(ptx)};
@@ -769,15 +769,15 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
769769

770770
// Adding a new announcer should not change overall accounting.
771771
BOOST_CHECK(orphanage->AddAnnouncer(ptx->GetWitnessHash(), node2));
772-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
772+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
773773

774774
// If we already have this announcer, AddAnnouncer returns false.
775775
BOOST_CHECK(orphanage->HaveTxFromPeer(ptx->GetWitnessHash(), node2));
776776
BOOST_CHECK(!orphanage->AddAnnouncer(ptx->GetWitnessHash(), node2));
777777

778778
// Same with using AddTx for an existing tx, which is equivalent to using AddAnnouncer
779779
BOOST_CHECK(!orphanage->AddTx(ptx, node1));
780-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
780+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
781781

782782
// if EraseForPeer is called for an orphan with multiple announcers, the orphanage should only
783783
// erase that peer from the announcers set.
@@ -787,15 +787,15 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
787787
// node0 is the only one that announced ptx_mutated
788788
BOOST_CHECK(!orphanage->HaveTx(ptx_mutated->GetWitnessHash()));
789789
expected_total_count -= 1;
790-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
790+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
791791

792792
// EraseForPeer should delete the orphan if it's the only announcer left.
793793
orphanage->EraseForPeer(node1);
794-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
794+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
795795
BOOST_CHECK(orphanage->HaveTx(ptx->GetWitnessHash()));
796796
orphanage->EraseForPeer(node2);
797797
expected_total_count -= 1;
798-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
798+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
799799
BOOST_CHECK(!orphanage->HaveTx(ptx->GetWitnessHash()));
800800
}
801801

@@ -809,13 +809,13 @@ BOOST_AUTO_TEST_CASE(multiple_announcers)
809809

810810
expected_total_count += 1;
811811

812-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
812+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
813813

814814
orphanage->EraseForBlock(block);
815815

816816
expected_total_count -= 1;
817817

818-
BOOST_CHECK_EQUAL(orphanage->Size(), expected_total_count);
818+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), expected_total_count);
819819
}
820820
}
821821
BOOST_AUTO_TEST_CASE(peer_worksets)
@@ -863,7 +863,7 @@ BOOST_AUTO_TEST_CASE(peer_worksets)
863863

864864
// Delete this tx, clearing the orphanage.
865865
BOOST_CHECK_EQUAL(orphanage->EraseTx(orphan_wtxid), 1);
866-
BOOST_CHECK_EQUAL(orphanage->Size(), 0);
866+
BOOST_CHECK_EQUAL(orphanage->CountUniqueOrphans(), 0);
867867
for (NodeId node = node0; node <= node2; ++node) {
868868
BOOST_CHECK_EQUAL(orphanage->GetTxToReconsider(node), nullptr);
869869
BOOST_CHECK(!orphanage->HaveTxFromPeer(orphan_wtxid, node));

0 commit comments

Comments
 (0)