mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
[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:
@@ -173,9 +173,8 @@ FUZZ_TARGET(txdownloadman, .init = initialize)
|
||||
// Initialize txdownloadman
|
||||
bilingual_str error;
|
||||
CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node), error};
|
||||
const auto max_orphan_count = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 300);
|
||||
FastRandomContext det_rand{true};
|
||||
node::TxDownloadManager txdownloadman{node::TxDownloadOptions{pool, det_rand, max_orphan_count, true}};
|
||||
node::TxDownloadManager txdownloadman{node::TxDownloadOptions{pool, det_rand, true}};
|
||||
|
||||
std::chrono::microseconds time{244466666};
|
||||
|
||||
@@ -304,9 +303,9 @@ FUZZ_TARGET(txdownloadman_impl, .init = initialize)
|
||||
// Initialize a TxDownloadManagerImpl
|
||||
bilingual_str error;
|
||||
CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node), error};
|
||||
const auto max_orphan_count = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 300);
|
||||
const auto max_orphan_count = node::DEFAULT_MAX_ORPHAN_TRANSACTIONS;
|
||||
FastRandomContext det_rand{true};
|
||||
node::TxDownloadManagerImpl txdownload_impl{node::TxDownloadOptions{pool, det_rand, max_orphan_count, true}};
|
||||
node::TxDownloadManagerImpl txdownload_impl{node::TxDownloadOptions{pool, det_rand, true}};
|
||||
|
||||
std::chrono::microseconds time{244466666};
|
||||
|
||||
|
||||
@@ -217,9 +217,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
|
||||
[&] {
|
||||
// test mocktime and expiry
|
||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||
auto limit = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
||||
orphanage.LimitOrphans(limit, orphanage_rng);
|
||||
Assert(orphanage.Size() <= limit);
|
||||
orphanage.LimitOrphans(orphanage_rng);
|
||||
Assert(orphanage.Size() <= node::DEFAULT_MAX_ORPHAN_TRANSACTIONS);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ BOOST_FIXTURE_TEST_CASE(tx_rejection_types, TestChain100Setup)
|
||||
{
|
||||
CTxMemPool& pool = *Assert(m_node.mempool);
|
||||
FastRandomContext det_rand{true};
|
||||
node::TxDownloadOptions DEFAULT_OPTS{pool, det_rand, node::DEFAULT_MAX_ORPHAN_TRANSACTIONS, true};
|
||||
node::TxDownloadOptions DEFAULT_OPTS{pool, det_rand, true};
|
||||
|
||||
// A new TxDownloadManagerImpl is created for each tx so we can just reuse the same one.
|
||||
TxValidationState state;
|
||||
@@ -172,7 +172,7 @@ BOOST_FIXTURE_TEST_CASE(handle_missing_inputs, TestChain100Setup)
|
||||
{
|
||||
CTxMemPool& pool = *Assert(m_node.mempool);
|
||||
FastRandomContext det_rand{true};
|
||||
node::TxDownloadOptions DEFAULT_OPTS{pool, det_rand, node::DEFAULT_MAX_ORPHAN_TRANSACTIONS, true};
|
||||
node::TxDownloadOptions DEFAULT_OPTS{pool, det_rand, true};
|
||||
NodeId nodeid{1};
|
||||
node::TxDownloadConnectionInfo DEFAULT_CONN{/*m_preferred=*/false, /*m_relay_permissions=*/false, /*m_wtxid_relay=*/true};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user