[prep/test] have TxOrphanage remember its own limits in LimitOrphans

Move towards a model where TxOrphanage is initialized with limits that
it remembers throughout its lifetime.
Remove the param. Limiting by number of unique orphans will be removed
in a later commit.
Now that -maxorphantx is gone, this does not change the node behavior.
The parameter is only used in tests.
This commit is contained in:
glozow
2025-05-16 10:36:05 -04:00
parent d0af4239b7
commit 77ebe8f280
10 changed files with 19 additions and 36 deletions

View File

@@ -181,34 +181,23 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
// Test LimitOrphanTxSize() function, nothing should timeout:
FastRandomContext rng{/*fDeterministic=*/true};
orphanage.LimitOrphans(/*max_orphans=*/expected_num_orphans, rng);
orphanage.LimitOrphans(rng);
BOOST_CHECK_EQUAL(orphanage.Size(), expected_num_orphans);
expected_num_orphans -= 1;
orphanage.LimitOrphans(/*max_orphans=*/expected_num_orphans, rng);
BOOST_CHECK_EQUAL(orphanage.Size(), expected_num_orphans);
assert(expected_num_orphans > 40);
orphanage.LimitOrphans(40, rng);
BOOST_CHECK_EQUAL(orphanage.Size(), 40);
orphanage.LimitOrphans(10, rng);
BOOST_CHECK_EQUAL(orphanage.Size(), 10);
orphanage.LimitOrphans(0, rng);
BOOST_CHECK_EQUAL(orphanage.Size(), 0);
// Add one more orphan, check timeout logic
auto timeout_tx = MakeTransactionSpending(/*outpoints=*/{}, rng);
orphanage.AddTx(timeout_tx, 0);
orphanage.LimitOrphans(1, rng);
BOOST_CHECK_EQUAL(orphanage.Size(), 1);
expected_num_orphans += 1;
BOOST_CHECK_EQUAL(orphanage.Size(), expected_num_orphans);
// One second shy of expiration
SetMockTime(now + node::ORPHAN_TX_EXPIRE_TIME - 1s);
orphanage.LimitOrphans(1, rng);
BOOST_CHECK_EQUAL(orphanage.Size(), 1);
orphanage.LimitOrphans(rng);
BOOST_CHECK_EQUAL(orphanage.Size(), expected_num_orphans);
// Jump one more second, orphan should be timed out on limiting
SetMockTime(now + node::ORPHAN_TX_EXPIRE_TIME);
BOOST_CHECK_EQUAL(orphanage.Size(), 1);
orphanage.LimitOrphans(1, rng);
orphanage.LimitOrphans(rng);
BOOST_CHECK_EQUAL(orphanage.Size(), 0);
}