Skip to content

Commit 5e86bb8

Browse files
committed
[p2p] bump DEFAULT_MAX_ORPHAN_ANNOUNCEMENTS to 3000
For the default number of peers (125), allows each to relay a default descendant package of transactions (up to 25-1=24 can be missing inputs) out of order. Functional tests aren't changed to check for a cap for 3000 because it would make the runtime too long. Also deletes the now-unused DEFAULT_MAX_ORPHAN_TRANSACTIONS.
1 parent 05e6241 commit 5e86bb8

5 files changed

Lines changed: 11 additions & 61 deletions

File tree

src/node/txorphanage.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ namespace node {
1919
/** Default value for TxOrphanage::m_reserved_usage_per_peer. */
2020
static constexpr int64_t DEFAULT_RESERVED_ORPHAN_WEIGHT_PER_PEER{404'000};
2121
/** Default value for TxOrphanage::m_max_global_announcements. */
22-
static constexpr unsigned int DEFAULT_MAX_ORPHAN_ANNOUNCEMENTS{100};
22+
static constexpr unsigned int DEFAULT_MAX_ORPHAN_ANNOUNCEMENTS{3000};
2323
/** Minimum NodeId for lower_bound lookups (in practice, NodeIds start at 0). */
2424
static constexpr NodeId MIN_PEER{std::numeric_limits<NodeId>::min()};
25-
/** Default maximum number of orphan transactions kept in memory */
26-
static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS{100};
2725

2826
/** A class to track orphan transactions (failed on TX_MISSING_INPUTS)
2927
* Since we cannot distinguish orphans from bad transactions with non-existent inputs, we heavily limit the amount of

src/test/fuzz/txdownloadman.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,9 @@ FUZZ_TARGET(txdownloadman, .init = initialize)
278278
// peer without tracking anything (this is only for the txdownload_impl target).
279279
static bool HasRelayPermissions(NodeId peer) { return peer == 0; }
280280

281-
static void CheckInvariants(const node::TxDownloadManagerImpl& txdownload_impl, size_t max_orphan_count)
281+
static void CheckInvariants(const node::TxDownloadManagerImpl& txdownload_impl)
282282
{
283-
// Orphanage usage should never exceed what is allowed
284-
Assert(txdownload_impl.m_orphanage->CountUniqueOrphans() <= max_orphan_count);
285283
txdownload_impl.m_orphanage->SanityCheck();
286-
287284
// We should never have more than the maximum in-flight requests out for a peer.
288285
for (NodeId peer = 0; peer < NUM_PEERS; ++peer) {
289286
if (!HasRelayPermissions(peer)) {
@@ -302,7 +299,6 @@ FUZZ_TARGET(txdownloadman_impl, .init = initialize)
302299
// Initialize a TxDownloadManagerImpl
303300
bilingual_str error;
304301
CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node), error};
305-
const auto max_orphan_count = node::DEFAULT_MAX_ORPHAN_TRANSACTIONS;
306302
FastRandomContext det_rand{true};
307303
node::TxDownloadManagerImpl txdownload_impl{node::TxDownloadOptions{pool, det_rand, true}};
308304

@@ -436,7 +432,7 @@ FUZZ_TARGET(txdownloadman_impl, .init = initialize)
436432
if (fuzzed_data_provider.ConsumeBool()) time_skip *= -1;
437433
time += time_skip;
438434
}
439-
CheckInvariants(txdownload_impl, max_orphan_count);
435+
CheckInvariants(txdownload_impl);
440436
// Disconnect everybody, check that all data structures are empty.
441437
for (NodeId nodeid = 0; nodeid < NUM_PEERS; ++nodeid) {
442438
txdownload_impl.DisconnectedPeer(nodeid);

src/test/fuzz/txorphan.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
5050

5151
std::vector<CTransactionRef> tx_history;
5252

53-
LIMITED_WHILE(outpoints.size() < 200'000 && fuzzed_data_provider.ConsumeBool(), 10 * node::DEFAULT_MAX_ORPHAN_TRANSACTIONS)
53+
LIMITED_WHILE(outpoints.size() < 200'000 && fuzzed_data_provider.ConsumeBool(), 1000)
5454
{
5555
// construct transaction
5656
const CTransactionRef tx = [&] {
@@ -97,7 +97,7 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
9797
}
9898
}
9999
// trigger orphanage functions
100-
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10 * node::DEFAULT_MAX_ORPHAN_TRANSACTIONS)
100+
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 1000)
101101
{
102102
NodeId peer_id = fuzzed_data_provider.ConsumeIntegral<NodeId>();
103103
const auto total_bytes_start{orphanage->TotalOrphanUsage()};
@@ -217,7 +217,6 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
217217
// test mocktime and expiry
218218
SetMockTime(ConsumeTime(fuzzed_data_provider));
219219
orphanage->LimitOrphans();
220-
Assert(orphanage->CountUniqueOrphans() <= node::DEFAULT_MAX_ORPHAN_TRANSACTIONS);
221220
});
222221
}
223222

@@ -270,7 +269,7 @@ FUZZ_TARGET(txorphan_protected, .init = initialize_orphanage)
270269
// These are honest peer's live announcements. We expect them to be protected from eviction.
271270
std::set<Wtxid> protected_wtxids;
272271

273-
LIMITED_WHILE(outpoints.size() < 200'000 && fuzzed_data_provider.ConsumeBool(), 10 * global_announcement_limit)
272+
LIMITED_WHILE(outpoints.size() < 200'000 && fuzzed_data_provider.ConsumeBool(), 1000)
274273
{
275274
// construct transaction
276275
const CTransactionRef tx = [&] {

test/functional/p2p_invalid_tx.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ def run_test(self):
147147
self.wait_until(lambda: 1 == len(node.getpeerinfo()), timeout=12) # p2ps[1] is no longer connected
148148
assert_equal(expected_mempool, set(node.getrawmempool()))
149149

150-
self.log.info('Test orphan pool overflow')
150+
self.log.info('Test orphanage can store more than 100 transactions')
151151
orphan_tx_pool = [CTransaction() for _ in range(101)]
152152
for i in range(len(orphan_tx_pool)):
153153
orphan_tx_pool[i].vin.append(CTxIn(outpoint=COutPoint(i, 333)))
154154
orphan_tx_pool[i].vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
155155

156-
with node.assert_debug_log(['orphanage overflow, removed 1 tx']):
157-
node.p2ps[0].send_txs_and_test(orphan_tx_pool, node, success=False)
156+
node.p2ps[0].send_txs_and_test(orphan_tx_pool, node, success=False)
157+
self.wait_until(lambda: len(node.getorphantxs()) >= 101)
158158

159159
self.log.info('Test orphan with rejected parents')
160160
rejected_parent = CTransaction()
@@ -165,8 +165,8 @@ def run_test(self):
165165
node.p2ps[0].send_txs_and_test([rejected_parent], node, success=False)
166166

167167
self.log.info('Test that a peer disconnection causes erase its transactions from the orphan pool')
168-
with node.assert_debug_log(['Erased 100 orphan transaction(s) from peer=26']):
169-
self.reconnect_p2p(num_connections=1)
168+
self.reconnect_p2p(num_connections=1)
169+
self.wait_until(lambda: len(node.getorphantxs()) == 0)
170170

171171
self.log.info('Test that a transaction in the orphan pool is included in a new tip block causes erase this transaction from the orphan pool')
172172
tx_withhold_until_block_A = CTransaction()

test/functional/p2p_orphan_handling.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
# for one peer and y seconds for another, use specific values instead.
4444
TXREQUEST_TIME_SKIP = NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY + OVERLOADED_PEER_TX_DELAY + 1
4545

46-
DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100
47-
4846
def cleanup(func):
4947
# Time to fastfoward (using setmocktime) in between subtests to ensure they do not interfere with
5048
# one another, in seconds. Equal to 12 hours, which is enough to expire anything that may exist
@@ -593,46 +591,6 @@ def test_orphan_txid_inv(self):
593591
assert_equal(node.getmempoolentry(tx_child["txid"])["wtxid"], tx_child["wtxid"])
594592
self.wait_until(lambda: len(node.getorphantxs()) == 0)
595593

596-
@cleanup
597-
def test_max_orphan_amount(self):
598-
self.log.info("Check that we never exceed our storage limits for orphans")
599-
600-
node = self.nodes[0]
601-
self.generate(self.wallet, 1)
602-
peer_1 = node.add_p2p_connection(P2PInterface())
603-
604-
self.log.info("Check that orphanage is empty on start of test")
605-
assert len(node.getorphantxs()) == 0
606-
607-
self.log.info("Filling up orphanage with " + str(DEFAULT_MAX_ORPHAN_TRANSACTIONS) + "(DEFAULT_MAX_ORPHAN_TRANSACTIONS) orphans")
608-
orphans = []
609-
parent_orphans = []
610-
for _ in range(DEFAULT_MAX_ORPHAN_TRANSACTIONS):
611-
tx_parent_1 = self.wallet.create_self_transfer()
612-
tx_child_1 = self.wallet.create_self_transfer(utxo_to_spend=tx_parent_1["new_utxo"])
613-
parent_orphans.append(tx_parent_1["tx"])
614-
orphans.append(tx_child_1["tx"])
615-
peer_1.send_without_ping(msg_tx(tx_child_1["tx"]))
616-
617-
peer_1.sync_with_ping()
618-
orphanage = node.getorphantxs()
619-
self.wait_until(lambda: len(node.getorphantxs()) == DEFAULT_MAX_ORPHAN_TRANSACTIONS)
620-
621-
for orphan in orphans:
622-
assert tx_in_orphanage(node, orphan)
623-
624-
self.log.info("Check that we do not add more than the max orphan amount")
625-
tx_parent_1 = self.wallet.create_self_transfer()
626-
tx_child_1 = self.wallet.create_self_transfer(utxo_to_spend=tx_parent_1["new_utxo"])
627-
peer_1.send_and_ping(msg_tx(tx_child_1["tx"]))
628-
parent_orphans.append(tx_parent_1["tx"])
629-
orphanage = node.getorphantxs()
630-
assert_equal(len(orphanage), DEFAULT_MAX_ORPHAN_TRANSACTIONS)
631-
632-
self.log.info("Clearing the orphanage")
633-
for index, parent_orphan in enumerate(parent_orphans):
634-
peer_1.send_and_ping(msg_tx(parent_orphan))
635-
self.wait_until(lambda: len(node.getorphantxs()) == 0)
636594

637595
@cleanup
638596
def test_orphan_handling_prefer_outbound(self):
@@ -820,7 +778,6 @@ def run_test(self):
820778
self.test_same_txid_orphan()
821779
self.test_same_txid_orphan_of_orphan()
822780
self.test_orphan_txid_inv()
823-
self.test_max_orphan_amount()
824781
self.test_orphan_handling_prefer_outbound()
825782
self.test_announcers_before_and_after()
826783
self.test_parents_change()

0 commit comments

Comments
 (0)